@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 droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSeparateTransactions() { // GIVEN IndexDefinition index = createIndex( db, label, propertyKey ); dropIndex( index ); // WHEN try { dropIndex( index ); fail( "Should not be able to drop index twice" ); } catch ( ConstraintViolationException e ) { assertThat( e.getMessage(), containsString( "No such INDEX ON :MY_LABEL(my_property_key)." ) ); } // THEN assertThat( "Index should have been deleted", getIndexes( db, label ), not( contains( index ) ) ); }
@Test public void droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSameTransaction() { // GIVEN IndexDefinition index = createIndex( db, label, propertyKey ); // WHEN try ( Transaction tx = db.beginTx() ) { index.drop(); try { index.drop(); fail( "Should not be able to drop index twice" ); } catch ( ConstraintViolationException e ) { assertThat( e.getMessage(), containsString( "No such INDEX ON :MY_LABEL(my_property_key)." ) ); } tx.success(); } // THEN assertThat( "Index should have been deleted", getIndexes( db, label ), not( contains( index ) ) ); }