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());
}
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));
}
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))));
}
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());
}
}
}
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;
}
Aggregations