mirror of https://github.com/apache/activemq.git
[AMQ-3166] init rollbackonly exception cause such that xaexception has meaning, thanks to james (jtahlborn) for the suggestion
This commit is contained in:
parent
f40532a23d
commit
7077d2b910
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue