Search in sources :

Example 56 with IndexDefinition

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;
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) PropertyConstraint(org.neo4j.kernel.api.constraints.PropertyConstraint) NodePropertyExistenceConstraint(org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) RelationshipPropertyConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint) NodePropertyConstraint(org.neo4j.kernel.api.constraints.NodePropertyConstraint) RelationshipPropertyExistenceConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint)

Example 57 with IndexDefinition

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)));
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 58 with IndexDefinition

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));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 59 with IndexDefinition

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();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 60 with IndexDefinition

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));
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Aggregations

IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)84 Test (org.junit.Test)56 Transaction (org.neo4j.graphdb.Transaction)32 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 Node (org.neo4j.graphdb.Node)9 Statement (org.neo4j.kernel.api.Statement)7 ArrayList (java.util.ArrayList)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Iterator (java.util.Iterator)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionData (org.neo4j.graphdb.event.TransactionData)2 TransactionEventHandler (org.neo4j.graphdb.event.TransactionEventHandler)2 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2