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);
}
}
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();
}
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();
}
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
}
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);
}
Aggregations