Search in sources :

Example 21 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testBrokenNodeCommand.

@Test
public void testBrokenNodeCommand() throws Exception {
    Xid xid = new XidImpl(new byte[4], new byte[4]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    xaCon.clearAllTransactions();
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    truncateLogicalLog(40);
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) Test(org.junit.Test)

Example 22 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testBrokenPrepare.

@Test
public void testBrokenPrepare() throws Exception {
    Xid xid = new XidImpl(new byte[4], new byte[4]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string value 1");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    // master (w/ shortstring) says 155
    truncateLogicalLog(188);
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) Test(org.junit.Test)

Example 23 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testBrokenCommand.

@Test
public void testBrokenCommand() throws Exception {
    Xid xid = new XidImpl(new byte[4], new byte[4]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    xaCon.clearAllTransactions();
    copyLogicalLog(path());
    xaCon.clearAllTransactions();
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    truncateLogicalLog(37);
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //            lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(0, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) Test(org.junit.Test)

Example 24 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testLogicalLogRotation.

@Test
public void testLogicalLogRotation() throws Exception {
    ds.keepLogicalLogs(true);
    Xid xid = new XidImpl(new byte[1], new byte[1]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().getProperties(node1, false);
    int relType1 = (int) ds.nextId(RelationshipType.class);
    xaCon.getRelationshipTypeConsumer().addRelationshipType(relType1, "relationshiptype1");
    long rel1 = ds.nextId(Relationship.class);
    xaCon.getRelationshipConsumer().createRelationship(rel1, node1, node2, relType1);
    long r1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getRelationshipConsumer().addProperty(rel1, r1prop1, index("prop1"), "string1");
    xaCon.getNodeConsumer().changeProperty(node1, n1prop1, "string2");
    xaCon.getRelationshipConsumer().changeProperty(rel1, r1prop1, "string2");
    xaCon.getNodeConsumer().removeProperty(node1, n1prop1);
    xaCon.getRelationshipConsumer().removeProperty(rel1, r1prop1);
    xaCon.getRelationshipConsumer().deleteRelationship(rel1);
    xaCon.getNodeConsumer().deleteNode(node1);
    xaCon.getNodeConsumer().deleteNode(node2);
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.commit(xid, true);
    long currentVersion = ds.getCurrentLogVersion();
    ds.rotateLogicalLog();
    assertTrue(logicalLogExists(currentVersion));
    ds.rotateLogicalLog();
    assertTrue(logicalLogExists(currentVersion));
    assertTrue(logicalLogExists(currentVersion + 1));
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 25 with XAResource

use of javax.transaction.xa.XAResource in project graphdb by neo4j-attic.

the class TestXa method testBrokenDone.

@Test
public void testBrokenDone() throws Exception {
    Xid xid = new XidImpl(new byte[4], new byte[4]);
    XAResource xaRes = xaCon.getXaResource();
    xaRes.start(xid, XAResource.TMNOFLAGS);
    long node1 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node1);
    long node2 = ds.nextId(Node.class);
    xaCon.getNodeConsumer().createNode(node2);
    long n1prop1 = ds.nextId(PropertyStore.class);
    xaCon.getNodeConsumer().addProperty(node1, n1prop1, index("prop1"), "string value 1");
    xaRes.end(xid, XAResource.TMSUCCESS);
    xaRes.prepare(xid);
    xaRes.commit(xid, false);
    copyLogicalLog(path());
    ds.close();
    deleteLogicalLogIfExist();
    renameCopiedLogicalLog(path());
    // master (w/ shortstring) says 171
    truncateLogicalLog(224);
    ds = newNeoStore();
    //        ds = new NeoStoreXaDataSource( file( "neo" ), file( "nioneo_logical.log" ),
    //             lockManager, lockReleaser );
    xaCon = (NeoStoreXaConnection) ds.getXaConnection();
    xaRes = xaCon.getXaResource();
    assertEquals(1, xaRes.recover(XAResource.TMNOFLAGS).length);
    xaCon.clearAllTransactions();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XidImpl(org.neo4j.kernel.impl.transaction.XidImpl) Test(org.junit.Test)

Aggregations

XAResource (javax.transaction.xa.XAResource)37 Xid (javax.transaction.xa.Xid)13 Test (org.junit.Test)13 SystemException (javax.transaction.SystemException)10 Transaction (javax.transaction.Transaction)10 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)9 XAException (javax.transaction.xa.XAException)8 RollbackException (javax.transaction.RollbackException)7 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 HashMap (java.util.HashMap)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 ResourceException (javax.resource.ResourceException)4 ManagedConnection (javax.resource.spi.ManagedConnection)4 XAConnection (javax.sql.XAConnection)4 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)3 Iterator (java.util.Iterator)3