@Test public void testRecovery() throws Exception { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); Node otherNode = db.createNode(); Relationship rel = node.createRelationshipTo( otherNode, withName( "recovery" ) ); db.index().forNodes( "node-index" ).add( node, "key1", "string value" ); db.index().forNodes( "node-index" ).add( node, "key2", 12345 ); db.index().forRelationships( "rel-index" ).add( rel, "key1", "string value" ); db.index().forRelationships( "rel-index" ).add( rel, "key2", 12345 ); tx.success(); } forceRecover(); }
@Test public void shouldNotCreateIndexesForReadOnlyDb() { // given db.withSetting( GraphDatabaseSettings.read_only, TRUE.toString() ); // when try ( Transaction tx = db.beginTx() ) { db.index().forNodes( "NODE" ); fail( "Should've failed" ); } catch ( WriteOperationsNotAllowedException e ) { // then good } try ( Transaction tx = db.beginTx() ) { db.index().forRelationships( "RELATIONSHIP" ); fail( "Should've failed" ); } catch ( WriteOperationsNotAllowedException e ) { // then good } } }
try ( Transaction tx = db.beginTx() ) Index<Node> nodeIndex = db.index().forNodes( "NODE" ); Index<Relationship> relationshipIndex = db.index().forRelationships( "RELATIONSHIP" ); try ( Transaction tx = db.beginTx() ) Index<Node> nodeIndex = db.index().forNodes( db.index().nodeIndexNames()[0] ); Index<Relationship> relationshipIndex = db.index().forRelationships( db.index().relationshipIndexNames()[0] );
@Test public void shouldAccessAndUpdateIndexInSameTransaction() { try ( Transaction tx = graphdb.beginTx() ) { Index<Node> version = graphdb.index().forNodes( "version" ); for ( int v = 0; v < 10; v++ ) { createNode( version, v ); } tx.success(); } }
@Test public void removalOfRelationshipIndexDoesNotInfluenceNodeIndexWithSameName() { String indexName = "index"; createNodeExplicitIndexWithSingleNode( db, indexName ); createRelationshipExplicitIndexWithSingleRelationship( db, indexName ); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", "otherValue" ); Index<Relationship> relationshipIndex = db.index().forRelationships( indexName ); relationshipIndex.delete(); tx.success(); } try ( Transaction tx = db.beginTx() ) { assertFalse( db.index().existsForRelationships( indexName ) ); Index<Node> nodeIndex = db.index().forNodes( indexName ); assertEquals( 2, sizeOf( nodeIndex ) ); tx.success(); } }
@BeforeClass public static void initializeIndex() { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); db.index().forNodes( INDEX_NAME ).add( node, "foo", "bar" ); tx.success(); } }
@Test public void removalOfNodeIndexDoesNotInfluenceRelationshipIndexWithSameName() { String indexName = "index"; createNodeExplicitIndexWithSingleNode( db, indexName ); createRelationshipExplicitIndexWithSingleRelationship( db, indexName ); try ( Transaction tx = db.beginTx() ) { Relationship relationship = db.createNode().createRelationshipTo( db.createNode(), TYPE ); Index<Relationship> relationshipIndex = db.index().forRelationships( indexName ); relationshipIndex.add( relationship, "key", "otherValue" ); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.delete(); tx.success(); } try ( Transaction tx = db.beginTx() ) { assertFalse( db.index().existsForNodes( indexName ) ); Index<Relationship> relationshipIndex = db.index().forRelationships( indexName ); assertEquals( 2, sizeOf( relationshipIndex ) ); tx.success(); } }
@Test public void testAsLittleAsPossibleRecoveryScenario() throws Exception { try ( Transaction tx = db.beginTx() ) { db.index().forNodes( "my-index" ).add( db.createNode(), "key", "value" ); tx.success(); } forceRecover(); }
db.index().forNodes( "index" ); tx.success(); try ( Transaction tx = db.beginTx() ) index = db.index().forNodes( "index" ); index2 = db.index().forNodes( "index2" ); Node node = db.createNode(); index.add( node, "key", "value" ); assertFalse( db.index().existsForNodes( "index" ) ); assertNotNull( db.index().forNodes( "index2" ).get( "key", "value" ).getSingle() );
@Test public void shouldThrowIllegalArgumentChangingTypeOfFieldOnNodeIndex() { String indexName = "index"; createNodeExplicitIndexWithSingleNode( db, indexName ); long nodeId; try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); nodeId = node.getId(); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", "otherValue" ); tx.success(); } try ( Transaction tx = db.beginTx() ) { Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.remove( db.getNodeById( nodeId ), "key" ); tx.success(); } expectedException.expect( IllegalArgumentException.class ); try ( Transaction tx = db.beginTx() ) { Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( db.getNodeById( nodeId ), "key", ValueContext.numeric( 52 ) ); tx.success(); } }
@Test public void testIndexDeleteIssue() throws Exception { try ( Transaction tx = db.beginTx() ) { db.index().forNodes( "index" ); tx.success(); } shutdownDB(); db.ensureStarted(); Index<Node> index; Index<Node> index2; try ( Transaction tx = db.beginTx() ) { index = db.index().forNodes( "index" ); index2 = db.index().forNodes( "index2" ); Node node = db.createNode(); index.add( node, "key", "value" ); tx.success(); } try ( Transaction tx = db.beginTx() ) { index.delete(); index2.add( db.createNode(), "key", "value" ); tx.success(); } db.shutdown(); db.ensureStarted(); forceRecover(); }
@Test public void shouldThrowIllegalArgumentChangingTypeOfFieldOnRelationshipIndex() { String indexName = "index"; createRelationshipExplicitIndexWithSingleRelationship( db, indexName ); long relId; try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); Relationship rel = node.createRelationshipTo( node, TYPE ); relId = rel.getId(); RelationshipIndex index = db.index().forRelationships( indexName ); index.add( rel, "key", "otherValue" ); tx.success(); } try ( Transaction tx = db.beginTx() ) { RelationshipIndex index = db.index().forRelationships( indexName ); index.remove( db.getRelationshipById( relId ), "key" ); tx.success(); } expectedException.expect( IllegalArgumentException.class ); try ( Transaction tx = db.beginTx() ) { RelationshipIndex index = db.index().forRelationships( indexName ); index.add( db.getRelationshipById( relId ), "key", ValueContext.numeric( 52 ) ); tx.success(); } }
Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", "hej" ); nodeIndex.add( node, "keydelete", "hej" ); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.remove( db.getNodeById( nodeId ), "keydelete" ); tx.success(); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", "hej" ); tx.success();
@Test public void shouldNotAcceptValuesWithNullToString() throws Exception { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); Node otherNode = db.createNode(); Relationship rel = node.createRelationshipTo( otherNode, RelationshipType.withName( "recovery" ) ); Index<Node> nodeIndex = db.index().forNodes( "node-index" ); RelationshipIndex relationshipIndex = db.index().forRelationships( "rel-index" ); // Add assertAddFailsWithIllegalArgument( nodeIndex, node, "key1", new ClassWithToStringAlwaysNull() ); assertAddFailsWithIllegalArgument( relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull() ); // Remove assertRemoveFailsWithIllegalArgument( nodeIndex, node, "key1", new ClassWithToStringAlwaysNull() ); assertRemoveFailsWithIllegalArgument( relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull() ); tx.success(); } forceRecover(); }
try ( Transaction tx = db.beginTx() ) nodeIndex = db.index().forNodes( indexName ); node = db.createNode(); nodeIndex.add( node, key, value );
try ( Transaction tx = db.beginTx() ) relationshipIndex = db.index().forRelationships( indexName ); relationship = db.createNode().createRelationshipTo( db.createNode(), MyRelTypes.TEST ); relationshipIndex.add( relationship, key, value );
db.index().getRelationshipAutoIndexer().getAutoIndex(); Node start = db.getNodeById( startId ); Node end = db.getNodeById( endId ); assertEquals( 1, hits.size() ); rel.delete(); autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex(); hits = autoRelationshipIndex.get( "Type", type.name(), start, end ); assertEquals( 0, count( hits ) );
@Test public void recoveryForRelationshipCommandsOnly() throws Throwable { // shutdown db here DatabaseLayout databaseLayout = db.databaseLayout(); shutdownDB(); try ( Transaction tx = db.beginTx() ) { Index<Relationship> index = db.index().forRelationships( "myIndex" ); Node node = db.createNode(); Relationship relationship = db.createNode().createRelationshipTo( node, RelationshipType.withName( "KNOWS" ) ); index.add( relationship, "key", "value" ); tx.success(); } db.shutdown(); Config config = Config.defaults(); IndexConfigStore indexStore = new IndexConfigStore( databaseLayout, fileSystemRule.get() ); LuceneDataSource ds = new LuceneDataSource( databaseLayout, config, indexStore, fileSystemRule.get(), OperationalMode.single ); ds.start(); ds.stop(); }
relationship = startNode.createRelationshipTo( endNode, TYPE ); index = db.index().forRelationships( TYPE.name() ); index.add( relationship, "key", new ValueContext( 1 ).indexNumeric() );