@Test public void testResubscribeOnRehandshake() throws Exception { AtomicReference<CountDownLatch> messageLatch = new AtomicReference<CountDownLatch>(); ResubscribeOnRehandshakeService s = new ResubscribeOnRehandshakeService(messageLatch); boolean processed = processor.process(s); assertTrue(processed); final CountDownLatch subscribeLatch = new CountDownLatch(1); bayeuxClient .getChannel(Channel.META_SUBSCRIBE) .addListener( new ClientSessionChannel.MessageListener() { public void onMessage(ClientSessionChannel channel, Message message) { subscribeLatch.countDown(); } }); bayeuxClient.handshake(); assertTrue(bayeuxClient.waitFor(1000, BayeuxClient.State.CONNECTED)); assertTrue(subscribeLatch.await(5, TimeUnit.SECONDS)); messageLatch.set(new CountDownLatch(1)); bayeuxClient.getChannel("/foo").publish(new HashMap()); assertTrue(messageLatch.get().await(5, TimeUnit.SECONDS)); bayeuxClient.disconnect(); assertTrue(bayeuxClient.waitFor(1000, BayeuxClient.State.DISCONNECTED)); // Rehandshake bayeuxClient.handshake(); assertTrue(bayeuxClient.waitFor(1000, BayeuxClient.State.CONNECTED)); // Republish, it must have resubscribed messageLatch.set(new CountDownLatch(1)); bayeuxClient.getChannel("/foo").publish(new HashMap()); assertTrue(messageLatch.get().await(5, TimeUnit.SECONDS)); bayeuxClient.disconnect(); assertTrue(bayeuxClient.waitFor(1000, BayeuxClient.State.DISCONNECTED)); boolean deprocessed = processor.deprocess(s); assertTrue(deprocessed); // Rehandshake bayeuxClient.handshake(); assertTrue(bayeuxClient.waitFor(1000, BayeuxClient.State.CONNECTED)); // Republish, it must not have resubscribed messageLatch.set(new CountDownLatch(1)); bayeuxClient.getChannel("/foo").publish(new HashMap()); assertFalse(messageLatch.get().await(1, TimeUnit.SECONDS)); }
@Test public void testUsage() throws Exception { final CountDownLatch connectLatch = new CountDownLatch(1); final AtomicReference<CountDownLatch> messageLatch = new AtomicReference<>(); UsageService s = new UsageService(connectLatch, messageLatch); processor.process(s); assertTrue(s.initialized); assertFalse(s.connected); final CountDownLatch subscribeLatch = new CountDownLatch(1); bayeuxClient .getChannel(Channel.META_SUBSCRIBE) .addListener( new ClientSessionChannel.MessageListener() { public void onMessage(ClientSessionChannel channel, Message message) { subscribeLatch.countDown(); } }); bayeuxClient.handshake(); assertTrue(connectLatch.await(5, TimeUnit.SECONDS)); assertTrue(s.connected); assertTrue(subscribeLatch.await(5, TimeUnit.SECONDS)); messageLatch.set(new CountDownLatch(1)); bayeuxClient.getChannel("/foo").publish(new HashMap<>()); assertTrue(messageLatch.get().await(5, TimeUnit.SECONDS)); processor.deprocess(s); assertFalse(s.initialized); messageLatch.set(new CountDownLatch(1)); bayeuxClient.getChannel("/foo").publish(new HashMap<>()); assertFalse(messageLatch.get().await(1, TimeUnit.SECONDS)); }