use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestNeo4jCacheAndPersistence method createTestingGraph.
@Before
public void createTestingGraph() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
node1Id = node1.getId();
node2Id = node2.getId();
node1.setProperty(key1, int1);
node1.setProperty(key2, string1);
node2.setProperty(key1, int2);
node2.setProperty(key2, string2);
rel.setProperty(key1, int1);
rel.setProperty(key2, string1);
node1.setProperty(arrayKey, array);
node2.setProperty(arrayKey, array);
rel.setProperty(arrayKey, array);
Transaction tx = getTransaction();
tx.success();
tx.finish();
NodeManager nodeManager = ((EmbeddedGraphDatabase) getGraphDb()).getConfig().getGraphDbModule().getNodeManager();
nodeManager.clearCache();
tx = getGraphDb().beginTx();
setTransaction(tx);
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestNeo4jConstrains method testMultipleDeleteRelationship.
@Test
public void testMultipleDeleteRelationship() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
rel.delete();
node1.delete();
node2.delete();
try {
rel.delete();
Transaction tx = getTransaction();
tx.success();
tx.finish();
fail("Should not validate");
} catch (Exception e) {
// ok
}
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestExceptionTypeOnInvalidIds method getRelationshipById.
private void getRelationshipById(long index) {
Relationship value = graphdb.getRelationshipById(index);
fail(String.format("Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index));
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestExceptionTypeOnInvalidIds method getRelationshipByIdReadOnly.
private void getRelationshipByIdReadOnly(long index) {
Relationship value = graphDbReadOnly.getRelationshipById(index);
fail(String.format("Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index));
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestIsolation method testSimpleTransactionIsolation.
@Test
public void testSimpleTransactionIsolation() {
commit();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Transaction tx = getGraphDb().beginTx();
Node n1, n2;
Relationship r1;
try {
n1 = getGraphDb().createNode();
n2 = getGraphDb().createNode();
r1 = n1.createRelationshipTo(n2, DynamicRelationshipType.withName("TEST"));
tx.success();
} finally {
tx.finish();
}
final Node node1 = n1;
final Node node2 = n2;
final Relationship rel1 = r1;
tx = getGraphDb().beginTx();
try {
node1.setProperty("key", "old");
rel1.setProperty("key", "old");
tx.success();
} finally {
tx.finish();
}
assertPropertyEqual(node1, "key", "old");
assertPropertyEqual(rel1, "key", "old");
assertRelationshipCount(node1, 1);
assertRelationshipCount(node2, 1);
Thread t1 = new Thread(new Runnable() {
public void run() {
Transaction tx = getGraphDb().beginTx();
try {
node1.setProperty("key", "new");
rel1.setProperty("key", "new");
node1.createRelationshipTo(node2, DynamicRelationshipType.withName("TEST"));
assertPropertyEqual(node1, "key", "new");
assertPropertyEqual(rel1, "key", "new");
assertRelationshipCount(node1, 2);
assertRelationshipCount(node2, 2);
latch1.countDown();
latch2.await();
assertPropertyEqual(node1, "key", "new");
assertPropertyEqual(rel1, "key", "new");
assertRelationshipCount(node1, 2);
assertRelationshipCount(node2, 2);
// no tx.success();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.interrupted();
} finally {
tx.finish();
assertPropertyEqual(node1, "key", "old");
assertPropertyEqual(rel1, "key", "old");
assertRelationshipCount(node1, 1);
assertRelationshipCount(node2, 1);
}
}
});
t1.start();
try {
latch1.await();
} catch (InterruptedException e) {
Thread.interrupted();
}
assertPropertyEqual(node1, "key", "old");
assertPropertyEqual(rel1, "key", "old");
assertRelationshipCount(node1, 1);
assertRelationshipCount(node2, 1);
latch2.countDown();
try {
t1.join();
} catch (InterruptedException e) {
Thread.interrupted();
}
assertPropertyEqual(node1, "key", "old");
assertPropertyEqual(rel1, "key", "old");
assertRelationshipCount(node1, 1);
assertRelationshipCount(node2, 1);
tx = getGraphDb().beginTx();
try {
for (Relationship rel : node1.getRelationships()) {
rel.delete();
}
node1.delete();
node2.delete();
tx.success();
} finally {
tx.finish();
}
}
Aggregations