private void doTestRuleForSelectiveRollbackOnChecked(RuleBasedTransactionAttribute rta) { assertTrue(rta.rollbackOn(new RuntimeException())); // Check default behaviour is overridden assertFalse(rta.rollbackOn(new Exception())); // Check that default behaviour is overridden assertTrue(rta.rollbackOn(new RemoteException())); }
@Test public void testRollbackNever() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new NoRollbackRuleAttribute("Throwable")); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertFalse(rta.rollbackOn(new Throwable())); assertFalse(rta.rollbackOn(new RuntimeException())); assertFalse(rta.rollbackOn(new MyRuntimeException(""))); assertFalse(rta.rollbackOn(new Exception())); assertFalse(rta.rollbackOn(new IOException())); }
@Test public void testDefaultRule() { RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(); assertTrue(rta.rollbackOn(new RuntimeException())); assertTrue(rta.rollbackOn(new MyRuntimeException(""))); assertFalse(rta.rollbackOn(new Exception())); assertFalse(rta.rollbackOn(new IOException())); }
@Test public void testRuleForCommitOnUnchecked() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new NoRollbackRuleAttribute(MyRuntimeException.class.getName())); list.add(new RollbackRuleAttribute(IOException.class.getName())); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertTrue(rta.rollbackOn(new RuntimeException())); // Check default behaviour is overridden assertFalse(rta.rollbackOn(new MyRuntimeException(""))); assertFalse(rta.rollbackOn(new Exception())); // Check that default behaviour is overridden assertTrue(rta.rollbackOn(new IOException())); }
/** * Test one checked exception that should roll back. */ @Test public void testRuleForRollbackOnChecked() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new RollbackRuleAttribute(IOException.class.getName())); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertTrue(rta.rollbackOn(new RuntimeException())); assertTrue(rta.rollbackOn(new MyRuntimeException(""))); assertFalse(rta.rollbackOn(new Exception())); // Check that default behaviour is overridden assertTrue(rta.rollbackOn(new IOException())); }
/** * Check that a rule can cause commit on a IOException * when Exception prompts a rollback. */ @Test public void testRuleForCommitOnSubclassOfChecked() { List<RollbackRuleAttribute> list = new LinkedList<>(); // Note that it's important to ensure that we have this as // a FQN: otherwise it will match everything! list.add(new RollbackRuleAttribute("java.lang.Exception")); list.add(new NoRollbackRuleAttribute("IOException")); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertTrue(rta.rollbackOn(new RuntimeException())); assertTrue(rta.rollbackOn(new Exception())); // Check that default behaviour is overridden assertFalse(rta.rollbackOn(new IOException())); }
@Test public void testToStringMatchesEditor() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new NoRollbackRuleAttribute("Throwable")); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); TransactionAttributeEditor tae = new TransactionAttributeEditor(); tae.setAsText(rta.toString()); rta = (RuleBasedTransactionAttribute) tae.getValue(); assertFalse(rta.rollbackOn(new Throwable())); assertFalse(rta.rollbackOn(new RuntimeException())); assertFalse(rta.rollbackOn(new MyRuntimeException(""))); assertFalse(rta.rollbackOn(new Exception())); assertFalse(rta.rollbackOn(new IOException())); }
/** * See <a href="http://forum.springframework.org/showthread.php?t=41350">this forum post</a>. */ @Test public void testConflictingRulesToDetermineExactContract() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new NoRollbackRuleAttribute(MyBusinessWarningException.class)); list.add(new RollbackRuleAttribute(MyBusinessException.class)); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertTrue(rta.rollbackOn(new MyBusinessException())); assertFalse(rta.rollbackOn(new MyBusinessWarningException())); }
@Test public void testNonDefaultRollbackRules() throws Exception { TransactionAttributeEditor editor = new TransactionAttributeEditor(); editor.setAsText("+RuntimeException,+SkippableException"); RuleBasedTransactionAttribute attr = (RuleBasedTransactionAttribute) editor.getValue(); attr.getRollbackRules().add(new RollbackRuleAttribute(Exception.class)); assertTrue(attr.rollbackOn(new Exception(""))); assertFalse(attr.rollbackOn(new RuntimeException(""))); assertFalse(attr.rollbackOn(new SkippableException(""))); }
@Override public boolean rollbackOn(Throwable ex) { if (ex instanceof ListenerExecutionFailedException) { return super.rollbackOn(ex.getCause()); } else { return super.rollbackOn(ex); } }
@Override public boolean rollbackOn(Throwable ex) { if (ex instanceof ListenerExecutionFailedException) { return super.rollbackOn(ex.getCause()); } else { return super.rollbackOn(ex); } }