Search in sources :

Example 51 with Relationship

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);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Before(org.junit.Before)

Example 52 with Relationship

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
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 53 with Relationship

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));
}
Also used : Relationship(org.neo4j.graphdb.Relationship)

Example 54 with Relationship

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));
}
Also used : Relationship(org.neo4j.graphdb.Relationship)

Example 55 with Relationship

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)490 Node (org.neo4j.graphdb.Node)370 Test (org.junit.Test)250 Transaction (org.neo4j.graphdb.Transaction)138 LinkedList (java.util.LinkedList)48 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)48 RelationshipType (org.neo4j.graphdb.RelationshipType)38 NotFoundException (org.neo4j.graphdb.NotFoundException)35 Path (org.neo4j.graphdb.Path)29 HashMap (java.util.HashMap)27 Direction (org.neo4j.graphdb.Direction)26 HashSet (java.util.HashSet)24 ArrayList (java.util.ArrayList)18 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)18 Map (java.util.Map)14 WeightedPath (org.neo4j.graphalgo.WeightedPath)14 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)14 List (java.util.List)13 PropertyContainer (org.neo4j.graphdb.PropertyContainer)12 Graph (org.neo4j.test.GraphDescription.Graph)11