{
ClientSessionFactory sf = HornetQClient.createClientSessionFactory(new TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
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));