use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaImpl method getIndexes.
@Override
public Iterable<IndexDefinition> getIndexes(final Label label) {
try (Statement statement = statementContextSupplier.get()) {
List<IndexDefinition> definitions = new ArrayList<>();
int labelId = statement.readOperations().labelGetForName(label.name());
if (labelId == KeyReadOperations.NO_SUCH_LABEL) {
return emptyList();
}
addDefinitions(definitions, statement.readOperations(), statement.readOperations().indexesGetForLabel(labelId), false);
addDefinitions(definitions, statement.readOperations(), statement.readOperations().uniqueIndexesGetForLabel(labelId), true);
return definitions;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSeparateTransactions.
@Test
public void droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSeparateTransactions() throws Exception {
// GIVEN
IndexDefinition index = createIndex(db, label, propertyKey);
dropIndex(index);
// WHEN
try {
dropIndex(index);
fail("Should not be able to drop index twice");
} catch (ConstraintViolationException e) {
assertThat(e.getMessage(), containsString("No index was found for :MY_LABEL(my_property_key)."));
}
// THEN
assertThat("Index should have been deleted", getIndexes(db, label), not(contains(index)));
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method awaitingIndexComingOnlineWorks.
@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));
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaIndexWaitingAcceptanceTest method shouldTimeoutWatingForIndexToComeOnline.
@Test
public void shouldTimeoutWatingForIndexToComeOnline() throws Exception {
// given
GraphDatabaseService db = rule.getGraphDatabaseAPI();
DoubleLatch latch = provider.installPopulationJobCompletionLatch();
IndexDefinition index;
try (Transaction tx = db.beginTx()) {
index = db.schema().indexFor(Label.label("Person")).on("name").create();
tx.success();
}
latch.waitForAllToStart();
// when
try (Transaction tx = db.beginTx()) {
// then
db.schema().awaitIndexOnline(index, 1, TimeUnit.MILLISECONDS);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
// good
assertThat(e.getMessage(), containsString("come online"));
} finally {
latch.finish();
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldRecreateDroppedIndex.
@Test
public void shouldRecreateDroppedIndex() throws Exception {
// GIVEN
Node node = createNode(db, propertyKey, "Neo", label);
// create an index
IndexDefinition index = createIndex(db, label, propertyKey);
waitForIndex(db, index);
// delete the index right away
dropIndex(index);
// WHEN recreating that index
createIndex(db, label, propertyKey);
waitForIndex(db, index);
// THEN it should exist and be usable
assertThat(getIndexes(db, label), contains(index));
assertThat(findNodesByLabelAndProperty(label, propertyKey, "Neo", db), containsOnly(node));
}
Aggregations