use of org.neo4j.graphdb.index.IndexPopulationProgress in project neo4j by neo4j.
the class SchemaImplTest method testGetIndexPopulationProgress.
@Test
public void testGetIndexPopulationProgress() throws Exception {
assertFalse(indexExists(Label.label("User")));
// 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 = db.createNode(label);
userNode.setProperty("username", "user" + id + "@neo4j.org");
}
tx.success();
}
// Create an index
IndexDefinition indexDefinition;
try (Transaction tx = db.beginTx()) {
Schema schema = db.schema();
indexDefinition = schema.indexFor(Label.label("User")).on("username").create();
tx.success();
}
// Get state and progress
try (Transaction tx = db.beginTx()) {
Schema schema = db.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);
assertTrue(state == Schema.IndexState.ONLINE);
assertEquals(100.0f, progress.getCompletedPercentage(), 0.0f);
}
}
use of org.neo4j.graphdb.index.IndexPopulationProgress in project neo4j by neo4j.
the class SchemaImpl method getIndexPopulationProgress.
@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
actions.assertInOpenTransaction();
try (Statement statement = statementContextSupplier.get()) {
ReadOperations readOps = statement.readOperations();
NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
PopulationProgress progress = readOps.indexGetPopulationProgress(descriptor);
return new IndexPopulationProgress(progress.getCompleted(), progress.getTotal());
} catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
}
}
Aggregations