Here's a test I've just put together.
It addss a bunch of dummy XAResources to the tx, as well as the XASession
XAResource.
On prepare one of the dummy XAResources fails, causing rollback to happen, and
the message *isn't* sent.
As far as I can tell this is basically what you're trying to do.
The test runs passes, and no message is sent.
| public void test2PCSendFailOnPrepare() throws Exception
| {
| if (ServerManagement.isRemote()) return;
|
| XAConnection conn = null;
| Connection conn2 = null;
| try
| {
| conn = cf.createXAConnection();
|
| tm.begin();
|
| XASession sess = conn.createXASession();
| MessagingXAResource res =
(MessagingXAResource)sess.getXAResource();
|
| //prevent 1Pc optimisation
| res.setPreventJoining(true);
|
| XAResource res2 = new DummyXAResource(true);
| XAResource res3 = new DummyXAResource();
| XAResource res4 = new DummyXAResource();
|
| Transaction tx = tm.getTransaction();
| tx.enlistResource(res);
| tx.enlistResource(res2);
| tx.enlistResource(res3);
| tx.enlistResource(res4);
|
| MessageProducer prod = sess.createProducer(queue);
| prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
| Message m = sess.createTextMessage("XATest1");
| prod.send(queue, m);
| m = sess.createTextMessage("XATest2");
| prod.send(queue, m);
|
| try
| {
| tx.commit();
| }
| catch (Exception e)
| {
| //We should expect this
| }
|
| conn2 = cf.createConnection();
| conn2.start();
| Session sessReceiver = conn2.createSession(false,
Session.AUTO_ACKNOWLEDGE);
| MessageConsumer cons = sessReceiver.createConsumer(queue);
| Message m2 = cons.receive(1000);
| assertNull(m2);
|
| }
| finally
| {
| if (conn != null)
| {
| conn.close();
| }
| if (conn2 != null)
| {
| conn2.close();
| }
| }
| }
|
| static class DummyXAResource implements XAResource
| {
| boolean failOnPrepare;
|
| DummyXAResource()
| {
| }
|
| DummyXAResource(boolean failOnPrepare)
| {
| this.failOnPrepare = failOnPrepare;
| }
|
| public void commit(Xid arg0, boolean arg1) throws XAException
| {
| }
|
| public void end(Xid arg0, int arg1) throws XAException
| {
| }
|
| public void forget(Xid arg0) throws XAException
| {
| }
|
| public int getTransactionTimeout() throws XAException
| {
| return 0;
| }
|
| public boolean isSameRM(XAResource arg0) throws XAException
| {
| return false;
| }
|
| public int prepare(Xid arg0) throws XAException
| {
| if (failOnPrepare)
| {
| throw new XAException(XAException.XAER_RMERR);
| }
| return XAResource.XA_OK;
| }
|
| public Xid[] recover(int arg0) throws XAException
| {
| return null;
| }
|
| public void rollback(Xid arg0) throws XAException
| {
| }
|
| public boolean setTransactionTimeout(int arg0) throws XAException
| {
| return false;
| }
|
| public void start(Xid arg0, int arg1) throws XAException
| {
|
| }
|
| }
|
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3948002#3948002
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3948002
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user