Search in sources :

Example 6 with IndexDefinition

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

Example 7 with IndexDefinition

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

Example 8 with IndexDefinition

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

Example 9 with IndexDefinition

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

Example 10 with IndexDefinition

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);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) Node(org.neo4j.graphdb.Node) Schema(org.neo4j.graphdb.schema.Schema) Label(org.neo4j.graphdb.Label) 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