use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceCommitSuspendedNotRemoved.
@Test
public void testXAResourceCommitSuspendedNotRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
session.getXAResource().end(xid, XAResource.TMSUSPEND);
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
// amq5.x doesn't pass suspend flags to broker,
// directly suspend the tx
transaction.suspend();
session.getXAResource().commit(xid, true);
} catch (XAException ex) {
// ignore
} finally {
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNotNull(transaction);
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceCommittedRemoved.
@Test
public void testXAResourceCommittedRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("xa message"));
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().commit(xid, true);
}
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNull(transaction);
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceRolledBackSuspendedNotRemoved.
@Test
public void testXAResourceRolledBackSuspendedNotRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
session.getXAResource().end(xid, XAResource.TMSUSPEND);
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
// directly suspend the tx
transaction.suspend();
session.getXAResource().rollback(xid);
} catch (XAException ex) {
// ignore
} finally {
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNotNull(transaction);
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class ServerSessionImpl method individualAcknowledge.
@Override
public void individualAcknowledge(final long consumerID, final long messageID) throws Exception {
ServerConsumer consumer = findConsumer(consumerID);
if (tx != null && tx.getState() == State.ROLLEDBACK) {
// JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just
// have these messages to be stuck on the limbo until the server is restarted
// The tx has already timed out, so we need to ack and rollback immediately
Transaction newTX = newTransaction();
consumer.individualAcknowledge(tx, messageID);
newTX.rollback();
} else {
consumer.individualAcknowledge(autoCommitAcks ? null : tx, messageID);
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class ServerSessionImpl method findConsumer.
private ServerConsumer findConsumer(long consumerID) throws Exception {
ServerConsumer consumer = locateConsumer(consumerID);
if (consumer == null) {
Transaction currentTX = tx;
ActiveMQIllegalStateException exception = ActiveMQMessageBundle.BUNDLE.consumerDoesntExist(consumerID);
if (currentTX != null) {
currentTX.markAsRollbackOnly(exception);
}
throw exception;
}
return consumer;
}
Aggregations