Java Code Examples for javax.transaction.xa.XAResource#isSameRM()

The following examples show how to use javax.transaction.xa.XAResource#isSameRM() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMXAConnectionResource.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSameRM(XAResource otherResource) throws XAException {
    log.entering(this.getClass().getName(), "isSameRM");
    boolean isSame = false;
    try {
        // Drive the method calls to each of the proxied XAResource instances,
        // and return the logically ANDed value received from those method calls.
        if (getProxiedXAResources() != null) {
            isSame = true;
            for (XAResource resource : getProxiedXAResources()) {
                isSame = isSame && resource.isSameRM(otherResource);
            }
        }
        return isSame;
    } finally {
        log.exiting(this.getClass().getName(), "isSameRM", new Object[] {
                "isSame", Boolean.toString(isSame)
        });
    }
}
 
Example 2
Source File: TestFBXAResource.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testIsSameRM() throws Exception {
    FBManagedConnectionFactory mcf1 = initMcf();
    FBManagedConnection mc1 = mcf1.createManagedConnection();
    XAResource xa1 = mc1.getXAResource();
    FBManagedConnection mc2 = mcf1.createManagedConnection();
    XAResource xa2 = mc2.getXAResource();
    FBManagedConnectionFactory mcf3 = initMcf();
    FBManagedConnection mc3 = mcf3.createManagedConnection();
    XAResource xa3 = mc3.getXAResource();
    if (xa1.isSameRM(xa2)) {
        fail("isSameRM reports no difference from same mcf");
    }
    if (xa1.isSameRM(xa3)) {
        fail("isSameRM reports no difference from different mcf");
    }
    mc1.destroy();
    mc2.destroy();
    mc3.destroy();
}
 
Example 3
Source File: ActiveMQXAResourceWrapper.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSameRM(XAResource xaRes) throws XAException {
   if (xaRes instanceof ActiveMQXAResourceWrapper) {
      xaRes = ((ActiveMQXAResourceWrapper) xaRes).getDelegate(false);
   }

   XAResource xaResource = getDelegate(false);
   try {
      return xaResource.isSameRM(xaRes);
   } catch (XAException e) {
      throw check(e);
   }
}
 
Example 4
Source File: DtxStartPositiveTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if publishing messages works correctly with session joining. Steps are,
 * 1. Create two distributed transaction sessions and join one session to other.
 * 2. Publish messages using two sessions.
 * 3. Subscribe to the published queue and see if any message is received.
 * 4. Commit the session
 * 5. Subscribe to the queue and see if two messages are received
 */
@Test(groups = { "wso2.mb", "dtx" })
public void xaMultiSessionPublishTestCase()
        throws NamingException, JMSException, XAException, XPathExpressionException {
    String queueName = "DtxStartPositiveTestCaseXaMultiSessionPublishTestCase";

    InitialContext initialContext = JMSClientHelper.createInitialContextBuilder("admin", "admin", "localhost",
                                                                                getAMQPPort()).withQueue(queueName).build();

    XAConnectionFactory xaConnectionFactory = (XAConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_XA_CONNECTION_FACTORY);

    // Create XA resource one
    XAConnection xaConnectionOne = xaConnectionFactory.createXAConnection();
    xaConnectionOne.start();
    XASession xaSessionOne = xaConnectionOne.createXASession();

    XAResource xaResourceOne = xaSessionOne.getXAResource();
    Session sessionOne = xaSessionOne.getSession();

    Destination xaTestQueue = (Destination) initialContext.lookup(queueName);
    sessionOne.createQueue(queueName);
    MessageProducer producerOne = sessionOne.createProducer(xaTestQueue);

    // Create XA resource two
    XASession xaSessionTwo = xaConnectionOne.createXASession();

    XAResource xaResourceTwo = xaSessionTwo.getXAResource();
    Session sessionTwo = xaSessionTwo.getSession();

    MessageProducer producerTwo = sessionTwo.createProducer(xaTestQueue);

    Xid xid = JMSClientHelper.getNewXid();

    boolean sameRM = xaResourceOne.isSameRM(xaResourceTwo);

    Assert.assertEquals(sameRM, true, "Resource one and resource two are connected to different resource "
            + "managers");

    xaResourceOne.start(xid, XAResource.TMNOFLAGS);
    xaResourceTwo.start(xid, XAResource.TMJOIN);

    producerOne.send(sessionOne.createTextMessage("Test 1"));
    producerTwo.send(sessionTwo.createTextMessage("Test 2"));

    xaResourceOne.end(xid, XAResource.TMSUCCESS);

    // subscribe and see if the message is received
    ConnectionFactory nonXaConnectionFactory = (ConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_CONNECTION_FACTORY);
    Connection nonXaQueueConnection = nonXaConnectionFactory.createConnection();
    nonXaQueueConnection.start();
    Session nonXaQueueSession = nonXaQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer messageConsumer = nonXaQueueSession.createConsumer(xaTestQueue);

    // wait 5 seconds
    Message receive = messageConsumer.receive(5000);
    Assert.assertNull(receive, "Message received before committing");

    xaResourceOne.prepare(xid);
    xaResourceOne.commit(xid, false);

    xaConnectionOne.close();

    //This is only added to find out the reason for the intermittent failure of this test method. Should be removed
    // once the issue is identified.
    try {
        // Logging in
        LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
        String sessionCookie = loginLogoutClientForAdmin.login();
        AndesAdminClient admin = new AndesAdminClient(super.backendURL, sessionCookie);

        //Check message count in queue
        org.wso2.carbon.andes.stub.admin.types.Message[] queueOneMessages
                = admin.browseQueue(queueName, 0, 10);
        Assert.assertEquals(queueOneMessages.length, 2, "Message not published to queue " + queueName);

        //Logging out
        loginLogoutClientForAdmin.logout();

    } catch (RemoteException | AutomationUtilException | AndesAdminServiceBrokerManagerAdminException
            | LogoutAuthenticationExceptionException e) {
        e.printStackTrace();
    }

    receive = messageConsumer.receive(5000);
    Assert.assertNotNull(receive, "Message not received");

    receive = messageConsumer.receive(5000);
    Assert.assertNotNull(receive, "Message not received");

    nonXaQueueConnection.close();
}
 
