use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestAutoIndexReopen method testForceOpenIfChanged.
@Test
public void testForceOpenIfChanged() {
// do some actions to force the indexreader to be reopened
try (Transaction tx = graphDb.beginTx()) {
Node node1 = graphDb.getNodeById(id1);
Node node2 = graphDb.getNodeById(id2);
Node node3 = graphDb.getNodeById(id3);
node1.setProperty("np2", "test property");
node1.getRelationships(RelationshipType.withName("FOO")).forEach(r -> {
r.delete();
});
// check first node
assertEquals(0, relationShipAutoIndex().get("type", "FOO", node1, node3).size());
// create second relation ship
Relationship rel = node1.createRelationshipTo(node3, RelationshipType.withName("FOO"));
rel.setProperty("type", "FOO");
// check second node -> crashs with old FullTxData
assertEquals(0, relationShipAutoIndex().get("type", "FOO", node1, node2).size());
// create second relation ship
rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
rel.setProperty("type", "FOO");
assertEquals(1, relationShipAutoIndex().get("type", "FOO", node1, node2).size());
tx.success();
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestAutoIndexReopen method startDb.
@Before
public void startDb() {
graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(new HashMap<>()).newGraphDatabase();
try (Transaction tx = graphDb.beginTx()) {
// Create the node and relationship auto-indexes
graphDb.index().getNodeAutoIndexer().setEnabled(true);
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("type");
tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Node node3 = graphDb.createNode();
id1 = node1.getId();
id2 = node2.getId();
id3 = node3.getId();
Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
rel.setProperty("type", "FOO");
tx.success();
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestAutoIndexing method testRemoveRelationshipRemovesDocument.
@Test
public void testRemoveRelationshipRemovesDocument() {
AutoIndexer<Relationship> autoIndexer = graphDb.index().getRelationshipAutoIndexer();
autoIndexer.startAutoIndexingProperty("foo");
autoIndexer.setEnabled(true);
newTransaction();
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("foo"));
rel.setProperty("foo", "bar");
newTransaction();
assertThat(graphDb.index().forRelationships("relationship_auto_index").query("_id_:*").size(), equalTo(1));
newTransaction();
rel.delete();
newTransaction();
assertThat(graphDb.index().forRelationships("relationship_auto_index").query("_id_:*").size(), equalTo(0));
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestLuceneIndex method makeSureYouCanRemoveFromRelationshipIndex.
@Test
public void makeSureYouCanRemoveFromRelationshipIndex() {
Node n1 = graphDb.createNode();
Node n2 = graphDb.createNode();
Relationship r = n1.createRelationshipTo(n2, withName("foo"));
RelationshipIndex index = graphDb.index().forRelationships("rel-index");
String key = "bar";
index.remove(r, key, "value");
index.add(r, key, "otherValue");
for (int i = 0; i < 2; i++) {
assertThat(index.get(key, "value"), emptyIterable());
assertThat(index.get(key, "otherValue"), Contains.contains(r));
restartTx();
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestLuceneIndex method removingAnIndexedRelationshipWillAlsoRemoveItFromTheIndex.
@Test
public void removingAnIndexedRelationshipWillAlsoRemoveItFromTheIndex() {
Index<Relationship> index = relationshipIndex(LuceneIndexImplementation.EXACT_CONFIG);
Node a = graphDb.createNode();
Node b = graphDb.createNode();
Relationship rel = a.createRelationshipTo(b, withName("REL"));
rel.setProperty("poke", 1);
index.add(rel, "key", "value");
commitTx();
beginTx();
rel.delete();
commitTx();
beginTx();
IndexHits<Relationship> rels = index.get("key", "value");
// IndexHits.size is allowed to be inaccurate in this case:
assertThat(rels.size(), isOneOf(0, 1));
for (Relationship r : rels) {
r.getProperty("poke");
fail("Found relationship " + r);
}
commitTx();
beginTx();
IndexHits<Relationship> relsAgain = index.get("key", "value");
// After a read, the index should be repaired:
assertThat(relsAgain.size(), is(0));
for (Relationship r : relsAgain) {
r.getProperty("poke");
fail("Found relationship " + r);
}
}
Aggregations