use of org.neo4j.graphdb.schema.IndexPopulationProgress in project neo4j by neo4j.
the class SchemaImplTest method testGetIndexPopulationProgress.
@Test
void testGetIndexPopulationProgress() throws Exception {
assertFalse(indexExists(USER_LABEL));
// Create some nodes
try (Transaction tx = db.beginTx()) {
Label label = Label.label("User");
// Create a huge bunch of users so the index takes a while to build
for (int id = 0; id < 100000; id++) {
Node userNode = tx.createNode(label);
userNode.setProperty("username", "user" + id + "@neo4j.org");
}
tx.commit();
}
// Create an index
IndexDefinition indexDefinition;
try (Transaction tx = db.beginTx()) {
Schema schema = tx.schema();
indexDefinition = schema.indexFor(USER_LABEL).on("username").create();
tx.commit();
}
// Get state and progress
try (Transaction tx = db.beginTx()) {
Schema schema = tx.schema();
Schema.IndexState state;
IndexPopulationProgress progress;
do {
state = schema.getIndexState(indexDefinition);
progress = schema.getIndexPopulationProgress(indexDefinition);
assertTrue(progress.getCompletedPercentage() >= 0);
assertTrue(progress.getCompletedPercentage() <= 100);
Thread.sleep(10);
} while (state == Schema.IndexState.POPULATING);
assertSame(state, Schema.IndexState.ONLINE);
assertEquals(100.0, progress.getCompletedPercentage(), 0.0001);
}
}
use of org.neo4j.graphdb.schema.IndexPopulationProgress in project neo4j by neo4j.
the class SchemaImpl method getIndexPopulationProgress.
@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
try {
transaction.assertOpen();
SchemaRead schemaRead = transaction.schemaRead();
IndexDescriptor descriptor = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
PopulationProgress progress = schemaRead.indexGetPopulationProgress(descriptor);
return progress.toIndexPopulationProgress();
} catch (KernelException e) {
throw newIndexNotFoundException(index, e);
}
}
Aggregations