Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQXAConnection


     */
    public void testXAPrepareFailure() throws Exception {

        assertNotNull(connectionUri);
        ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("failover:(" + connectionUri + ")");
        ActiveMQXAConnection xaConnection = (ActiveMQXAConnection)cf.createConnection();
        xaConnection.start();
        XASession session = xaConnection.createXASession();
        XAResource resource = session.getXAResource();
        Xid tid = createXid();
        resource.start(tid, XAResource.TMNOFLAGS);

        MessageProducer producer = session.createProducer(session.createQueue(this.getClass().getName()));
        Message message = session.createTextMessage("Sample Message");
        producer.send(message);
        resource.end(tid, XAResource.TMSUCCESS);
        try {
            LOG.debug("Calling XA prepare(), expecting an exception");
            int ret = resource.prepare(tid);
            if (XAResource.XA_OK == ret)
                resource.commit(tid, false);
        } catch (XAException xae) {
            LOG.info("Received excpected XAException: {}", xae.getMessage());
            LOG.info("Rolling back transaction {}", tid);
           
            // with bug AMQ-4950 the thrown error reads "Cannot call prepare now"
            // we check that we receive the original exception message as
            // thrown by the BrokerPlugin
            assertEquals(simulatedExceptionMessage, xae.getMessage());
            resource.rollback(tid);
        }
        // couple of assertions
        assertTransactionGoneFromBroker(tid);
        assertTransactionGoneFromConnection(broker.getBrokerName(), xaConnection.getClientID(), xaConnection.getConnectionInfo().getConnectionId(), tid);
        assertTransactionGoneFromFailoverState(xaConnection, tid);

        //cleanup
        producer.close();
        session.close();
        xaConnection.close();
        LOG.debug("testXAPrepareFailure() finished.");
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.ActiveMQXAConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.