Search in sources :

Example 1 with ReadOnly

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

the class ParticipantResourceTestCase method testGetTerminator.

@Test
@SuppressWarnings("rawtypes")
public void testGetTerminator() throws Exception {
    registerParticipant(participantId, new LoggingParticipant(new ReadOnly()));
    Response response = getParticipantTerminator(participantId);
    Assert.assertEquals(200, response.getStatus());
    Link link = response.getLink(TxLinkNames.TERMINATOR);
    Assert.assertNotNull(link);
    Assert.assertEquals(PARTICIPANT_URL + "/" + participantId, link.getUri().toString());
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Response(javax.ws.rs.core.Response) Link(javax.ws.rs.core.Link) Test(org.junit.Test)

Example 2 with ReadOnly

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

the class ParticipantResourceTestCase method testPrepareOutcomeReadOnly.

@Test
public void testPrepareOutcomeReadOnly() throws Exception {
    final LoggingParticipant participant = new LoggingParticipant(new ReadOnly());
    registerParticipant(participantId, participant);
    ParticipantInformation participantInformation = ParticipantsContainer.getInstance().getParticipantInformation(participantId);
    Response stringResponse = prepareParticipant(participantId);
    Assert.assertEquals(200, stringResponse.getStatus());
    Assert.assertEquals(TxStatus.TransactionReadOnly.name(), TxSupport.getStatus(stringResponse.readEntity(String.class)));
    Assert.assertEquals(TxStatus.TransactionReadOnly.name(), participantInformation.getStatus());
    Assert.assertEquals(Arrays.asList(new String[] { "prepare" }), participant.getInvocations());
    Assert.assertNull(ParticipantsContainer.getInstance().getParticipantInformation(participantId));
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Response(javax.ws.rs.core.Response) ParticipantInformation(org.jboss.narayana.rest.integration.ParticipantInformation) Test(org.junit.Test)

Example 3 with ReadOnly

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

the class ParticipantResourceTestCase method testGetStatus.

@Test
public void testGetStatus() throws Exception {
    registerParticipant(participantId, new LoggingParticipant(new ReadOnly()));
    ParticipantInformation participantInformation = ParticipantsContainer.getInstance().getParticipantInformation(participantId);
    participantInformation.setStatus(TxStatus.TransactionPrepared.name());
    Response response = getParticipantStatus(participantId);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(TxStatus.isPrepare(TxSupport.getStatus(response.readEntity(String.class))));
    participantInformation.setStatus(TxStatus.TransactionCommitted.name());
    response = ClientBuilder.newClient().target(PARTICIPANT_URL + "/" + participantId).request().get();
    Assert.assertTrue(TxStatus.isCommit(TxSupport.getStatus(response.readEntity(String.class))));
}
Also used : LoggingParticipant(org.jboss.narayana.rest.integration.test.common.LoggingParticipant) ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Response(javax.ws.rs.core.Response) ParticipantInformation(org.jboss.narayana.rest.integration.ParticipantInformation) Test(org.junit.Test)

Example 4 with ReadOnly

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

the class ParticipantTestCase method testReadOnly.

@Test
public void testReadOnly() {
    txSupport.startTx();
    final List<LoggingParticipant> participants = Arrays.asList(new LoggingParticipant[] { new LoggingParticipant(new ReadOnly()), new LoggingParticipant(new Prepared()), new LoggingParticipant(new Prepared()) });
    for (LoggingParticipant p : participants) {
        ParticipantsManagerFactory.getInstance().enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), p);
    }
    txSupport.commitTx();
    // One of the participants was only prepared, while other two were prepared and committed.
    Assert.assertEquals(5, participants.get(0).getInvocations().size() + participants.get(1).getInvocations().size() + participants.get(2).getInvocations().size());
    for (LoggingParticipant p : participants) {
        if (p.getInvocations().size() == 1) {
            Assert.assertEquals(Arrays.asList(new String[] { "prepare" }), p.getInvocations());
        } else {
            Assert.assertEquals(Arrays.asList(new String[] { "prepare", "commit" }), p.getInvocations());
        }
    }
}
Also used : LoggingParticipant(org.wildfly.test.extension.rts.common.LoggingParticipant) ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Prepared(org.jboss.narayana.rest.integration.api.Prepared) Test(org.junit.Test)

Example 5 with ReadOnly

use of org.jboss.narayana.rest.integration.api.ReadOnly 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)

Aggregations

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