private boolean indexesAreOnline( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { for ( IndexDefinition index : db.schema().getIndexes() ) { switch ( db.schema().getIndexState( index ) ) { case ONLINE: break; // Good case POPULATING: return false; // Still populating case FAILED: fail( index + " entered failed state: " + db.schema().getIndexFailure( index ) ); default: throw new UnsupportedOperationException(); } } tx.success(); } return true; }
@Test public void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated() throws Exception { // Given Label label = label( "Foo" ); String property = "Bar"; String value = "Baz"; BatchInserter inserter = newBatchInserter(); // When inserter.createDeferredConstraint( label ).assertPropertyIsUnique( property ).create(); inserter.createNode( Collections.singletonMap( property, value ), label ); inserter.createNode( Collections.singletonMap( property, value ), label ); // Then GraphDatabaseService db = switchToEmbeddedGraphDatabaseService( inserter ); try ( Transaction tx = db.beginTx() ) { IndexDefinition index = db.schema().getIndexes( label ).iterator().next(); String indexFailure = db.schema().getIndexFailure( index ); assertThat( indexFailure, containsString( "IndexEntryConflictException" ) ); assertThat( indexFailure, containsString( value ) ); tx.success(); } finally { db.shutdown(); } }
@Test void validateNodePropertiesOnPopulation() { setUp(); Label label = Label.label( "populationTestNodeLabel" ); String propertyName = "populationTestPropertyName"; try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( propertyName, StringUtils.repeat( "a", IndexWriter.MAX_TERM_LENGTH + 1 ) ); transaction.success(); } IndexDefinition indexDefinition = createIndex( label, propertyName ); try { try ( Transaction ignored = database.beginTx() ) { database.schema().awaitIndexesOnline( 5, TimeUnit.MINUTES ); } } catch ( IllegalStateException e ) { try ( Transaction ignored = database.beginTx() ) { String indexFailure = database.schema().getIndexFailure( indexDefinition ); assertThat( "", indexFailure, Matchers.containsString( "java.lang.IllegalArgumentException: Index key-value size it to large. Please see index documentation for limitations." ) ); } } }
IndexDefinition next = iterator.next(); assertEquals( "state is FAILED", Schema.IndexState.FAILED, db.schema().getIndexState( next ) ); assertThat( db.schema().getIndexFailure( next ), Matchers.containsString( "Index key-value size it to large. Please see index documentation for limitations." ) ); tx.success();
@Override public String getIndexFailure( IndexDefinition index ) { return actual.getIndexFailure( index ); }
if ( verbose && state == IndexState.FAILED ) printer.addRaw( schema.getIndexFailure( index ) );