[Neo4j] Using in-memory DB for unit tests
Jon Walton
jon.w.walton at gmail.com
Wed Nov 30 05:49:05 CET 2011
On Tue, Nov 29, 2011 at 7:20 PM, Linan Wang <tali.wang at gmail.com> wrote:
> Why call tx.failure in close db?
>
To assure a pristine DB between unit tests, as suggested here:
http://wiki.neo4j.org/content/Testing_with_Neo4j
I don't think this is the cause of my problem as the exception gets thrown
before the call to roll back the TX.
>
> On Wednesday, November 30, 2011, Jon Walton <jon.w.walton at gmail.com>
> wrote:
> > Greetings - I have started my first project using neo4j, and am having
> some
> > trouble with unit tests. I must be missing something, but when I
> retrieve
> > a node using an incoming direction, I am unable to get properties from
> that
> > node. The first test works fine, the second one fails with a
> > NotFoundException on the property "asn". (although it does find the
> > end-node with no trouble) Can anyone point out what I am doing wrong?
> >
> > Thanks,
> >
> > Jon
> >
> > /**
> > * $Id$
> > */
> > package com.mcafee.tsw.webgraph;
> >
> > import org.junit.After;
> > import org.junit.Before;
> > import org.junit.Test;
> > import org.neo4j.graphdb.Direction;
> > import org.neo4j.graphdb.GraphDatabaseService;
> > import org.neo4j.graphdb.Node;
> > import org.neo4j.graphdb.RelationshipType;
> > import org.neo4j.graphdb.Transaction;
> > import org.neo4j.test.ImpermanentGraphDatabase;
> >
> > /**
> > */
> > public class TestMe {
> >
> > private GraphDatabaseService svc;
> > private Transaction tx;
> >
> > /**
> > * @throws java.lang.Exception
> > */
> > @Before
> > public void initDB() throws Exception {
> > svc = new ImpermanentGraphDatabase();
> > tx = svc.beginTx();
> > }
> >
> > /**
> > * @throws java.lang.Exception
> > */
> > @After
> > public void closeDB() throws Exception {
> > tx.failure();
> > tx.finish();
> > svc.shutdown();
> > svc = null;
> > }
> >
> > // This one works.
> > @Test
> > public void testOutgoing() {
> >
> > Node network = svc.createNode();
> > Node as = svc.createNode();
> >
> > as.setProperty("asn", "123");
> > network.createRelationshipTo(as, IPAddressRelationshipType.AS);
> >
> >
> >
>
> System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS,
> > Direction.OUTGOING)
> > .getEndNode().getProperty("asn"));
> >
> > }
> >
> > // This one results in a not found exception on the 'asn' property.
> > @Test
> > public void testIncoming() {
> >
> > Node network = svc.createNode();
> > Node as = svc.createNode();
> > as.setProperty("asn", "123");
> >
> > as.createRelationshipTo(network, IPAddressRelationshipType.AS);
> >
> >
> >
>
> System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS,
> > Direction.INCOMING)
> > .getEndNode().getProperty("asn"));
> >
> > }
> >
> > }
> > _______________________________________________
> > Neo4j mailing list
> > User at lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
>
> --
> Best wishes,
>
> Linan Wang
> Architect, Programmer, PhD
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
More information about the User
mailing list