// start delivery
OrderCheckingMessageHandler ocm = new OrderCheckingMessageHandler(
topic, subId, startMsgId, numMsgs);
subscriber.startDelivery(topic, subId, ocm);
for (int i=0; i<numMsgs; i++) {
Message msg = Message.newBuilder().setBody(
ByteString.copyFromUtf8(Integer.toString(startMsgId + i))).build();
publisher.publish(topic, msg);
}
logger.info("Publish finished.");
queue.take();
logger.info("Deliver finished.");
// check messages received in order
assertTrue(ocm.isInOrder());
// wait for retention secs
Thread.sleep((RETENTION_SECS_VALUE + 2) * 1000);
subscriber.stopDelivery(topic, subId);
subscriber.closeSubscription(topic, subId);
startMsgId = 20;
// reconnect it again
subscriber.subscribe(topic, subId, CreateOrAttach.CREATE_OR_ATTACH);
ocm = new OrderCheckingMessageHandler(topic, subId, startMsgId, numMsgs);
subscriber.startDelivery(topic, subId, ocm);
for (int i=0; i<numMsgs; i++) {
Message msg = Message.newBuilder().setBody(
ByteString.copyFromUtf8(Integer.toString(startMsgId + i))).build();
publisher.publish(topic, msg);
}
queue.take();
// check messages received in order