Search in sources :

Example 11 with TxSupport

use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.

the class ParticipantsManagerImpl method enlistParticipant.

private String enlistParticipant(final String participantUrl, final String participantEnlistmentURL) {
    TxSupport txSupport = new TxSupport();
    String participantLinkHeader = txSupport.makeTwoPhaseAwareParticipantLinkHeader(participantUrl, participantUrl);
    final String recoveryUrl;
    try {
        recoveryUrl = txSupport.enlistParticipant(participantEnlistmentURL, participantLinkHeader);
    } catch (HttpResponseException e) {
        throw new ParticipantException("Failed to enlist participant", e);
    }
    return recoveryUrl;
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Example 12 with TxSupport

use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.

the class ParticipantsManagerImpl method enlistVolatileParticipant.

private void enlistVolatileParticipant(final String participantUrl, final String volatileParticipantEnlistmentURL) {
    final StringBuilder linkHeader = new StringBuilder();
    linkHeader.append("<").append(participantUrl).append(">; rel=\"").append(TxLinkNames.VOLATILE_PARTICIPANT).append("\"");
    final String participantLinkHeader = linkHeader.toString();
    try {
        new TxSupport().enlistVolatileParticipant(volatileParticipantEnlistmentURL, participantLinkHeader);
    } catch (HttpResponseException e) {
        throw new ParticipantException("Failed to enlist volatile participant", e);
    }
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Example 13 with TxSupport

use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.

the class CoordinatorTest method test2PCRollbackWithoutResponse.

@Test
public void test2PCRollbackWithoutResponse() 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.rollbackTx();
    for (int i = 0; i < pid.length; i++) {
        pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
        Assert.assertEquals(pVal[i], "v1");
    }
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Example 14 with TxSupport

use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.

the class CoordinatorTest method test1PCCommitUnaware.

@Test
public void test1PCCommitUnaware() 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");
    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 thus two-phase commit count expected being 0", "0", commitCount);
    String onePhaseCommitCount = getResourceProperty(txn, pUrl, pid, "commitOnePhaseCnt");
    Assert.assertEquals("one phase executed thus one-phase commit count expected being 1", "1", onePhaseCommitCount);
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Example 15 with TxSupport

use of org.jboss.jbossts.star.util.TxSupport in project narayana by jbosstm.

the class CoordinatorTest method test1PCAbort.

// 1PC commit abort
@Test
public void test1PCAbort() 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.rollbackTx();
    pVal = getResourceProperty(txn, pUrl, pid, "p1");
    Assert.assertEquals(pVal, "v1");
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Aggregations

TxSupport (org.jboss.jbossts.star.util.TxSupport)26 Test (org.junit.Test)18 HttpResponseException (org.jboss.jbossts.star.provider.HttpResponseException)4 HEAD (javax.ws.rs.HEAD)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ParticipantException (org.jboss.narayana.rest.integration.api.ParticipantException)2 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1