client.handshake();
Assert.assertTrue(subscribed.await(5, TimeUnit.SECONDS));
Assert.assertEquals(0, messages.size());
final ServerChannel chatChannel = bayeux.getChannel(channelName);
Assert.assertNotNull(chatChannel);
final int count = 5;
client.batch(new Runnable()
{
public void run()
{
for (int i = 0; i < count; ++i)
client.getChannel(channelName).publish("hello_" + i);
}
});
for (int i = 0; i < count; ++i)
Assert.assertEquals("hello_" + i, messages.poll(5, TimeUnit.SECONDS).getData());
// Wait for the long poll to happen
Thread.sleep(1000);
int port = connector.getLocalPort();
connector.stop();
// Wait for connections to process the remote close
Thread.sleep(1000);
Assert.assertTrue(connector.isStopped());
Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.UNCONNECTED));
// Send messages while client is offline
for (int i = count; i < 2 * count; ++i)
chatChannel.publish(null, "hello_" + i);
Thread.sleep(1000);
Assert.assertEquals(0, messages.size());
connector.setPort(port);