MessageSeqId.Builder builder = MessageSeqId.newBuilder();
builder.setLocalComponent(seqId);
MessageSeqId msgId = builder.build();
SubscriptionState.Builder stateBuilder = SubscriptionState.newBuilder(SubscriptionState.getDefaultInstance()).setMsgId(msgId);
SubscriptionData data = SubscriptionData.newBuilder().setState(stateBuilder).build();
// create a subscription state
subManager.createSubscriptionData(topic, subid, data, callback, null);
Either<Version, PubSubException> cbResult = callback.queue.take();
Version v1 = cbResult.left();
Assert.assertEquals("Should not fail with PubSubException",
null, cbResult.right());
// read subscriptions
subManager.readSubscriptions(topic, subsCallback, null);
res = subsCallback.queue.take();
Assert.assertEquals("Should find just 1 subscriber", 1, res.left().size());
Assert.assertEquals("Should not fail with PubSubException", null, res.right());
Versioned<SubscriptionData> versionedSubData = res.left().get(subid);
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v1.compare(versionedSubData.getVersion()));
SubscriptionData imss = versionedSubData.getValue();
Assert.assertEquals("Found inconsistent subscription state",
data, imss);
Assert.assertEquals("Found inconsistent last consumed seq id",
seqId, imss.getState().getMsgId().getLocalComponent());
// move consume seq id
seqId = 99;
builder = MessageSeqId.newBuilder();
builder.setLocalComponent(seqId);
msgId = builder.build();
stateBuilder = SubscriptionState.newBuilder(data.getState()).setMsgId(msgId);
data = SubscriptionData.newBuilder().setState(stateBuilder).build();
// update subscription state
if (subManager.isPartialUpdateSupported()) {
subManager.updateSubscriptionData(topic, subid, data, versionedSubData.getVersion(), callback, null);
} else {
subManager.replaceSubscriptionData(topic, subid, data, versionedSubData.getVersion(), callback, null);
}
cbResult = callback.queue.take();
Assert.assertEquals("Fail to update a subscription state", null, cbResult.right());
Version v2 = cbResult.left();
// read subscription state
subManager.readSubscriptionData(topic, subid, readCallback, null);
Assert.assertEquals("Found inconsistent subscription state",
data, readCallback.queue.take().left().getValue());
// read subscriptions again
subManager.readSubscriptions(topic, subsCallback, null);
res = subsCallback.queue.take();
Assert.assertEquals("Should find just 1 subscriber", 1, res.left().size());
Assert.assertEquals("Should not fail with PubSubException", null, res.right());
versionedSubData = res.left().get(subid);
Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(versionedSubData.getVersion()));
imss = res.left().get(subid).getValue();
Assert.assertEquals("Found inconsistent subscription state",
data, imss);
Assert.assertEquals("Found inconsistent last consumed seq id",
seqId, imss.getState().getMsgId().getLocalComponent());
// update or replace subscription data with bad version
if (subManager.isPartialUpdateSupported()) {
subManager.updateSubscriptionData(topic, subid, data, v1, callback, null);
} else {