use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method addingAnIndexingRuleInNestedTxShouldSucceed.
@Test
public void addingAnIndexingRuleInNestedTxShouldSucceed() throws Exception {
IndexDefinition index;
// WHEN
IndexDefinition indexDef;
try (Transaction tx = db.beginTx()) {
try (Transaction nestedTransaction = db.beginTx()) {
indexDef = db.schema().indexFor(label).on(propertyKey).create();
nestedTransaction.success();
}
index = indexDef;
tx.success();
}
waitForIndex(db, indexDef);
// THEN
assertThat(getIndexes(db, label), containsOnly(index));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method addingAnIndexingRuleShouldSucceed.
@Test
public void addingAnIndexingRuleShouldSucceed() throws Exception {
// WHEN
IndexDefinition index = createIndex(db, label, propertyKey);
// THEN
assertThat(getIndexes(db, label), containsOnly(index));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method addingACompositeIndexingRuleShouldSucceed.
@Test
public void addingACompositeIndexingRuleShouldSucceed() throws Exception {
// WHEN
IndexDefinition index = createIndex(db, label, propertyKey, secondPropertyKey);
// THEN
assertThat(getIndexes(db, label), containsOnly(index));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaImplTest method indexExists.
private boolean indexExists(Label label) {
try (Transaction transaction = db.beginTx()) {
Iterable<IndexDefinition> indexes = db.schema().getIndexes(label);
IndexDefinition index = Iterables.firstOrNull(indexes);
boolean exists = index != null;
transaction.success();
return exists;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition 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);
}
}
Aggregations