Search in sources :

Example 6 with TxSupport

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

the class CoordinatorTest method testListTransactions.

/*
      * Note: TxSupport methods throw exceptions if unexpected status codes are returned.
      * use the TxSupport.httpRequest(...) if you want to specify other status codes
      */
// list transactions
@Test
public void testListTransactions() throws IOException {
    TxSupport[] txns = { new TxSupport(), new TxSupport() };
    int txnCount = new TxSupport().txCount();
    for (TxSupport txn : txns) txn.startTx();
    // there should be txns.length more transactions
    Assert.assertEquals(txnCount + txns.length, txns[0].txCount());
    for (TxSupport txn : txns) txn.commitTx();
    // the number of transactions should be back to the original number
    Assert.assertEquals(txnCount, txns[0].txCount());
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Test(org.junit.Test)

Example 7 with TxSupport

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

the class LoggingRestATResource method headParticipant.

/**
 * Returns links to the participant terminator.
 *
 * @return Link to the participant terminator.
 */
@HEAD
public Response headParticipant(@Context UriInfo uriInfo) {
    LOG.info("LoggingRestATResource.headParticipant()");
    invocations.add("LoggingRestATResource.headParticipant()");
    String serviceURL = uriInfo.getBaseUri() + uriInfo.getPath();
    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 8 with TxSupport

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

the class CoordinatorTestCase method testTimeoutCleanup.

@Test
public void testTimeoutCleanup() throws InterruptedException {
    TxSupport txn = new TxSupport();
    int txnCount = txn.txCount();
    txn.startTx(1000);
    txn.enlistTestResource(getDeploymentUrl() + WorkRestATResource.PATH_SEGMENT, 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 9 with TxSupport

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

the class AbstractTestCase method before.

@Before
public void before() {
    TxSupport.setTxnMgrUrl(getBaseUrl() + "/rest-at-coordinator/tx/transaction-manager");
    txSupport = new TxSupport();
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) Before(org.junit.Before)

Example 10 with TxSupport

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

the class Transaction method beforeCompletion.

@Override
protected boolean beforeCompletion() {
    boolean commit = true;
    for (String uri : volatileParticipants) {
        try {
            new TxSupport().httpRequest(new int[] { HttpURLConnection.HTTP_OK }, uri, "PUT", null);
        } catch (HttpResponseException e) {
            commit = false;
            if (log.isDebugEnabled())
                log.debugf(e, "volatile participant %s error %s during beforeCompletion", uri, e.getMessage());
        }
    }
    if (!super.beforeCompletion())
        commit = false;
    // Get a list of the participants before they check-out of the transaction
    enlistmentIds = new ArrayList<String>();
    getParticipants(enlistmentIds);
    return commit;
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException)

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