public static IndexDefinition createIndex( GraphDatabaseService beansAPI, Label label, String... properties ) { IndexDefinition indexDef = createIndexNoWait( beansAPI, label, properties ); waitForIndex( beansAPI, indexDef ); return indexDef; }
@Test public void shouldPopulateIndex() { // GIVEN Node node = createNode( db, propertyKey, "Neo", label ); // create an index IndexDefinition index = createIndex( db, label, propertyKey ); waitForIndex( db, index ); // THEN assertThat( findNodesByLabelAndProperty( label, propertyKey, "Neo", db ), containsOnly( node ) ); }
@Test public void shouldRecreateDroppedIndex() { // GIVEN Node node = createNode( db, propertyKey, "Neo", label ); // create an index IndexDefinition index = createIndex( db, label, propertyKey ); waitForIndex( db, index ); // delete the index right away dropIndex( index ); // WHEN recreating that index createIndex( db, label, propertyKey ); waitForIndex( db, index ); // THEN it should exist and be usable assertThat( getIndexes( db, label ), contains( index ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, "Neo", db ), containsOnly( node ) ); }
@Test public void awaitingAllIndexesComingOnlineWorks() { // GIVEN // WHEN IndexDefinition index = createIndex( db, label, propertyKey ); createIndex( db, label, "other_property" ); // PASS waitForIndex( db, index ); try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1L, TimeUnit.MINUTES ); // THEN assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) ); } }
@Test public void addingAnIndexingRuleInNestedTxShouldSucceed() { IndexDefinition index; // WHEN IndexDefinition indexDef; try ( Transaction tx = db.beginTx() ) { try ( Transaction nestedTransaction = db.beginTx() ) { indexDef = db.schema().indexFor( label ).on( propertyKey ).create(); nestedTransaction.success(); } index = indexDef; tx.success(); } waitForIndex( db, indexDef ); // THEN assertThat( getIndexes( db, label ), containsOnly( index ) ); }