server0.start();
locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
ClientSession session0 = sf0.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
final int numMessages = 1000;
final SimpleString propKey = new SimpleString("testkey");
final SimpleString selectorKey = new SimpleString("animal");
for (int i = 0; i < numMessages; i++)
{
ClientMessage message = session0.createMessage(false);
message.getBodyBuffer().writeBytes(new byte[1024]);
message.putIntProperty(propKey, i);
message.putStringProperty(selectorKey, new SimpleString("monkey" + i));
producer0.send(message);
}
server1.start();
// Inserting the duplicateIDs so the bridge will fail in a few
{
long ids[] = new long[100];
Queue queue = server0.locateQueue(new SimpleString(queueName0));
LinkedListIterator<MessageReference> iterator = queue.iterator();
for (int i = 0; i < 100; i++)
{
iterator.hasNext();
ids[i] = iterator.next().getMessage().getMessageID();
}
iterator.close();
DuplicateIDCache duplicateTargetCache = server1.getPostOffice()
.getDuplicateIDCache(PostOfficeImpl.BRIDGE_CACHE_STR.concat(forwardAddress));
TransactionImpl tx = new TransactionImpl(server1.getStorageManager());
for (long id : ids)
{
byte[] duplicateArray = BridgeImpl.getDuplicateBytes(server0.getNodeManager().getUUID(), id);
duplicateTargetCache.addToCache(duplicateArray, tx);
}
tx.commit();
}
Thread.sleep(1000);
ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
ClientSession session1 = sf1.createSession(false, true, true);
try
{
session1.createQueue(forwardAddress, queueName1);
}
catch (Throwable ignored)
{
ignored.printStackTrace();
}
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
for (int i = 100; i < numMessages; i++)
{
ClientMessage message = consumer1.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty(propKey).intValue());
message.acknowledge();
}
session1.commit();
Assert.assertNull(consumer1.receiveImmediate());
consumer1.close();
session1.deleteQueue(queueName1);
session1.close();
sf1.close();
server1.stop();