Hi,
I am trying to verify simple transactional behavior of EmbeddedNeo
together with NeoIndexService and run into a strange and rather
inconsistent errors. Attached are the relevant parts from a simple Maven
project I used for testing. Simply issue 'mvn archetype:create -e
-DgroupId=com.neo4j.test -DartifactId=transaction' and copy the files
into the respective folders. Note, that the order in how I execute tests
are relevant. Furthermore, I tried this with and without Spring
integration and Neo 1.0-b7, 1.0-b8, and trunk. So, here goes:
[mvn clean install]
This will lead to both test classes failing due to
'org.neo4j.api.core.NotFoundException: Node[7] not found' exception.
[mvn test -Dtest=org.neo4j.test.TransactionRollbackTest]
Same error as above for this test.
[mvn test -Dtest=org.neo4j.test.TransactionCommitTest]
Surprisingly succeeds.
[mvn test -Dtest=org.neo4j.test.TransactionRollbackTest]
Surprisingly succeeds this time.
[mvn clean install]
Surprisingly succeeds this time for all tests.
Here's also a more detailed example of the exception:
org.neo4j.api.core.NotFoundException: Node[7] not found.
at org.neo4j.impl.core.NodeManager.getNodeForProxy(NodeManager.java:431)
at
org.neo4j.impl.core.NodeProxy.getSingleRelationship(NodeProxy.java:98)
at org.neo4j.util.btree.TreeNode.getFirstEntry(TreeNode.java:181)
at org.neo4j.util.btree.TreeNode.getEntry(TreeNode.java:398)
at org.neo4j.util.btree.BTree.getAsKeyEntry(BTree.java:341)
at
org.neo4j.util.index.AbstractIndex.getSingleNodeFor(AbstractIndex.java:393)
at
org.neo4j.util.index.MultiValueIndex.getSingleNodeFor(MultiValueIndex.java:34)
at
org.neo4j.util.index.NeoIndexService.getSingleNode(NeoIndexService.java:140)
at
org.neo4j.test.TransactionRollbackTest.hasNewNode(TransactionRollbackTest.java:66)
at
org.neo4j.test.TransactionRollbackTest.testProgramaticNeoMultiRollback(TransactionRollbackTest.java:32)
As mentioned above already I tried this test scenario with and without
the Spring test integration and arrived at the same results. Can anyone
explain the reason for these inconsistencies or what I am doing wrong?
Help is very much appreciated!
Thank you,
-Andreas
---
package org.neo4j.test;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.neo4j.api.core.NeoService;
import org.neo4j.api.core.Node;
import org.neo4j.api.core.Transaction;
import org.neo4j.api.core.RelationshipType;
import org.neo4j.util.index.IndexService;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {/applicationContext-test.xml})
public class TransactionCommitTest {
@Autowired
protected NeoService neoService = null;
@Autowired
protected IndexService neoIndexService = null;
@Test
public void testProgramaticNeoMultiCommit() {
String testValue = String.valueOf(System.nanoTime());
assertTrue(No node expected, !hasNewNode(testValue));
insertNewNodeAndCommit(testValue);
assertTrue(Node expected, hasNewNode(testValue));
testValue = String.valueOf(System.nanoTime());
assertTrue(No node expected, !hasNewNode(testValue));
insertNewNodeAndCommit(testValue);
assertTrue(Node expected, hasNewNode(testValue));
}
private void insertNewNodeAndCommit(String testValue) {
Transaction tx = null;
try {
tx = neoService.beginTx();
Node newNode = neoService.createNode();
newNode.setProperty(id, testValue);
neoService.getReferenceNode().createRelationshipTo(newNode,
NeoRelationshipTypes.LINKS_TO);
neoIndexService.index(newNode, id, testValue);
tx.success();
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
tx.finish();
}
}
private boolean hasNewNode(String testValue) {
Transaction tx = null;
Node node = null;
try {
tx = neoService.beginTx();
node = neoIndexService.getSingleNode(id, testValue);
tx.success();
} finally {
tx.finish();
}
return node != null;
}
public static enum NeoRelationshipTypes implements RelationshipType {
LINKS_TO
}
}
---
package org.neo4j.test;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.neo4j.api.core.NeoService;
import