Search in sources :

Example 66 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class DatabaseActionsTest method shouldCreateSchemaIndex.

@Test
public void shouldCreateSchemaIndex() throws Exception {
    // GIVEN
    String labelName = "person", propertyKey = "name";
    // WHEN
    actions.createSchemaIndex(labelName, Arrays.asList(propertyKey));
    // THEN
    try (Transaction transaction = graph.beginTx()) {
        Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes(labelName);
        assertEquals(1, Iterables.count(defs));
        assertEquals(propertyKey, firstOrNull(firstOrNull(defs).getPropertyKeys()));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 67 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class Neo4jMatchers method createIndexNoWait.

public static IndexDefinition createIndexNoWait(GraphDatabaseService beansAPI, Label label, String... properties) {
    IndexDefinition indexDef;
    try (Transaction tx = beansAPI.beginTx()) {
        IndexCreator indexCreator = beansAPI.schema().indexFor(label);
        for (String property : properties) {
            indexCreator = indexCreator.on(property);
        }
        indexDef = indexCreator.create();
        tx.success();
    }
    return indexDef;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 68 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class IndexConstraintsTest method convertIndexToConstraint.

// The following tests verify that multiple interacting schema commands can be applied in the same transaction.
@Test
public void convertIndexToConstraint() {
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.schema().indexFor(LABEL).on(PROPERTY_KEY).create();
        tx.success();
    }
    try (Transaction tx = graphDb.beginTx()) {
        IndexDefinition index = firstOrNull(graphDb.schema().getIndexes(LABEL));
        index.drop();
        graphDb.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
        tx.success();
    }
// assert no exception is thrown
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 69 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class TestLuceneSchemaBatchInsertIT method shouldLoadAndUseLuceneProvider.

@Test
public void shouldLoadAndUseLuceneProvider() throws Exception {
    // GIVEN
    File storeDir = testDirectory.graphDbDir();
    BatchInserter inserter = BatchInserters.inserter(storeDir, fileSystemRule.get());
    inserter.createDeferredSchemaIndex(LABEL).on("name").create();
    // WHEN
    inserter.createNode(map("name", "Mattias"), LABEL);
    inserter.shutdown();
    // THEN
    GraphDatabaseFactory graphDatabaseFactory = new TestGraphDatabaseFactory();
    GraphDatabaseAPI db = (GraphDatabaseAPI) graphDatabaseFactory.newEmbeddedDatabase(storeDir);
    DependencyResolver dependencyResolver = db.getDependencyResolver();
    SchemaIndexProvider schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
    // assert the indexProvider is a Lucene one
    try (Transaction ignore = db.beginTx()) {
        IndexDefinition indexDefinition = Iterables.single(db.schema().getIndexes(LABEL));
        assertThat(db.schema().getIndexState(indexDefinition), is(Schema.IndexState.ONLINE));
        assertThat(schemaIndexProvider, instanceOf(LuceneSchemaIndexProvider.class));
    }
    // CLEANUP
    db.shutdown();
}
Also used : LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 70 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class SchemaIndexAcceptanceTest method recoveryAfterCreateAndDropIndex.

@Test
public void recoveryAfterCreateAndDropIndex() throws Exception {
    // GIVEN
    IndexDefinition indexDefinition = createIndex(db, label, propertyKey);
    createSomeData(label, propertyKey);
    doStuff(db, label, propertyKey);
    dropIndex(indexDefinition);
    doStuff(db, label, propertyKey);
    // WHEN
    crashAndRestart();
    // THEN
    assertThat(getIndexes(db, label), isEmpty());
}
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