use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.
the class CoordinatorTest method test1PCCommitUnawareWithoutOnePhase.
@Test
public void test1PCCommitUnawareWithoutOnePhase() throws Exception {
TxSupport txn = new TxSupport();
String pUrl = PURL;
String pid = null;
String pVal;
pid = modifyResource(txn, pUrl, pid, "p1", "v1");
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals("intial value for key " + pid + " was set now checking it", pVal, "v1");
txn.startTx();
pid = enlistResource(txn, pUrl + "?pId=" + pid + "&twoPhaseAware=false&isUnawareTwoPhaseParticipantOnePhase=false");
modifyResource(txn, pUrl, pid, "p1", "v2");
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals("transaction in run for key " + pid + " we should see already a new value", pVal, "v2");
txn.commitTx();
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals("transaction wrote for key " + pid + " but read value is different", pVal, "v2");
String commitCount = getResourceProperty(txn, pUrl, pid, "commitCnt");
Assert.assertEquals("one phase executed without 1pc support thus two-phase commit count expected being 1", "1", commitCount);
String onePhaseCommitCount = getResourceProperty(txn, pUrl, pid, "commitOnePhaseCnt");
Assert.assertEquals("one phase executed without 1pc support thus one-phase commit count expected being 0", "0", onePhaseCommitCount);
}
use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.
the class CoordinatorTest method testFailureInSecondParticipantDuringCommit.
@Test
public void testFailureInSecondParticipantDuringCommit() {
final TxSupport txn = new TxSupport();
final int originalTxCount = txn.txCount();
final String pUrl = PURL;
final String[] pid = new String[2];
pid[0] = modifyResource(txn, pUrl, null, "p1", "v1");
pid[1] = modifyResource(txn, pUrl, null, "p1", "v1");
txn.startTx();
enlistResource(txn, pUrl + "?pId=" + pid[0]);
enlistResource(txn, pUrl + "?pId=" + pid[1] + "&fault=CRUNTIME");
modifyResource(txn, pUrl, pid[0], "p1", "v2");
modifyResource(txn, pUrl, pid[1], "p1", "v2");
Assert.assertEquals("v2", getResourceProperty(txn, pUrl, pid[0], "p1"));
Assert.assertEquals("v2", getResourceProperty(txn, pUrl, pid[1], "p1"));
txn.commitTx();
Assert.assertEquals("v2", getResourceProperty(txn, pUrl, pid[0], "p1"));
Assert.assertEquals("v1", getResourceProperty(txn, pUrl, pid[1], "p1"));
// Transaction should not be removed because of the failure
Assert.assertEquals(originalTxCount + 1, txn.txCount());
}
use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.
the class CoordinatorTest method testCommitInvalidTx.
// commit an invalid transaction
@Test
public void testCommitInvalidTx() throws IOException {
// start a transaction
TxSupport txn = new TxSupport().startTx();
String terminator = txn.getTerminatorURI();
// mangle the terminator URI
// terminator = terminator.replace("/terminate", "_dead/terminate");
terminator += "/_dead";
// an attempt to commit on this URI should fail:
txn.httpRequest(new int[] { HttpURLConnection.HTTP_NOT_FOUND }, terminator, "PUT", TxMediaType.TX_STATUS_MEDIA_TYPE, TxStatusMediaType.TX_COMMITTED);
// commit it properly
txn.commitTx();
}
use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.
the class CoordinatorTest method test1PCCommit.
// 1PC commit
@Test
public void test1PCCommit() throws Exception {
TxSupport txn = new TxSupport();
String pUrl = PURL;
String pid = null;
String pVal;
pid = modifyResource(txn, pUrl, pid, "p1", "v1");
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals(pVal, "v1");
txn.startTx();
pid = enlistResource(txn, pUrl + "?pId=" + pid);
modifyResource(txn, pUrl, pid, "p1", "v2");
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals(pVal, "v2");
txn.commitTx();
pVal = getResourceProperty(txn, pUrl, pid, "p1");
Assert.assertEquals(pVal, "v2");
}
use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.
the class CoordinatorTest method test2PCCommitWithoutResponse.
@Test
public void test2PCCommitWithoutResponse() throws Exception {
TxSupport txn = new TxSupport();
String pUrl = PURL;
String[] pid = new String[2];
String[] pVal = new String[2];
for (int i = 0; i < pid.length; i++) {
pid[i] = modifyResource(txn, pUrl, null, "p1", "v1");
pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
Assert.assertEquals(pVal[i], "v1");
}
txn.startTx();
for (int i = 0; i < pid.length; i++) {
enlistResource(txn, PURL_NO_RESPONSE + "?pId=" + pid[i]);
modifyResource(txn, pUrl, pid[i], "p1", "v2");
pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
Assert.assertEquals(pVal[i], "v2");
}
String status = txn.commitTx();
for (int i = 0; i < pid.length; i++) {
pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
Assert.assertEquals(pVal[i], "v2");
}
}
Aggregations