/** * Always fire immediately. * * @param withdrawal * @throws Exception */ public void withdrawNoTx(@Observes(during = TransactionPhase.IN_PROGRESS) Withdrawal withdrawal) throws Exception { logEventFired(TransactionPhase.IN_PROGRESS); }
/** * * @param amount * @throws Exception */ public void withdrawNoTransaction(int amount) throws Exception { event.fire(new Withdrawal(amount)); ActionSequence.addAction("checkpoint"); }
/** * * @param amount * @throws Exception */ public void withdrawObserverFailedTransaction(int amount) throws Exception { userTransaction.begin(); event.fire(new Withdrawal(amount)); eventFailure.fire(new Failure()); ActionSequence.addAction("checkpoint"); if (userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) { userTransaction.rollback(); } else { userTransaction.commit(); } }
/** * No transaction - send all events immediately. * * @throws Exception */ @Test @SpecAssertions({ @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "a"), @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "b") }) public void testNoTransaction() throws Exception { logger.log("testNoTransaction"); ActionSequence.reset(); // Checkpoint is after event send accountService.withdrawNoTransaction(3); // No TX is active - all events are fired immediately and thus before checkpoint List<String> sequence = ActionSequence.getSequenceData(); assertEquals(sequence.size(), 6); assertEquals(sequence.get(sequence.size() - 1), "checkpoint"); }
@Test @SpecAssertions({ @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "bda") }) public void testObserverFailedTransaction() throws Exception { logger.log("testObserverFailedTransaction"); ActionSequence.reset(); accountService.withdrawObserverFailedTransaction(2); // IN_PROGRESS is fired twice // AFTER_FAILURE and AFTER_COMPLETION must be fired after checkpoint // AFTER_SUCCESS and BEFORE_COMPLETION is not fired List<String> phases = ActionSequence.getSequenceData(); assertEquals(phases.size(), 5); assertEquals(phases.get(0), TransactionPhase.IN_PROGRESS.name()); assertEquals(phases.get(1), TransactionPhase.IN_PROGRESS.name()); assertEquals(phases.get(2), "checkpoint"); assertTrue(phases.contains(TransactionPhase.AFTER_FAILURE.name())); assertTrue(phases.contains(TransactionPhase.AFTER_COMPLETION.name())); }
@Test @SpecAssertions({ @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "a"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "b"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "c"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "d"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "e"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "gaa"), @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "b") }) public void testFailedTransaction() throws Exception { logger.log("testFailedTransaction"); ActionSequence.reset(); // Checkpoint is right before tx rollback accountService.withdrawFailedTransaction(2); // AFTER_FAILURE and AFTER_COMPLETION must be fired after checkpoint // AFTER_SUCCESS and BEFORE_COMPLETION is not fired List<String> phases = ActionSequence.getSequenceData(); assertEquals(phases.size(), 4); assertEquals(phases.get(0), TransactionPhase.IN_PROGRESS.name()); assertEquals(phases.get(1), "checkpoint"); assertTrue(phases.contains(TransactionPhase.AFTER_FAILURE.name())); assertTrue(phases.contains(TransactionPhase.AFTER_COMPLETION.name())); }
@Test @SpecAssertions({ @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "a"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "b"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "c"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "d"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "e"), @SpecAssertion(section = TRANSACTIONAL_OBSERVER_METHODS, id = "gaa"), @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "b") }) public void testSucessfullTransaction() throws Exception { logger.log("testSucessfullTransaction"); ActionSequence.reset(); // Checkpoint is right before tx commit accountService.withdrawSuccesTransaction(1); // Test sequence // BEFORE_COMPLETION must be fired at the beginning of the commit (after checkpoint) // AFTER_SUCCESS and AFTER_COMPLETION must be fired after BEFORE_COMPLETION // AFTER_FAILURE is not fired List<String> phases = ActionSequence.getSequenceData(); assertEquals(phases.size(), 5); assertEquals(phases.get(0), TransactionPhase.IN_PROGRESS.name()); assertEquals(phases.get(1), "checkpoint"); assertEquals(phases.get(2), TransactionPhase.BEFORE_COMPLETION.name()); assertTrue(phases.contains(TransactionPhase.AFTER_SUCCESS.name())); assertTrue(phases.contains(TransactionPhase.AFTER_COMPLETION.name())); }
/** * * @param amount * @throws Exception */ public void withdrawSuccesTransaction(int amount) throws Exception { userTransaction.begin(); event.fire(new Withdrawal(amount)); ActionSequence.addAction("checkpoint"); userTransaction.commit(); }
/** * * @param withdrawal * @throws Exception */ public void withdrawAfterFailure(@Observes(during = TransactionPhase.AFTER_FAILURE) Withdrawal withdrawal) throws Exception { logEventFired(TransactionPhase.AFTER_FAILURE); }
/** * * @param amount * @throws Exception */ public void withdrawFailedTransaction(int amount) throws Exception { userTransaction.begin(); event.fire(new Withdrawal(amount)); ActionSequence.addAction("checkpoint"); // Failed for any reason userTransaction.rollback(); }
/** * * @param withdrawal * @throws Exception */ public void withdrawAfterSuccess(@Observes(during = TransactionPhase.AFTER_SUCCESS) Withdrawal withdrawal) throws Exception { logEventFired(TransactionPhase.AFTER_SUCCESS); }
public void withdraw(long n) { queueAction(new Withdrawal(n)); } public void deposit(long n) { queueAction(new Deposit(n)); } void queueAction(Action action) { action.doAction(); if (actionsList.size() >= 10) actionsList.poll(); actionsList.offer(aaction); }
/** * * @param withdrawal * @throws Exception */ public void withdrawAfterCompletion(@Observes(during = TransactionPhase.AFTER_COMPLETION) Withdrawal withdrawal) throws Exception { logEventFired(TransactionPhase.AFTER_COMPLETION); }
/** * * @param withdrawal * @throws Exception */ public void withdrawBeforeCompletion(@Observes(during = TransactionPhase.BEFORE_COMPLETION) Withdrawal withdrawal) throws Exception { logEventFired(TransactionPhase.BEFORE_COMPLETION); }
/** * * @param failure * @throws Exception */ public void failBeforeCompletion(@Observes(during = TransactionPhase.IN_PROGRESS) Failure failure) throws Exception { logEventFired(TransactionPhase.IN_PROGRESS); userTransaction.setRollbackOnly(); }