[AMQ-3166] init rollbackonly exception cause such that xaexception has meaning, thanks to james (jtahlborn) for the suggestion

This commit is contained in:
gtully 2016-11-22 16:07:28 +00:00
parent f40532a23d
commit 7077d2b910
2 changed files with 9 additions and 6 deletions

View File

@ -44,7 +44,7 @@ public abstract class Transaction {
public static final byte PREPARED_STATE = 2; // can go to: 3
public static final byte FINISHED_STATE = 3;
boolean committed = false;
boolean rollbackOnly = false;
Throwable rollackOnlyCause = null;
private final ArrayList<Synchronization> synchronizations = new ArrayList<Synchronization>();
private byte state = START_STATE;
@ -111,9 +111,10 @@ public abstract class Transaction {
throw xae;
}
if (rollbackOnly) {
if (isRollbackOnly()) {
XAException xae = newXAException("COMMIT FAILED: Transaction marked rollback only", XAException.XA_RBROLLBACK);
TransactionRolledBackException transactionRolledBackException = new TransactionRolledBackException(xae.getLocalizedMessage());
transactionRolledBackException.initCause(rollackOnlyCause);
xae.initCause(transactionRolledBackException);
throw xae;
}
@ -215,14 +216,14 @@ public abstract class Transaction {
}
public void setRollbackOnly(Throwable cause) {
if (!rollbackOnly) {
if (!isRollbackOnly()) {
getLog().trace("setting rollback only, cause:", cause);
rollbackOnly = true;
rollackOnlyCause = cause;
}
}
public boolean isRollbackOnly() {
return rollbackOnly;
return rollackOnlyCause != null;
}
}

View File

@ -51,7 +51,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class AMQ3166Test {
public class {
private static final Logger LOG = LoggerFactory.getLogger(AMQ3166Test.class);
@ -133,6 +133,8 @@ public class AMQ3166Test {
fail("Expect TransactionRolledBackException");
} catch (JMSException expected) {
assertTrue(expected.getCause() instanceof XAException);
assertTrue(expected.getCause().getCause() instanceof TransactionRolledBackException);
assertTrue(expected.getCause().getCause().getCause() instanceof RuntimeException);
}
assertTrue("one message still there!", Wait.waitFor(new Wait.Condition() {