Search in sources :

Example 16 with TxSupport

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

the class CoordinatorTest method testTimeoutCleanup.

@Test
public void testTimeoutCleanup() throws InterruptedException {
    TxSupport txn = new TxSupport();
    int txnCount = txn.txCount();
    txn.startTx(1000);
    txn.enlistTestResource(PURL, false);
    // Let the txn timeout
    Thread.sleep(2000);
    Assert.assertEquals(txnCount, txn.txCount());
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Example 17 with TxSupport

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

the class CoordinatorTest method test2PC.

// 2PC commit
@Test
public void test2PC() 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 + "?pId=" + pid[i]);
        modifyResource(txn, pUrl, pid[i], "p1", "v2");
        pVal[i] = getResourceProperty(txn, pUrl, pid[i], "p1");
        Assert.assertEquals(pVal[i], "v2");
    }
    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 18 with TxSupport

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

the class TxSupportTest method testListTransactionsWhenNoActiveTxns.

@Test
public void testListTransactionsWhenNoActiveTxns() throws IOException {
    TxSupport txn = new TxSupport(TXN_MGR_URL, 60000);
    Collection<String> transactionsInProgress = txn.getTransactions();
    // There should be no txns in progress, since none were started in this test
    Assert.assertEquals(0, txn.txCount());
    Assert.assertEquals(0, transactionsInProgress.size());
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Example 19 with TxSupport

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

the class LoggingRestATResource method headParticipant.

/**
 * Returns links to the participant terminator.
 *
 * @return Link to the participant terminator.
 */
@HEAD
public Response headParticipant(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("LoggingRestATResource.headParticipant()");
    }
    invocations.add("LoggingRestATResource.headParticipant()");
    final String serviceURL = uriInfo.getBaseUri() + uriInfo.getPath();
    final String linkHeader = new TxSupport().makeTwoPhaseAwareParticipantLinkHeader(serviceURL, false, null, null);
    return Response.ok().header("Link", linkHeader).build();
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) HEAD(javax.ws.rs.HEAD)

Example 20 with TxSupport

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

the class WorkRestATResource method getBasic.

@GET
public String getBasic(@Context UriInfo info, @QueryParam("pId") @DefaultValue("") String pId, @QueryParam("context") @DefaultValue("") String ctx, @QueryParam("name") @DefaultValue("") String name, @QueryParam("value") @DefaultValue("") String value, @QueryParam("query") @DefaultValue("pUrl") String query, @QueryParam("arg") @DefaultValue("") String arg, @QueryParam("twoPhaseAware") @DefaultValue("true") String twoPhaseAware, @QueryParam("isVolatile") @DefaultValue("false") String isVolatileParticipant, @QueryParam("register") @DefaultValue("true") String register) {
    Work work = faults.get(pId);
    String res = null;
    boolean isVolatile = "true".equals(isVolatileParticipant);
    boolean isTwoPhaseAware = "true".equals(twoPhaseAware);
    if (name.length() != 0) {
        if (value.length() != 0) {
            if (work == null) {
                work = makeWork(new TxSupport(), info.getAbsolutePath().toString(), String.valueOf(++pid), null, null, isTwoPhaseAware, isVolatile, null, null);
                work.oldState.put(name, value);
                faults.put(work.id, work);
                return work.id;
            }
            work.newState.put(name, value);
        }
        if (work != null) {
            if ("syncCount".equals(name))
                res = String.valueOf(work.syncCount);
            else if ("commitCnt".equals(name))
                res = String.valueOf(work.commitCnt);
            else if ("prepareCnt".equals(name))
                res = String.valueOf(work.prepareCnt);
            else if ("rollbackCnt".equals(name))
                res = String.valueOf(work.rollbackCnt);
            else if ("commmitOnePhaseCnt".equals(name))
                res = String.valueOf(work.commmitOnePhaseCnt);
            else if (work.inTxn())
                res = work.newState.get(name);
            else
                res = work.oldState.get(name);
        }
    }
    if (work == null)
        throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND);
    if ("move".equals(query)) {
    /* Ignore*/
    } else if ("recoveryUrl".equals(query))
        res = work.recoveryUrl;
    else if ("status".equals(query))
        res = work.status;
    else if (res == null)
        res = work.pLinks;
    // null will generate a 204 status code (no content)
    return res;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) TxSupport(org.jboss.jbossts.star.util.TxSupport) GET(javax.ws.rs.GET)

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