Search in sources :

Example 41 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class FailoverTest method testXAMessagesConsumedSoRollbackOnPrepare.

@Test(timeout = 120000)
public void testXAMessagesConsumedSoRollbackOnPrepare() throws Exception {
    createSessionFactory();
    ClientSession session1 = createSessionAndQueue();
    ClientProducer producer = session1.createProducer(FailoverTestBase.ADDRESS);
    sendMessagesSomeDurable(session1, producer);
    session1.commit();
    ClientSession session2 = createSession(sf, true, false, false);
    ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
    session2.start();
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session2.start(xid, XAResource.TMNOFLAGS);
    receiveMessages(consumer);
    session2.end(xid, XAResource.TMSUCCESS);
    crash(session2);
    try {
        session2.prepare(xid);
        Assert.fail("Should throw exception");
    } catch (XAException e) {
        Assert.assertEquals(XAException.XAER_RMFAIL, e.errorCode);
    }
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 42 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class OutgoingConnectionTest method testSimpleMessageSendAndReceiveXA.

@Test
public void testSimpleMessageSendAndReceiveXA() throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection();
    XASession s = queueConnection.createXASession();
    XAResource resource = s.getXAResource();
    resource.start(xid, XAResource.TMNOFLAGS);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receiveNoWait();
    assertNull(textMessage);
    resource.end(xid, XAResource.TMSUCCESS);
    resource.commit(xid, true);
    resource.start(xid, XAResource.TMNOFLAGS);
    textMessage = (TextMessage) consumer.receiveNoWait();
    resource.end(xid, XAResource.TMSUCCESS);
    resource.commit(xid, true);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    // When I wrote this call, this method was doing an infinite loop.
    // this is just to avoid such thing again
    textMessage.getJMSDeliveryTime();
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) XASession(javax.jms.XASession) MessageProducer(javax.jms.MessageProducer) XAQueueConnection(javax.jms.XAQueueConnection) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 43 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class ScheduledMessageTest method testTxMessageDeliveredCorrectly.

public void testTxMessageDeliveredCorrectly(final boolean recover) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(true, false, false);
    session.createQueue(atestq, atestq, null, true);
    session.start(xid, XAResource.TMNOFLAGS);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage message = createDurableMessage(session, "testINVMCoreClient");
    long time = System.currentTimeMillis() + 1000;
    message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(message);
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    if (recover) {
        producer.close();
        session.close();
        server.stop();
        server = null;
        server = createServer(true, configuration);
        server.start();
        sessionFactory = createSessionFactory(locator);
        session = sessionFactory.createSession(true, false, false);
    }
    session.commit(xid, false);
    ClientConsumer consumer = session.createConsumer(atestq);
    session.start();
    session.start(xid2, XAResource.TMNOFLAGS);
    ClientMessage message2 = consumer.receive(11000);
    long end = System.currentTimeMillis();
    System.out.println("elapsed time = " + (end - time));
    Assert.assertTrue(end >= time);
    Assert.assertNotNull(message2);
    Assert.assertEquals("testINVMCoreClient", message2.getBodyBuffer().readString());
    message2.acknowledge();
    session.end(xid2, XAResource.TMSUCCESS);
    session.prepare(xid2);
    session.commit(xid2, false);
    consumer.close();
    // Make sure no more messages
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 44 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class BasicXaRecoveryTest method testRollbackPaging.

public void testRollbackPaging(final boolean restartServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    SimpleString pageQueue = new SimpleString("pagequeue");
    AddressSettings pageAddressSettings = new AddressSettings().setMaxSizeBytes(100 * 1024).setPageSizeBytes(10 * 1024);
    addressSettings.put(pageQueue.toString(), pageAddressSettings);
    addSettings();
    clientSession.createQueue(pageQueue, pageQueue, null, true);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    ClientProducer pageProducer = clientSession.createProducer(pageQueue);
    for (int i = 0; i < 1000; i++) {
        ClientMessage m = createBytesMessage(new byte[512], true);
        pageProducer.send(m);
    }
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (restartServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(1, xids.length);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    clientSession.rollback(xid);
    clientSession.start();
    ClientConsumer pageConsumer = clientSession.createConsumer(pageQueue);
    Assert.assertNull(pageConsumer.receiveImmediate());
// Management message (from createQueue) will not be taken into account again as it is nonPersistent
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 45 with XidImpl

use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.

the class BasicXaRecoveryTest method testNonPersistentMultipleIDs.

@Test
public void testNonPersistentMultipleIDs() throws Exception {
    for (int i = 0; i < 10; i++) {
        Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
        ClientMessage m1 = createTextMessage("m1", false);
        ClientMessage m2 = createTextMessage("m2", false);
        ClientMessage m3 = createTextMessage("m3", false);
        ClientMessage m4 = createTextMessage("m4", false);
        clientSession.start(xid, XAResource.TMNOFLAGS);
        clientProducer.send(m1);
        clientProducer.send(m2);
        clientProducer.send(m3);
        clientProducer.send(m4);
        clientSession.end(xid, XAResource.TMSUCCESS);
        clientSession.prepare(xid);
        if (i == 2) {
            clientSession.commit(xid, false);
        }
        recreateClients();
    }
    stopAndRestartServer();
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(9, xids.length);
}
Also used : Xid(javax.transaction.xa.Xid) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Test(org.junit.Test)

Aggregations

XidImpl (org.apache.activemq.artemis.core.transaction.impl.XidImpl)59 Xid (javax.transaction.xa.Xid)57 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)44 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)40 Test (org.junit.Test)39 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 XAException (javax.transaction.xa.XAException)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 CountDownLatch (java.util.concurrent.CountDownLatch)10 Queue (javax.jms.Queue)6 XASession (javax.jms.XASession)6 XAConnection (javax.jms.XAConnection)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)5 MessageProducer (javax.jms.MessageProducer)4 TemporaryQueue (javax.jms.TemporaryQueue)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3