Search in sources :

Example 1 with Aborted

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

the class BasicIntegrationTestCase method testHeuristicRollbackAfterUnsuccessfullPrepare.

@Test
public void testHeuristicRollbackAfterUnsuccessfullPrepare() {
    txSupport.startTx();
    LoggingParticipant loggingParticipant = new LoggingParticipant(new Aborted());
    HeuristicParticipant heuristicParticipant = new HeuristicParticipant(HeuristicType.HEURISTIC_ROLLBACK, new Prepared());
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), loggingParticipant);
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), heuristicParticipant);
    final String txStatus = TxSupport.getStatus(txSupport.commitTx());
    Assert.assertEquals(TxStatus.TransactionRolledBack.name(), txStatus);
    Assert.assertEquals(Arrays.asList(new String[] { "prepare", "rollback" }), loggingParticipant.getInvocations());
    Assert.assertEquals(Arrays.asList(new String[] { "prepare", "rollback" }), heuristicParticipant.getInvocations());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) HeuristicParticipant(org.jboss.narayana.rest.integration.test.common.HeuristicParticipant) Prepared(org.jboss.narayana.rest.integration.api.Prepared) Aborted(org.jboss.narayana.rest.integration.api.Aborted) Test(org.junit.Test)

Example 2 with Aborted

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

the class BasicIntegrationTestCase method testRollbackByParticipant.

@Test
public void testRollbackByParticipant() {
    txSupport.startTx();
    final List<LoggingParticipant> participants = Arrays.asList(new LoggingParticipant[] { new LoggingParticipant(new Aborted()), new LoggingParticipant(new Aborted()) });
    for (LoggingParticipant p : participants) {
        ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), p);
    }
    txSupport.commitTx();
    // One of the participants was prepared and then decided to rollback, the other was rolledback straight away.
    Assert.assertEquals(3, participants.get(0).getInvocations().size() + participants.get(1).getInvocations().size());
    for (LoggingParticipant p : participants) {
        if (p.getInvocations().size() == 1) {
            Assert.assertEquals(Arrays.asList(new String[] { "rollback" }), p.getInvocations());
        } else {
            Assert.assertEquals(Arrays.asList(new String[] { "prepare", "rollback" }), p.getInvocations());
        }
    }
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Aborted(org.jboss.narayana.rest.integration.api.Aborted) Test(org.junit.Test)

Example 3 with Aborted

use of org.jboss.narayana.rest.integration.api.Aborted in project wildfly by wildfly.

the class ParticipantTestCase method testRollbackByParticipant.

@Test
public void testRollbackByParticipant() {
    txSupport.startTx();
    final List<LoggingParticipant> participants = Arrays.asList(new LoggingParticipant[] { new LoggingParticipant(new Aborted()), new LoggingParticipant(new Aborted()) });
    for (LoggingParticipant p : participants) {
        ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), p);
    }
    txSupport.commitTx();
    // One of the participants was prepared and then decided to rollback, the other was rolledback straight away.
    Assert.assertEquals(3, participants.get(0).getInvocations().size() + participants.get(1).getInvocations().size());
    for (LoggingParticipant p : participants) {
        if (p.getInvocations().size() == 1) {
            Assert.assertEquals(Arrays.asList(new String[] { "rollback" }), p.getInvocations());
        } else {
            Assert.assertEquals(Arrays.asList(new String[] { "prepare", "rollback" }), p.getInvocations());
        }
    }
}
Also used : LoggingParticipant(org.wildfly.test.extension.rts.common.LoggingParticipant) Aborted(org.jboss.narayana.rest.integration.api.Aborted) Test(org.junit.Test)

Example 4 with Aborted

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

the class ParticipantResource method prepare.

private Vote prepare(final ParticipantInformation participantInformation) throws HeuristicException {
    if (isHeuristic(participantInformation)) {
        return prepareHeuristic(participantInformation);
    }
    participantInformation.setStatus(TxStatus.TransactionPreparing.name());
    final Vote vote;
    try {
        vote = participantInformation.getParticipant().prepare();
    } catch (ParticipantException e) {
        participantInformation.setStatus(TxStatus.TransactionActive.name());
        throw e;
    }
    if (vote instanceof Aborted) {
        rollback(participantInformation);
    } else if (vote instanceof Prepared) {
        participantInformation.setStatus(TxStatus.TransactionPrepared.name());
        RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
    } else if (vote instanceof ReadOnly) {
        readOnly(participantInformation);
    }
    return vote;
}
Also used : ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Vote(org.jboss.narayana.rest.integration.api.Vote) Prepared(org.jboss.narayana.rest.integration.api.Prepared) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException) Aborted(org.jboss.narayana.rest.integration.api.Aborted)

Example 5 with Aborted

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

the class BasicIntegrationTestCase method testSecondParticipantHeuristicCommitWithFirstParticipantUnsuccessfullPrepare.

@Test
public void testSecondParticipantHeuristicCommitWithFirstParticipantUnsuccessfullPrepare() throws JAXBException {
    txSupport.startTx();
    LoggingParticipant loggingParticipant1 = new LoggingParticipant(new Aborted());
    LoggingParticipant loggingParticipant2 = new LoggingParticipant(new Prepared());
    ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), loggingParticipant1);
    String lastParticipantid = ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), loggingParticipant2);
    ParticipantsManagerFactory.getInstance().reportHeuristic(lastParticipantid, HeuristicType.HEURISTIC_COMMIT);
    System.out.println(ParticipantsContainer.getInstance().getParticipantInformation(lastParticipantid).getStatus());
    final String txStatus = TxSupport.getStatus(txSupport.commitTx());
    Assert.assertEquals(TxStatus.TransactionHeuristicCommit.name(), txStatus);
    Assert.assertEquals(Arrays.asList(new String[] { "prepare", "rollback" }), loggingParticipant1.getInvocations());
    Assert.assertEquals(Collections.EMPTY_LIST, loggingParticipant2.getInvocations());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) Prepared(org.jboss.narayana.rest.integration.api.Prepared) Aborted(org.jboss.narayana.rest.integration.api.Aborted) Test(org.junit.Test)

Aggregations

Aborted (org.jboss.narayana.rest.integration.api.Aborted)7 Test (org.junit.Test)6 LoggingParticipant (org.jboss.narayana.rest.integration.test.common.LoggingParticipant)5 Prepared (org.jboss.narayana.rest.integration.api.Prepared)4 HeuristicParticipant (org.jboss.narayana.rest.integration.test.common.HeuristicParticipant)2 Response (javax.ws.rs.core.Response)1 ParticipantInformation (org.jboss.narayana.rest.integration.ParticipantInformation)1 ParticipantException (org.jboss.narayana.rest.integration.api.ParticipantException)1 ReadOnly (org.jboss.narayana.rest.integration.api.ReadOnly)1 Vote (org.jboss.narayana.rest.integration.api.Vote)1 LoggingParticipant (org.wildfly.test.extension.rts.common.LoggingParticipant)1