// Write non-existed persistence info
tpManager.writeTopicPersistenceInfo(topic, LedgerRanges.getDefaultInstance(),
Version.NEW, writeCallback, null);
Either<Version, PubSubException> res = writeCallback.queue.take();
Assert.assertEquals(null, res.right());
Version v1 = res.left();
// read persistence info
tpManager.readTopicPersistenceInfo(topic, readCallback, null);
Versioned<LedgerRanges> ranges = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v1.compare(ranges.getVersion()));
Assert.assertEquals(LedgerRanges.getDefaultInstance(), ranges.getValue());
LedgerRange lastRange = LedgerRange.newBuilder().setLedgerId(1).build();
LedgerRanges.Builder builder = LedgerRanges.newBuilder();
builder.addRanges(lastRange);
LedgerRanges newRanges = builder.build();
// write existed persistence info with null version
tpManager.writeTopicPersistenceInfo(topic, newRanges, Version.NEW,
writeCallback, null);
res = writeCallback.queue.take();
Assert.assertNotNull(res.right());
Assert.assertTrue(res.right() instanceof PubSubException.TopicPersistenceInfoExistsException);
// write existed persistence info with right version
tpManager.writeTopicPersistenceInfo(topic, newRanges, 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 persistence info
tpManager.readTopicPersistenceInfo(topic, readCallback, null);
ranges = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(ranges.getVersion()));
Assert.assertEquals(newRanges, ranges.getValue());
lastRange = LedgerRange.newBuilder().setLedgerId(2).build();
builder = LedgerRanges.newBuilder();
builder.addRanges(lastRange);
LedgerRanges newRanges2 = builder.build();
// write existed persistence info with bad version
tpManager.writeTopicPersistenceInfo(topic, newRanges2, v1,
writeCallback, null);
res = writeCallback.queue.take();
Assert.assertNotNull(res.right());
Assert.assertTrue(res.right() instanceof PubSubException.BadVersionException);
// read persistence info
tpManager.readTopicPersistenceInfo(topic, readCallback, null);
ranges = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(ranges.getVersion()));
Assert.assertEquals(newRanges, ranges.getValue());
// delete with bad version
tpManager.deleteTopicPersistenceInfo(topic, v1, deleteCallback, null);
Assert.assertTrue(deleteCallback.queue.take().right() instanceof
PubSubException.BadVersionException);
// read persistence info
tpManager.readTopicPersistenceInfo(topic, readCallback, null);
ranges = readCallback.queue.take().left();
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(ranges.getVersion()));
Assert.assertEquals(newRanges, ranges.getValue());
// delete existed persistence info with right version
tpManager.deleteTopicPersistenceInfo(topic, v2, deleteCallback, null);
Assert.assertEquals(null, deleteCallback.queue.take().right());