Search in sources :

Example 76 with Xid

use of javax.transaction.xa.Xid in project spanner-jdbc by olavloite.

the class XATester method prepareDeleteRow.

private Xid prepareDeleteRow(CloudSpannerXAConnection xaConnection) throws SQLException, XAException {
    Connection connection = xaConnection.getConnection();
    Xid xid = getRandomXid();
    xaConnection.start(xid, XAResource.TMNOFLAGS);
    String sql = "delete from test where id=1000000";
    PreparedStatement statement = connection.prepareStatement(sql);
    statement.executeUpdate();
    xaConnection.end(xid, XAResource.TMSUCCESS);
    xaConnection.prepare(xid);
    return xid;
}
Also used : RecoveredXid(nl.topicus.jdbc.xa.RecoveredXid) Xid(javax.transaction.xa.Xid) Connection(java.sql.Connection) CloudSpannerXAConnection(nl.topicus.jdbc.xa.CloudSpannerXAConnection) PreparedStatement(java.sql.PreparedStatement)

Example 77 with Xid

use of javax.transaction.xa.Xid in project spanner-jdbc by olavloite.

the class XATester method testXARecover.

private void testXARecover(CloudSpannerXAConnection xaConnection) throws SQLException, XAException {
    log.info("Started XA recover transaction test");
    testXATransaction(xaConnection, CommitMode.None);
    Xid[] xids = xaConnection.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(1, xids.length);
    xaConnection.commit(xids[0], false);
    boolean found = false;
    try (ResultSet rs = xaConnection.getConnection().createStatement().executeQuery("select * from test where id=1000000")) {
        if (rs.next())
            found = true;
    }
    Assert.assertTrue(found);
    log.info("Finished XA recover transaction test");
}
Also used : RecoveredXid(nl.topicus.jdbc.xa.RecoveredXid) Xid(javax.transaction.xa.Xid) ResultSet(java.sql.ResultSet)

Example 78 with Xid

use of javax.transaction.xa.Xid in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method testJoinWithDifferentXid.

@Test
public void testJoinWithDifferentXid() throws SQLException, XAException {
    thrown.expect(CloudSpannerXAException.class);
    thrown.expectMessage(CloudSpannerXAException.INTERLEAVING_NOT_IMPLEMENTED);
    CloudSpannerXAConnection subject = createSubject();
    Xid xid = getRandomXid();
    subject.start(xid, XAResource.TMNOFLAGS);
    subject.end(xid, XAResource.TMSUCCESS);
    subject.start(getRandomXid(), XAResource.TMJOIN);
}
Also used : Xid(javax.transaction.xa.Xid) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 79 with Xid

use of javax.transaction.xa.Xid in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method testJoinWhenNotEnded.

@Test
public void testJoinWhenNotEnded() throws SQLException, XAException {
    thrown.expect(CloudSpannerXAException.class);
    thrown.expectMessage(CloudSpannerXAException.INTERLEAVING_NOT_IMPLEMENTED);
    CloudSpannerXAConnection subject = createSubject();
    Xid xid = getRandomXid();
    subject.start(xid, XAResource.TMJOIN);
}
Also used : Xid(javax.transaction.xa.Xid) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 80 with Xid

use of javax.transaction.xa.Xid in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method testPrepareWithoutEnd.

@Test
public void testPrepareWithoutEnd() throws SQLException, XAException {
    thrown.expect(CloudSpannerXAException.class);
    thrown.expectMessage(CloudSpannerXAException.PREPARE_BEFORE_END);
    CloudSpannerXAConnection subject = createSubject();
    Xid xid = getRandomXid();
    subject.start(xid, XAResource.TMNOFLAGS);
    subject.prepare(xid);
}
Also used : Xid(javax.transaction.xa.Xid) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Aggregations

Xid (javax.transaction.xa.Xid)82 Test (org.junit.Test)35 XAException (javax.transaction.xa.XAException)20 IOException (java.io.IOException)16 XAResource (javax.transaction.xa.XAResource)14 UnitTest (nl.topicus.jdbc.test.category.UnitTest)11 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)11 LinkedList (java.util.LinkedList)10 InOrder (org.mockito.InOrder)6 HashMap (java.util.HashMap)5 RecoveredXid (nl.topicus.jdbc.xa.RecoveredXid)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)4 ArrayList (java.util.ArrayList)4 RollbackException (javax.transaction.RollbackException)4 SystemException (javax.transaction.SystemException)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 TransactionContext (com.hazelcast.transaction.TransactionContext)3 SerializableXID (com.hazelcast.transaction.impl.xa.SerializableXID)3