use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class XidCodecSupport method decodeXid.
public static Xid decodeXid(final ActiveMQBuffer in) {
int formatID = in.readInt();
byte[] bq = new byte[in.readInt()];
in.readBytes(bq);
byte[] gtxid = new byte[in.readInt()];
in.readBytes(gtxid);
Xid xid = new XidImpl(bq, formatID, gtxid);
return xid;
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class FailoverTest method testTimeoutOnFailoverTransactionCommit.
// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionCommit() throws Exception {
locator.setCallTimeout(5000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
if (nodeManager instanceof InVMNodeManager) {
((InVMNodeManager) nodeManager).failoverPause = 5000L;
}
ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
final ClientSession session = createSession(sf1, true, false, false);
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
final CountDownLatch connectionFailed = new CountDownLatch(1);
session.addFailureListener(new SessionFailureListener() {
@Override
public void beforeReconnect(ActiveMQException exception) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
}
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed.countDown();
}
});
final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
session.start(xid, XAResource.TMNOFLAGS);
for (int i = 0; i < 500; i++) {
ClientMessage message = session.createMessage(true);
message.putIntProperty("counter", i);
producer.send(message);
}
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
crash(true, session);
try {
session.commit(xid, false);
} catch (XAException e) {
// there is still an edge condition that we must deal with
Assert.assertTrue(connectionFailed.await(10, TimeUnit.SECONDS));
session.commit(xid, false);
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
for (int i = 0; i < 500; i++) {
ClientMessage m = consumer.receive(1000);
Assert.assertNotNull(m);
Assert.assertEquals(i, m.getIntProperty("counter").intValue());
}
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class FailoverTest method testXAMessagesConsumedSoRollbackOnEnd2.
@Test(timeout = 120000)
public void testXAMessagesConsumedSoRollbackOnEnd2() throws Exception {
createSessionFactory();
ClientSession session1 = createSessionAndQueue();
ClientProducer producer = session1.createProducer(FailoverTestBase.ADDRESS);
for (int i = 0; i < NUM_MESSAGES; i++) {
// some are durable, some are not!
producer.send(createMessage(session1, i, true));
}
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);
crash(session2);
receiveMessages(consumer);
try {
session2.end(xid, XAResource.TMSUCCESS);
Assert.fail("Should throw exception");
} catch (XAException e) {
}
// Since the end was not accepted, the messages should be redelivered
receiveMessages(consumer);
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class FailoverTest method testXAMessagesSentSoRollbackOnCommit.
// This might happen if 1PC optimisation kicks in
@Test(timeout = 120000)
public void testXAMessagesSentSoRollbackOnCommit() throws Exception {
createSessionFactory();
ClientSession session = createSession(sf, true, false, false);
Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
session.start(xid, XAResource.TMNOFLAGS);
sendMessagesSomeDurable(session, producer);
session.end(xid, XAResource.TMSUCCESS);
crash(session);
try {
session.commit(xid, false);
Assert.fail("Should throw exception");
} catch (XAException e) {
Assert.assertEquals(XAException.XAER_NOTA, e.errorCode);
}
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class FailoverTest method testXAMessagesNotSentSoNoRollbackOnCommit.
@Test(timeout = 120000)
public void testXAMessagesNotSentSoNoRollbackOnCommit() throws Exception {
createSessionFactory();
ClientSession session = createSession(sf, true, false, false);
Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
session.start(xid, XAResource.TMNOFLAGS);
sendMessagesSomeDurable(session, producer);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.commit(xid, false);
crash(session);
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
Xid xid2 = new XidImpl("tfytftyf".getBytes(), 54654, "iohiuohiuhgiu".getBytes());
session.start(xid2, XAResource.TMNOFLAGS);
receiveDurableMessages(consumer);
session.end(xid2, XAResource.TMSUCCESS);
session.prepare(xid2);
session.commit(xid2, false);
}
Aggregations