fail("Should not reach here!");
}
subscriber.startDelivery(topic, subscriberId, new TestMessageHandler());
// new a client
HedwigClient client2 = new HedwigClient(new ClientConfiguration() {
@Override
public HedwigSocketAddress getDefaultServerHedwigSocketAddress() {
return getDefaultHedwigAddress();
}
});
Subscriber subscriber2 = client2.getSubscriber();
Publisher publisher2 = client2.getPublisher();
SynchronousQueue<SubscriptionEvent> eventQueue2 =
new SynchronousQueue<SubscriptionEvent>();
subscriber2.addSubscriptionListener(new TestSubscriptionListener(eventQueue2));
try {
subscriber2.subscribe(topic, subscriberId, options);
} catch (PubSubException.ServiceDownException e) {
fail("Should not reach here!");
}
SynchronousQueue<Boolean> consumeQueue2 = new SynchronousQueue<Boolean>();
subscriber2.startDelivery(topic, subscriberId, new TestMessageHandler(consumeQueue2));
assertEquals(SubscriptionEvent.SUBSCRIPTION_FORCED_CLOSED, eventQueue.take());
assertTrue(eventQueue2.isEmpty());
// Now publish some messages for the topic to be consumed by the
// subscriber.
publisher.asyncPublish(topic, Message.newBuilder().setBody(ByteString.copyFromUtf8("Message #1")).build(),
new TestCallback(), null);
assertTrue(queue.take());
assertTrue(consumeQueue2.take());
assertTrue(consumeQueue.isEmpty());
publisher2.asyncPublish(topic, Message.newBuilder().setBody(ByteString.copyFromUtf8("Message #2")).build(),
new TestCallback(), null);
assertTrue(queue.take());
assertTrue(consumeQueue2.take());
assertTrue(consumeQueue.isEmpty());
client2.close();
}