@Override protected boolean matchesSafely( Neo4jMatchers.Deferred<IndexDefinition> indexes, Description description ) { for ( IndexDefinition current : indexes.collection() ) { Schema.IndexState currentState = db.schema().getIndexState( current ); if ( !currentState.equals( expectedState ) ) { description.appendValue( current ).appendText( " has state " ).appendValue( currentState ); return false; } } return true; }
public static Object getIndexState( GraphDatabaseService beansAPI, IndexDefinition indexDef ) { try ( Transaction ignored = beansAPI.beginTx() ) { return beansAPI.schema().getIndexState( indexDef ); } }
public ListRepresentation getSchemaIndexes() { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes(); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
public ListRepresentation getSchemaIndexes( String labelName ) { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes( label( labelName ) ); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
@Test public void addedUncommittedIndexesShouldBeVisibleWithinTheTransaction() { // GIVEN IndexDefinition indexA = createIndex( db, label, "a" ); createUniquenessConstraint( label, "b" ); // WHEN try ( Transaction tx = db.beginTx() ) { assertThat( count( db.schema().getIndexes( label ) ), is( 2L ) ); IndexDefinition indexC = db.schema().indexFor( label ).on( "c" ).create(); // THEN assertThat( count( db.schema().getIndexes( label ) ), is( 3L ) ); assertThat( db.schema().getIndexState( indexA ), is( Schema.IndexState.ONLINE ) ); assertThat( db.schema().getIndexState( indexC ), is( Schema.IndexState.POPULATING ) ); } }
private void indexStateShouldBe( Matcher<Schema.IndexState> matchesExpectation ) { try ( Transaction tx = db.beginTx() ) { for ( IndexDefinition index : db.schema().getIndexes() ) { assertThat( db.schema().getIndexState( index ), matchesExpectation ); } tx.success(); } }
@Test public void awaitingIndexComingOnlineWorks() { // GIVEN // WHEN IndexDefinition index = createIndex( db, label, propertyKey ); // PASS try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( index, 1L, TimeUnit.MINUTES ); // THEN assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) ); } }
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; }
assertTrue( iterator.hasNext() ); 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." ) );
@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 shouldThrowWhenPopulatingWithNonUniquePoints() throws Exception { Config config = Config.defaults( stringMap( default_schema_provider.name(), schemaIndex.providerName() ) ); BatchInserter inserter = newBatchInserter( config ); PointValue point = Values.pointValue( CoordinateReferenceSystem.WGS84, 0.0, 0.0 ); inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE ); inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE ); inserter.createDeferredConstraint( TestLabels.LABEL_ONE ).assertPropertyIsUnique( "prop" ).create(); inserter.shutdown(); GraphDatabaseService db = graphDatabaseService( config ); try ( Transaction tx = db.beginTx() ) { Iterator<IndexDefinition> indexes = db.schema().getIndexes().iterator(); assertTrue( indexes.hasNext() ); IndexDefinition index = indexes.next(); Schema.IndexState indexState = db.schema().getIndexState( index ); assertEquals( Schema.IndexState.FAILED, indexState ); assertFalse( indexes.hasNext() ); tx.success(); } finally { db.shutdown(); } }
do state = schema.getIndexState( indexDefinition ); progress = schema.getIndexPopulationProgress( indexDefinition );
@Override public IndexState getIndexState( IndexDefinition index ) { return actual.getIndexState( index ); }
private void awaitIndexes( Output out, org.neo4j.graphdb.schema.Schema schema, Label[] labels, String property ) throws RemoteException { for ( IndexDefinition index : indexesByLabelAndProperty( schema, labels, property ) ) { if ( schema.getIndexState( index ) != IndexState.ONLINE ) { out.println( String.format( "Awaiting :%s ON %s %s", index.getLabel().name(), asList( index.getPropertyKeys() ), IndexState.ONLINE ) ); schema.awaitIndexOnline( index, 10000, TimeUnit.DAYS ); } } }
public ListRepresentation getSchemaIndexes() { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes(); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
public ListRepresentation getSchemaIndexes( String labelName ) { Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes( label( labelName ) ); Iterable<IndexDefinitionRepresentation> representations = map( definition -> new IndexDefinitionRepresentation( definition, graphDb.schema().getIndexState( definition ), graphDb.schema().getIndexPopulationProgress( definition ) ), definitions ); return new ListRepresentation( RepresentationType.INDEX_DEFINITION, representations ); }
.getPropertyKeys() ) ); IndexState state = schema.getIndexState( index ); String uniqueOrNot = index.isConstraintIndex() ? "(for uniqueness constraint)" : "";