Configuration config = createDefaultConfig(false);
config.setBackup(true);
HornetQServer server = new HornetQServerImpl(config);
server.start();
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(ServiceTestBase.INVM_CONNECTOR_FACTORY));
final ArrayList<Integer> executions = new ArrayList<Integer>();
try
{
StorageManager storage = getStorage();
ReplicationManagerImpl manager = new ReplicationManagerImpl((ClientSessionFactoryInternal) locator.createSessionFactory(), factory);
manager.start();
Journal replicatedJournal = new ReplicatedJournal((byte)1, new FakeJournal(), manager);
int numberOfAdds = 200;
final CountDownLatch latch = new CountDownLatch(numberOfAdds);
OperationContext ctx = storage.getContext();
for (int i = 0; i < numberOfAdds; i++)
{
final int nAdd = i;
if (i % 2 == 0)
{
replicatedJournal.appendPrepareRecord(i, new FakeData(), false);
}
ctx.executeOnCompletion(new IOAsyncTask()
{
public void onError(final int errorCode, final String errorMessage)
{
}
public void done()
{
System.out.println("Add " + nAdd);
executions.add(nAdd);
latch.countDown();
}
});
}
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
for (int i = 0; i < numberOfAdds; i++)
{
Assert.assertEquals(i, executions.get(i).intValue());
}
Assert.assertEquals(0, manager.getActiveTokens().size());
manager.stop();
}
finally
{
server.stop();
}
}