final AtomicReference<ServerMessage> messageRef = new AtomicReference<>();
ListenUnlistenService s = new ListenUnlistenService(sessionRef, messageRef);
boolean processed = processor.process(s);
assertTrue(processed);
ServerChannel channel = bayeuxServer.getChannel("/foo");
assertNotNull(channel);
assertEquals(1, channel.getListeners().size());
// Fake a publish
LocalSession remote = bayeuxServer.newLocalSession("remote");
remote.handshake();
ServerMessage.Mutable message = bayeuxServer.newMessage();
message.setChannel(channel.getId());
bayeuxServer.handle((ServerSessionImpl)remote.getServerSession(), message);
assertNotNull(sessionRef.get());
assertSame(sessionRef.get(), remote.getServerSession());
assertNotNull(messageRef.get());
processed = processor.deprocessCallbacks(s);
assertTrue(processed);
// Fake another publish
sessionRef.set(null);
messageRef.set(null);
message = bayeuxServer.newMessage();
message.setChannel(channel.getId());
bayeuxServer.handle((ServerSessionImpl)remote.getServerSession(), message);
assertNull(sessionRef.get());
assertNull(messageRef.get());
// Be sure the channel is removed after few sweeps
for (int i = 0; i < 3; ++i)
bayeuxServer.sweep();
assertNull(bayeuxServer.getChannel(channel.getId()));
}