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()));
}
}
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;
}
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
}
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();
}
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());
}
Aggregations