StubCallback<Versioned<HubInfo>> readCallback = new StubCallback<Versioned<HubInfo>>();
StubCallback<Version> writeCallback = new StubCallback<Version>();
StubCallback<Void> deleteCallback = new StubCallback<Void>();
Either<Version, PubSubException> res;
HubInfo owner = new HubInfo(new HedwigSocketAddress("127.0.0.1", 8008), 999);
// Write non-existed owner info
toManager.writeOwnerInfo(topic, owner, Version.NEW, writeCallback, null);
res = writeCallback.queue.take();
Assert.assertEquals(null, res.right());
Version v1 = res.left();
// read owner info
toManager.readOwnerInfo(topic, readCallback, null);
Versioned<HubInfo> hubInfo = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v1.compare(hubInfo.getVersion()));
Assert.assertEquals(owner, hubInfo.getValue());
HubInfo newOwner = new HubInfo(new HedwigSocketAddress("127.0.0.1", 8008), 1000);
// write exsited owner info with null version
toManager.writeOwnerInfo(topic, newOwner, Version.NEW, writeCallback, null);
res = writeCallback.queue.take();
Assert.assertNotNull(res.right());
Assert.assertTrue(res.right() instanceof PubSubException.TopicOwnerInfoExistsException);
// write existed owner info with right version
toManager.writeOwnerInfo(topic, newOwner, v1, writeCallback, null);
res = writeCallback.queue.take();
Assert.assertEquals(null, res.right());
Version v2 = res.left();
Assert.assertEquals(Version.Occurred.AFTER, v2.compare(v1));
// read owner info
toManager.readOwnerInfo(topic, readCallback, null);
hubInfo = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(hubInfo.getVersion()));
Assert.assertEquals(newOwner, hubInfo.getValue());
HubInfo newOwner2 = new HubInfo(new HedwigSocketAddress("127.0.0.1", 8008), 1001);
// write existed owner info with bad version
toManager.writeOwnerInfo(topic, newOwner2, v1,
writeCallback, null);
res = writeCallback.queue.take();