Example 5
Source File: DtxStartPositiveTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if acknowledging a messages works correctly with session joining. Steps are,
 * 1. Publish two messages to two queues using two non-transacted sessions
 * 2. Create two distributed transaction sessions and join one session to other.
 * 3. Receive messages and ack using two sessions.
 * 4. Commit the session
 * 5. Subscribe to the published queue and see if any message is received.
 */
@Test(groups = { "wso2.mb", "dtx" })
public void xaStartJoinMessageAckTestCase()
        throws NamingException, JMSException, XAException, XPathExpressionException {
    String queueNameOne = "DtxStartPositiveTestCaseXaStartJoinMessageAckTestCaseOne";
    String queueNameTwo = "DtxStartPositiveTestCaseXaStartJoinMessageAckTestCaseTwo";

    InitialContext initialContext = JMSClientHelper.createInitialContextBuilder("admin", "admin", "localhost",
            getAMQPPort()).withQueue(queueNameOne).build();

    ConnectionFactory nonXaConnectionFactory = (ConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_CONNECTION_FACTORY);
    Connection nonXaQueueConnection = nonXaConnectionFactory.createConnection();
    nonXaQueueConnection.start();
    Session nonXaQueueSessionOne = nonXaQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Destination xaTestQueueOne = nonXaQueueSessionOne.createQueue(queueNameOne);
    Destination xaTestQueueTwo = nonXaQueueSessionOne.createQueue(queueNameTwo);

    MessageProducer nonXaQueueSessionProducerOne = nonXaQueueSessionOne.createProducer(xaTestQueueOne);
    MessageProducer nonXaQueueSessionProducerTwo = nonXaQueueSessionOne.createProducer(xaTestQueueTwo);

    nonXaQueueSessionProducerOne.send(nonXaQueueSessionOne.createTextMessage("Message 1"));
    nonXaQueueSessionProducerTwo.send(nonXaQueueSessionOne.createTextMessage("Message 2"));

    nonXaQueueSessionProducerOne.close();
    nonXaQueueSessionProducerTwo.close();

    XAConnectionFactory xaConnectionFactory = (XAConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_XA_CONNECTION_FACTORY);

    // Create XA resource one
    XAConnection xaConnectionOne = xaConnectionFactory.createXAConnection();
    xaConnectionOne.start();
    XASession xaSessionOne = xaConnectionOne.createXASession();

    XAResource xaResourceOne = xaSessionOne.getXAResource();
    Session sessionOne = xaSessionOne.getSession();

    MessageConsumer xaConsumerOne = sessionOne.createConsumer(xaTestQueueOne);

    // Create XA resource two
    XAConnection xaConnectionTwo = xaConnectionFactory.createXAConnection();
    xaConnectionTwo.start();
    XASession xaSessionTwo = xaConnectionTwo.createXASession();

    XAResource xaResourceTwo = xaSessionTwo.getXAResource();
    Session sessionTwo = xaSessionTwo.getSession();

    MessageConsumer xaConsumerTwo = sessionTwo.createConsumer(xaTestQueueTwo);

    Xid xid = JMSClientHelper.getNewXid();

    boolean sameRM = xaResourceOne.isSameRM(xaResourceTwo);

    Assert.assertEquals(sameRM, true, "Resource one and resource two are connected to different resource "
            + "managers");

    xaResourceOne.start(xid, XAResource.TMNOFLAGS);
    xaResourceTwo.start(xid, XAResource.TMJOIN);

    Message receivedMessageForQueueOne = xaConsumerOne.receive(5000);
    Assert.assertNotNull(receivedMessageForQueueOne, "A message was not received for queue " + queueNameOne);
    Message receivedMessageForQueueTwo = xaConsumerTwo.receive(5000);
    Assert.assertNotNull(receivedMessageForQueueTwo, "A message was not received for queue " + queueNameTwo);

    xaResourceOne.end(xid, XAResource.TMSUCCESS);

    xaResourceOne.prepare(xid);
    xaResourceOne.commit(xid, false);

    xaConnectionOne.close();
    xaConnectionTwo.close();

    // subscribe and see if the message is received
    MessageConsumer nonXaConsumerOne = nonXaQueueSessionOne.createConsumer(xaTestQueueOne);

    Session nonXaQueueSessionTwo = nonXaQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer nonXaConsumerTwo = nonXaQueueSessionTwo.createConsumer(xaTestQueueTwo);

    // wait 3 seconds
    receivedMessageForQueueOne = nonXaConsumerOne.receive(3000);
    Assert.assertNull(receivedMessageForQueueOne, "Message received after committing for queue " + queueNameOne);

    receivedMessageForQueueTwo = nonXaConsumerTwo.receive(3000);
    Assert.assertNull(receivedMessageForQueueTwo, "Message received after committing for queue " + queueNameTwo);

    nonXaQueueConnection.close();
}