use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testXADuplicateDetection4.
@Test
public void testXADuplicateDetection4() throws Exception {
ClientSession session = sf.createSession(true, false, false);
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid, XAResource.TMNOFLAGS);
session.start();
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
session.createQueue(queueName, queueName, null, false);
ClientProducer producer = session.createProducer(queueName);
ClientMessage message = createMessage(session, 0);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.commit(xid, false);
session.close();
Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session = sf.createSession(true, false, false);
session.start(xid2, XAResource.TMNOFLAGS);
session.start();
producer = session.createProducer(queueName);
ClientConsumer consumer = session.createConsumer(queueName);
// Should NOT be able to resend it
message = createMessage(session, 1);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
session.end(xid2, XAResource.TMSUCCESS);
try {
session.prepare(xid2);
fail("Should throw an exception here!");
} catch (XAException expected) {
assertTrue(expected.getCause().toString().contains("DUPLICATE_ID_REJECTED"));
}
session.rollback(xid2);
Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid3, XAResource.TMNOFLAGS);
consumer.receive(250);
message = consumer.receiveImmediate();
Assert.assertNull(message);
DuplicateDetectionTest.log.info("ending session");
session.end(xid3, XAResource.TMSUCCESS);
DuplicateDetectionTest.log.info("preparing session");
session.prepare(xid3);
DuplicateDetectionTest.log.info("committing session");
session.commit(xid3, false);
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testXADuplicateDetectionPrepareAndRollbackStopServer.
@Test
public void testXADuplicateDetectionPrepareAndRollbackStopServer() throws Exception {
ClientSession session = sf.createSession(true, false, false);
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid, XAResource.TMNOFLAGS);
session.start();
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
session.createQueue(queueName, queueName, null, true);
ClientProducer producer = session.createProducer(queueName);
ClientMessage message = createMessage(session, 0);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.close();
server.stop();
waitForServerToStop(server);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(true, false, false);
session.start(xid, XAResource.TMJOIN);
session.end(xid, XAResource.TMSUCCESS);
session.rollback(xid);
session.close();
Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session = sf.createSession(true, false, false);
session.start(xid2, XAResource.TMNOFLAGS);
session.start();
producer = session.createProducer(queueName);
producer.send(message);
session.end(xid2, XAResource.TMSUCCESS);
session.prepare(xid2);
session.commit(xid2, false);
session.close();
session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(queueName);
ClientMessage msgRec = consumer.receive(5000);
assertNotNull(msgRec);
msgRec.acknowledge();
session.commit();
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testXADuplicateDetection1.
@Test
public void testXADuplicateDetection1() throws Exception {
ClientSession session = sf.createSession(true, false, false);
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid, XAResource.TMNOFLAGS);
session.start();
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
session.createQueue(queueName, queueName, null, false);
ClientProducer producer = session.createProducer(queueName);
ClientMessage message = createMessage(session, 0);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
session.end(xid, XAResource.TMSUCCESS);
session.close();
Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session = sf.createSession(true, false, false);
session.start(xid2, XAResource.TMNOFLAGS);
session.start();
producer = session.createProducer(queueName);
ClientConsumer consumer = session.createConsumer(queueName);
// Should be able to resend it and not get rejected since transaction didn't commit
message = createMessage(session, 1);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
session.end(xid2, XAResource.TMSUCCESS);
session.prepare(xid2);
session.commit(xid2, false);
Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid3, XAResource.TMNOFLAGS);
message = consumer.receive(250);
Assert.assertEquals(1, message.getObjectProperty(propKey));
message = consumer.receiveImmediate();
Assert.assertNull(message);
DuplicateDetectionTest.log.info("ending session");
session.end(xid3, XAResource.TMSUCCESS);
DuplicateDetectionTest.log.info("preparing session");
session.prepare(xid3);
DuplicateDetectionTest.log.info("committing session");
session.commit(xid3, false);
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testNoPersistXA1.
@Test
public void testNoPersistXA1() throws Exception {
server.stop();
config = createDefaultInVMConfig().setIDCacheSize(cacheSize).setPersistIDCache(false);
server = createServer(config);
server.start();
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(true, false, false);
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid, XAResource.TMNOFLAGS);
session.start();
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
session.createQueue(queueName, queueName, null, false);
ClientProducer producer = session.createProducer(queueName);
ClientConsumer consumer = session.createConsumer(queueName);
ClientMessage message = createMessage(session, 1);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
message = createMessage(session, 2);
SimpleString dupID2 = new SimpleString("hijklmnopqr");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
producer.send(message);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.commit(xid, false);
session.close();
sf.close();
server.stop();
waitForServerToStop(server);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(true, false, false);
Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid2, XAResource.TMNOFLAGS);
session.start();
session.createQueue(queueName, queueName, null, false);
producer = session.createProducer(queueName);
consumer = session.createConsumer(queueName);
message = createMessage(session, 1);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
message = createMessage(session, 2);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
producer.send(message);
session.end(xid2, XAResource.TMSUCCESS);
session.prepare(xid2);
session.commit(xid2, false);
Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid3, XAResource.TMNOFLAGS);
ClientMessage message2 = consumer.receive(200);
Assert.assertEquals(1, message2.getObjectProperty(propKey));
message2 = consumer.receive(200);
Assert.assertEquals(2, message2.getObjectProperty(propKey));
}
use of org.apache.activemq.artemis.core.transaction.impl.XidImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testPersistXA1.
@Test
public void testPersistXA1() throws Exception {
ClientSession session = addClientSession(sf.createSession(true, false, false));
Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid, XAResource.TMNOFLAGS);
session.start();
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
session.createQueue(queueName, queueName, null, false);
ClientProducer producer = session.createProducer(queueName);
ClientConsumer consumer = session.createConsumer(queueName);
ClientMessage message = createMessage(session, 1);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
message = createMessage(session, 2);
SimpleString dupID2 = new SimpleString("hijklmnopqr");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
producer.send(message);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.commit(xid, false);
session.close();
sf.close();
server.stop();
waitForServerToStop(server);
server.start();
sf = createSessionFactory(locator);
session = addClientSession(sf.createSession(true, false, false));
Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid2, XAResource.TMNOFLAGS);
session.start();
session.createQueue(queueName, queueName, null, false);
producer = session.createProducer(queueName);
consumer = session.createConsumer(queueName);
message = createMessage(session, 1);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
message = createMessage(session, 2);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
producer.send(message);
session.end(xid2, XAResource.TMSUCCESS);
try {
session.prepare(xid2);
fail("Should throw an exception here!");
} catch (XAException expected) {
}
session.rollback(xid2);
Xid xid3 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
session.start(xid3, XAResource.TMNOFLAGS);
ClientMessage message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
}
Aggregations