Search in sources :

Example 51 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestRelationship method setPropertyAndClearCacheBeforeCommit.

@Test
public void setPropertyAndClearCacheBeforeCommit() throws Exception {
    Node node = getGraphDb().createNode();
    node.setProperty("name", "Test");
    assertEquals("Test", node.getProperty("name"));
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 52 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestRelationship method deletionOfAlreadyDeletedRelationshipShouldThrow.

@Test(expected = NotFoundException.class)
public void deletionOfAlreadyDeletedRelationshipShouldThrow() {
    // Given
    GraphDatabaseService db = getGraphDb();
    // transaction is opened by test
    Node node1 = db.createNode();
    Node node2 = db.createNode();
    Relationship relationship = node1.createRelationshipTo(node2, TEST);
    commit();
    try (Transaction tx = db.beginTx()) {
        relationship.delete();
        tx.success();
    }
    // When
    try (Transaction tx = db.beginTx()) {
        relationship.delete();
        tx.success();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 53 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestRelationship method deleteRelsWithCommitInMiddle.

@Test
public void deleteRelsWithCommitInMiddle() throws Exception {
    Node node = getGraphDb().createNode();
    Node otherNode = getGraphDb().createNode();
    RelationshipType[] types = new RelationshipType[] { withName("r1"), withName("r2"), withName("r3"), withName("r4") };
    // 30*4 > 100 (rel grabSize)
    int count = 30;
    for (int i = 0; i < types.length * count; i++) {
        node.createRelationshipTo(otherNode, types[i % types.length]);
    }
    newTransaction();
    int delCount = 0;
    int loopCount = 0;
    while (delCount < count) {
        loopCount++;
        for (Relationship rel : node.getRelationships(types[1])) {
            rel.delete();
            if (++delCount == count / 2) {
                newTransaction();
            }
        }
    }
    assertEquals(1, loopCount);
    assertEquals(count, delCount);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 54 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestLengthyArrayPacking method bitPackingOfLengthyArrays.

@Test
public void bitPackingOfLengthyArrays() throws Exception {
    long arrayRecordsBefore = dynamicArrayRecordsInUse();
    // Store an int array which would w/o packing require two dynamic records
    // 4*40 = 160B (assuming data size of 120B)
    int[] arrayWhichUnpackedWouldFillTwoDynamicRecords = new int[40];
    for (int i = 0; i < arrayWhichUnpackedWouldFillTwoDynamicRecords.length; i++) {
        arrayWhichUnpackedWouldFillTwoDynamicRecords[i] = i * i;
    }
    Node node = getGraphDb().createNode();
    String key = "the array";
    node.setProperty(key, arrayWhichUnpackedWouldFillTwoDynamicRecords);
    newTransaction();
    // Make sure it only requires one dynamic record
    assertEquals(arrayRecordsBefore + 1, dynamicArrayRecordsInUse());
    assertTrue(Arrays.equals(arrayWhichUnpackedWouldFillTwoDynamicRecords, (int[]) node.getProperty(key)));
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 55 with Node

use of org.neo4j.graphdb.Node in project neo4j by neo4j.

the class TestLoopRelationships method getNewlyCreatedLoopRelationshipFromCache.

@Test
public void getNewlyCreatedLoopRelationshipFromCache() throws Exception {
    Node node = getGraphDb().createNode();
    node.createRelationshipTo(getGraphDb().createNode(), TEST);
    newTransaction();
    Relationship relationship = node.createRelationshipTo(node, TEST);
    newTransaction();
    assertEquals(relationship, node.getSingleRelationship(TEST, Direction.INCOMING));
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

Node (org.neo4j.graphdb.Node)1281 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)375 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 LinkedList (java.util.LinkedList)60 RelationshipType (org.neo4j.graphdb.RelationshipType)58 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)45 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26