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);
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();
messagingService2.stop();
messagingService2 = HornetQServers.newHornetQServer(conf);
messagingService2.start();
sf = HornetQClient.createClientSessionFactory(new TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
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));