public class NewJdbcWrongUsageMockTest extends AbstractMockJdbcTest {
private final static Logger log = LoggerFactory.getLogger(NewJdbcWrongUsageMockTest.class);
public void testPrepareXAFailureCase() throws Exception {
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
tm.begin();
Connection connection1 = poolingDataSource1.getConnection();
PooledConnectionProxy handle = (PooledConnectionProxy) connection1;
JdbcPooledConnection pc1 = handle.getPooledConnection();
XAConnection xaConnection1 = (XAConnection) getWrappedXAConnectionOf(pc1);
MockXAResource mockXAResource = (MockXAResource) xaConnection1.getXAResource();
XAException xaException = new XAException("resource failed");
xaException.errorCode = XAException.XAER_RMERR;
mockXAResource.setPrepareException(xaException);
connection1.createStatement();
Connection connection2 = poolingDataSource2.getConnection();
connection2.createStatement();
connection1.close();
connection2.close();
try {
tm.commit();
fail("TM should have thrown rollback exception");
} catch (RollbackException ex) {
assertTrue("Got: " + ex.getMessage(), ex.getMessage().matches("transaction failed to prepare: a Bitronix Transaction with GTRID (.*?) status=ROLLEDBACK, 2 resource\\(s\\) enlisted (.*?)"));
assertTrue("Got: " + ex.getCause().getMessage(), ex.getCause().getMessage().matches("transaction failed during prepare of a Bitronix Transaction with GTRID (.*?) status=PREPARING, 2 resource\\(s\\) enlisted (.*?) resource\\(s\\) \\[pds1\\] threw unexpected exception"));