use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class LuceneIndexRecoveryIT method removeShouldBeIdempotentWhenDoingRecovery.
@Test
public void removeShouldBeIdempotentWhenDoingRecovery() throws Exception {
// Given
startDb(createLuceneIndexFactory());
IndexDefinition indexDefinition = createIndex(myLabel);
waitForIndex(indexDefinition);
long node = createNode(myLabel, 12);
rotateLogsAndCheckPoint();
deleteNode(node);
// And Given
killDb();
// When
startDb(createLuceneIndexFactory());
// Then
assertEquals(0, doIndexLookup(myLabel, 12).size());
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class IndexValuesValidationTest method createIndex.
private IndexDefinition createIndex(Label label, String propertyName) {
try (Transaction transaction = database.beginTx()) {
IndexDefinition indexDefinition = database.schema().indexFor(label).on(propertyName).create();
transaction.success();
return indexDefinition;
}
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class IndexSamplingIntegrationTest method shouldSampleNotUniqueIndex.
@Test
public void shouldSampleNotUniqueIndex() throws Throwable {
GraphDatabaseService db = null;
long deletedNodes = 0;
try {
// Given
db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
IndexDefinition indexDefinition;
try (Transaction tx = db.beginTx()) {
indexDefinition = db.schema().indexFor(label).on(property).create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < nodes; i++) {
db.createNode(label).setProperty(property, names[i % names.length]);
tx.success();
}
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < (nodes / 10); i++) {
db.findNodes(label, property, names[i % names.length]).next().delete();
deletedNodes++;
tx.success();
}
}
} finally {
if (db != null) {
db.shutdown();
}
}
// When
triggerIndexResamplingOnNextStartup();
// Then
// sampling will consider also the delete nodes till the next lucene compaction
DoubleLongRegister register = fetchIndexSamplingValues(db);
assertEquals(names.length, register.readFirst());
assertEquals(nodes, register.readSecond());
// but the deleted nodes should not be considered in the index size value
DoubleLongRegister indexSizeRegister = fetchIndexSizeValues(db);
assertEquals(0, indexSizeRegister.readFirst());
assertEquals(nodes - deletedNodes, indexSizeRegister.readSecond());
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class CypherResultSubGraph method from.
public static SubGraph from(Result result, GraphDatabaseService gds, boolean addBetween) {
final CypherResultSubGraph graph = new CypherResultSubGraph();
final List<String> columns = result.columns();
for (Map<String, Object> row : loop(result)) {
for (String column : columns) {
final Object value = row.get(column);
graph.addToGraph(value);
}
}
for (IndexDefinition def : gds.schema().getIndexes()) {
if (graph.getLabels().contains(def.getLabel())) {
graph.addIndex(def);
}
}
for (ConstraintDefinition def : gds.schema().getConstraints()) {
if (graph.getLabels().contains(def.getLabel())) {
graph.addConstraint(def);
}
}
if (addBetween) {
graph.addRelationshipsBetweenNodes();
}
return graph;
}
use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.
the class SubGraphExporter method exportIndexes.
private Collection<String> exportIndexes() {
final List<String> result = new ArrayList<>();
for (IndexDefinition index : graph.getIndexes()) {
if (!index.isConstraintIndex()) {
Iterator<String> propertyKeys = index.getPropertyKeys().iterator();
if (!propertyKeys.hasNext()) {
throw new IllegalStateException("Indexes should have at least one property key");
}
String key = quote(propertyKeys.next());
if (propertyKeys.hasNext()) {
throw new RuntimeException("Exporting compound indexes is not implemented yet");
}
String label = quote(index.getLabel().name());
result.add("create index on :" + label + "(" + key + ")");
}
}
Collections.sort(result);
return result;
}
Aggregations