Search in sources :

Example 11 with Prepared

use of org.jboss.narayana.rest.integration.api.Prepared in project narayana by jbosstm.

the class BasicIntegrationTestCase method testRollback.

@Test
public void testRollback() {
    txSupport.startTx();
    LoggingParticipant participant1 = new LoggingParticipant(new Prepared());
    LoggingParticipant participant2 = new LoggingParticipant(new Prepared());
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), participant1);
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), participant2);
    txSupport.rollbackTx();
    Assert.assertEquals(Arrays.asList(new String[] { "rollback" }), participant1.getInvocations());
    Assert.assertEquals(Arrays.asList(new String[] { "rollback" }), participant2.getInvocations());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Prepared(org.jboss.narayana.rest.integration.api.Prepared) Test(org.junit.Test)

Example 12 with Prepared

use of org.jboss.narayana.rest.integration.api.Prepared in project narayana by jbosstm.

the class BasicIntegrationTestCase method testCommitWithVolatileParticipant.

@Test
public void testCommitWithVolatileParticipant() {
    txSupport.startTx();
    LoggingParticipant loggingParticipant = new LoggingParticipant(new Prepared());
    LoggingVolatileParticipant loggingVolatileParticipant = new LoggingVolatileParticipant();
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), loggingParticipant);
    ParticipantsManagerFactory.getInstance().enlistVolatileParticipant(txSupport.getVolatileParticipantEnlistmentURI(), loggingVolatileParticipant);
    final String txStatus = TxSupport.getStatus(txSupport.commitTx());
    Assert.assertEquals(TxStatus.TransactionCommitted.name(), txStatus);
    Assert.assertEquals(Arrays.asList(new String[] { "commitOnePhase" }), loggingParticipant.getInvocations());
    Assert.assertEquals(Arrays.asList(new String[] { "beforeCompletion", "afterCompletion" }), loggingVolatileParticipant.getInvocations());
    Assert.assertEquals(TxStatus.TransactionCommitted, loggingVolatileParticipant.getTxStatus());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Prepared(org.jboss.narayana.rest.integration.api.Prepared) LoggingVolatileParticipant(org.jboss.narayana.rest.integration.test.common.LoggingVolatileParticipant) Test(org.junit.Test)

Example 13 with Prepared

use of org.jboss.narayana.rest.integration.api.Prepared in project narayana by jbosstm.

the class BasicIntegrationTestCase method testCommit.

@Test
public void testCommit() {
    txSupport.startTx();
    LoggingParticipant participant1 = new LoggingParticipant(new Prepared());
    LoggingParticipant participant2 = new LoggingParticipant(new Prepared());
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), participant1);
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), participant2);
    txSupport.commitTx();
    Assert.assertEquals(Arrays.asList(new String[] { "prepare", "commit" }), participant1.getInvocations());
    Assert.assertEquals(Arrays.asList(new String[] { "prepare", "commit" }), participant2.getInvocations());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Prepared(org.jboss.narayana.rest.integration.api.Prepared) Test(org.junit.Test)

Example 14 with Prepared

use of org.jboss.narayana.rest.integration.api.Prepared in project narayana by jbosstm.

the class RecoveryIntegrationTestCase method testCrashBeforeCommit.

@Test
public void testCrashBeforeCommit() throws Exception {
    startContainer(VM_ARGUMENTS + " " + BYTEMAN_ARGUMENTS.replace("@BMScript@", "CrashBeforeCommit"));
    txSupport.startTx();
    enlistParticipant(txSupport.getDurableParticipantEnlistmentURI(), new Prepared());
    enlistParticipant(txSupport.getDurableParticipantEnlistmentURI(), new Prepared());
    Assert.assertEquals(2, txSupport.getTransactionInfo().getTwoPhaseAware().size());
    try {
        // JVM is killed here.
        txSupport.commitTx();
    } catch (HttpResponseException e) {
    }
    restartContainer(VM_ARGUMENTS);
    registerDeserializer();
    TransactionStatusElement status;
    int cycles = 0;
    do {
        Thread.sleep(RECOVERY_PERIOD * 2000);
        status = null;
        try {
            // Updates coordinator's active transactions list
            txSupport.getTransactions();
            // After successful recovery transaction is removed and 404 is returned.
            status = txSupport.getTransactionInfo().getStatus();
        } catch (HttpResponseException e) {
        }
    } while (status != null && cycles++ < RECOVERY_WAIT_CYCLES);
    if (status != null) {
        Assert.fail("Recovery failed unexpected status " + status);
    }
}
Also used : TransactionStatusElement(org.jboss.jbossts.star.util.media.txstatusext.TransactionStatusElement) Prepared(org.jboss.narayana.rest.integration.api.Prepared) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException) Test(org.junit.Test)

Example 15 with Prepared

use of org.jboss.narayana.rest.integration.api.Prepared in project narayana by jbosstm.

the class RecoveryManagerTestCase method testRecoveryWithoutDeserializer.

@Test
public void testRecoveryWithoutDeserializer() {
    final String participantId = new Uid().toString();
    final LoggingParticipant loggingParticipantBefore = new LoggingParticipant(new Prepared());
    loggingParticipantBefore.commit();
    final ParticipantInformation participantInformationBefore = new ParticipantInformation(participantId, APPLICATION_ID + "1", "", loggingParticipantBefore, TxStatus.TransactionCommitted.name());
    ParticipantsContainer.getInstance().clear();
    ParticipantsManagerFactory.getInstance().setBaseUrl("");
    RecoveryManager.getInstance().persistParticipantInformation(participantInformationBefore);
    RecoveryManager.getInstance().registerDeserializer(APPLICATION_ID + "2", new TestParticipantDeserializer());
    final ParticipantInformation participantInformationAfter = ParticipantsContainer.getInstance().getParticipantInformation(participantId);
    Assert.assertNull(participantInformationAfter);
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Uid(com.arjuna.ats.arjuna.common.Uid) Prepared(org.jboss.narayana.rest.integration.api.Prepared) ParticipantInformation(org.jboss.narayana.rest.integration.ParticipantInformation) TestParticipantDeserializer(org.jboss.narayana.rest.integration.test.common.TestParticipantDeserializer) Test(org.junit.Test)

Aggregations

Prepared (org.jboss.narayana.rest.integration.api.Prepared)36 Test (org.junit.Test)33 LoggingParticipant (org.jboss.narayana.rest.integration.test.common.LoggingParticipant)25 ParticipantInformation (org.jboss.narayana.rest.integration.ParticipantInformation)12 Response (javax.ws.rs.core.Response)10 LoggingParticipant (org.wildfly.test.extension.rts.common.LoggingParticipant)6 Aborted (org.jboss.narayana.rest.integration.api.Aborted)4 HeuristicParticipant (org.jboss.narayana.rest.integration.test.common.HeuristicParticipant)4 ReadOnly (org.jboss.narayana.rest.integration.api.ReadOnly)3 Vote (org.jboss.narayana.rest.integration.api.Vote)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 HttpResponseException (org.jboss.jbossts.star.provider.HttpResponseException)2 TransactionStatusElement (org.jboss.jbossts.star.util.media.txstatusext.TransactionStatusElement)2 LoggingVolatileParticipant (org.jboss.narayana.rest.integration.test.common.LoggingVolatileParticipant)2 JSONArray (org.codehaus.jettison.json.JSONArray)1 HeuristicException (org.jboss.narayana.rest.integration.api.HeuristicException)1 ParticipantException (org.jboss.narayana.rest.integration.api.ParticipantException)1 TestParticipantDeserializer (org.jboss.narayana.rest.integration.test.common.TestParticipantDeserializer)1