use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestBatchInsert method testGraphDbServiceGetRelationships.
@Test
public void testGraphDbServiceGetRelationships() {
BatchInserter batchInserter = newBatchInserter();
GraphDatabaseService graphDb = batchInserter.getGraphDbService();
Node startNode = graphDb.createNode();
for (int i = 0; i < 5; i++) {
Node endNode = graphDb.createNode();
startNode.createRelationshipTo(endNode, relTypeArray[i]);
}
try {
startNode.createRelationshipTo(startNode, relTypeArray[0]);
fail("Could create relationship with same start and end node");
} catch (IllegalArgumentException e) {
// ok good
}
for (int i = 0; i < 5; i++) {
assertTrue(startNode.getSingleRelationship(relTypeArray[i], Direction.OUTGOING) != null);
}
for (int i = 0; i < 5; i++) {
Iterator<Relationship> relItr = startNode.getRelationships(relTypeArray[i], Direction.OUTGOING).iterator();
relItr.next();
assertTrue(!relItr.hasNext());
}
for (int i = 0; i < 5; i++) {
Iterator<Relationship> relItr = startNode.getRelationships(relTypeArray[i]).iterator();
relItr.next();
assertTrue(!relItr.hasNext());
}
graphDb.shutdown();
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestBigStore method createAndVerifyGraphStartingWithId.
private void createAndVerifyGraphStartingWithId(long startId, int requiredHeapMb) throws Exception {
assumeTrue(machineIsOkToRunThisTest(testName.getMethodName(), requiredHeapMb));
/*
* Will create a layout like this:
*
* (refNode) --> (node) --> (highNode)
* ...
* ...
*
* Each node/relationship will have a bunch of different properties on them.
*/
setHighIds(startId - 1000);
byte[] bytes = new byte[45];
bytes[2] = 5;
bytes[10] = 42;
Map<String, Object> properties = map("number", 11, "short string", "test", "long string", "This is a long value, long enough", "array", bytes);
Transaction tx = db.beginTx();
int count = 10000;
for (int i = 0; i < count; i++) {
Node node = db.createNode();
setProperties(node, properties);
Relationship rel = db.getReferenceNode().createRelationshipTo(node, this);
setProperties(rel, properties);
Node highNode = db.createNode();
node.createRelationshipTo(highNode, OTHER_TYPE);
setProperties(highNode, properties);
if (i % 100 == 0 && i > 0) {
tx.success();
tx.finish();
tx = db.beginTx();
}
}
tx.success();
tx.finish();
db.shutdown();
db = new EmbeddedGraphDatabase(PATH);
// Verify the data
int verified = 0;
for (Relationship rel : db.getReferenceNode().getRelationships(Direction.OUTGOING)) {
Node node = rel.getEndNode();
assertProperties(properties, node);
assertProperties(properties, rel);
Node highNode = node.getSingleRelationship(OTHER_TYPE, Direction.OUTGOING).getEndNode();
assertProperties(properties, highNode);
verified++;
}
assertEquals(count, verified);
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestNeo4j method testIdUsageInfo.
// private static enum RelTypes implements RelationshipType
// {
// ONE_MORE_RELATIONSHIP;
// }
// TODO: fix this testcase
@Test
public void testIdUsageInfo() {
GraphDbModule graphDbModule = ((EmbeddedGraphDatabase) getGraphDb()).getConfig().getGraphDbModule();
NodeManager nm = graphDbModule.getNodeManager();
long nodeCount = nm.getNumberOfIdsInUse(Node.class);
long relCount = nm.getNumberOfIdsInUse(Relationship.class);
if (nodeCount > nm.getHighestPossibleIdInUse(Node.class)) {
// fail( "Node count greater than highest id " + nodeCount );
}
if (relCount > nm.getHighestPossibleIdInUse(Relationship.class)) {
// fail( "Rel count greater than highest id " + relCount );
}
// assertTrue( nodeCount <= nm.getHighestPossibleIdInUse( Node.class )
// );
// assertTrue( relCount <= nm.getHighestPossibleIdInUse(
// Relationship.class ) );
Node n1 = nm.createNode();
Node n2 = nm.createNode();
Relationship r1 = n1.createRelationshipTo(n2, MyRelTypes.TEST);
// assertEquals( nodeCount + 2, nm.getNumberOfIdsInUse( Node.class ) );
// assertEquals( relCount + 1, nm.getNumberOfIdsInUse(
// Relationship.class ) );
r1.delete();
n1.delete();
n2.delete();
// must commit for ids to be reused
try {
getTransaction().success();
getTransaction().finish();
} catch (Exception e) {
fail("" + e);
}
// assertEquals( nodeCount, nm.getNumberOfIdsInUse( Node.class ) );
// assertEquals( relCount, nm.getNumberOfIdsInUse( Relationship.class )
// );
setTransaction(getGraphDb().beginTx());
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestNeo4jApiExceptions method testNotFoundException.
@Test
public void testNotFoundException() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
long nodeId = node1.getId();
long relId = rel.getId();
rel.delete();
node2.delete();
node1.delete();
newTransaction();
try {
getGraphDb().getNodeById(nodeId);
fail("Get node by id on deleted node should throw exception");
} catch (NotFoundException e) {
// good
}
try {
getGraphDb().getRelationshipById(relId);
fail("Get relationship by id on deleted node should " + "throw exception");
} catch (NotFoundException e) {
// good
}
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestNeo4jApiExceptions method testNotInTransactionException.
@Test
public void testNotInTransactionException() {
Node node1 = getGraphDb().createNode();
node1.setProperty("test", 1);
Node node2 = getGraphDb().createNode();
Node node3 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
rel.setProperty("test", 11);
commit();
try {
getGraphDb().createNode();
fail("Create node with no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.createRelationshipTo(node2, MyRelTypes.TEST);
fail("Create relationship with no transaction should " + "throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.setProperty("test", 2);
fail("Set property with no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
rel.setProperty("test", 22);
fail("Set property with no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node3.delete();
fail("Delete node with no transaction should " + "throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
rel.delete();
fail("Delete relationship with no transaction should " + "throw exception");
} catch (NotInTransactionException e) {
// good
}
newTransaction();
assertEquals(node1.getProperty("test"), 1);
assertEquals(rel.getProperty("test"), 11);
assertEquals(rel, node1.getSingleRelationship(MyRelTypes.TEST, Direction.OUTGOING));
node1.delete();
node2.delete();
rel.delete();
node3.delete();
}
Aggregations