@Test public void testHeuristicCommitBeforePrepare() throws JAXBException { txSupport.startTx(); final List<LoggingParticipant> participants = Arrays.asList( new LoggingParticipant[] { new LoggingParticipant(new Prepared()), new LoggingParticipant(new Prepared()) }); String lastParticipantid = null; for (LoggingParticipant p : participants) { lastParticipantid = ParticipantsManagerFactory.getInstance() .enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), p); } ParticipantsManagerFactory.getInstance() .reportHeuristic(lastParticipantid, HeuristicType.HEURISTIC_COMMIT); final String transactionStatus = TxSupport.getStatus(txSupport.commitTx()); Assert.assertEquals(TxStatus.TransactionCommitted.name(), transactionStatus); Assert.assertEquals( Arrays.asList(new String[] {"prepare", "commit"}), participants.get(0).getInvocations()); Assert.assertEquals(Collections.EMPTY_LIST, participants.get(1).getInvocations()); }
@Test public void testHeuristicRollbackBeforePrepare() throws JAXBException { txSupport.startTx(); final List<LoggingParticipant> participants = Arrays.asList( new LoggingParticipant[] { new LoggingParticipant(new Prepared()), new LoggingParticipant(new Prepared()) }); String lastParticipantid = null; for (LoggingParticipant p : participants) { lastParticipantid = ParticipantsManagerFactory.getInstance() .enlist(APPLICATION_ID, txSupport.getDurableParticipantEnlistmentURI(), p); } ParticipantsManagerFactory.getInstance() .reportHeuristic(lastParticipantid, HeuristicType.HEURISTIC_ROLLBACK); final String transactionStatus = TxSupport.getStatus(txSupport.commitTx()); Assert.assertEquals(TxStatus.TransactionRolledBack.name(), transactionStatus); if (participants.get(0).getInvocations().size() == 1) { Assert.assertEquals( Arrays.asList(new String[] {"rollback"}), participants.get(0).getInvocations()); } else { Assert.assertEquals( Arrays.asList(new String[] {"prepare", "rollback"}), participants.get(0).getInvocations()); } }