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"));
}
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();
}
}
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);
}
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)));
}
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));
}
Aggregations