use of org.redisson.api.listener.BasePatternStatusListener in project redisson by redisson.
the class RedissonTopicPatternTest method test.
@Test
public void test() throws InterruptedException {
final CountDownLatch messageRecieved = new CountDownLatch(5);
final CountDownLatch statusRecieved = new CountDownLatch(1);
RedissonClient redisson1 = BaseTest.createInstance();
RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
topic1.addListener(new BasePatternStatusListener() {
@Override
public void onPSubscribe(String pattern) {
Assert.assertEquals("topic.*", pattern);
statusRecieved.countDown();
}
});
topic1.addListener((pattern, channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
RedissonClient redisson2 = BaseTest.createInstance();
RTopic<Message> topic2 = redisson2.getTopic("topic.t1");
topic2.addListener((channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
topic2.publish(new Message("123"));
topic2.publish(new Message("123"));
RTopic<Message> topicz = redisson2.getTopic("topicz.t1");
// this message doesn't get
topicz.publish(new Message("789"));
// delivered, and would fail the
// assertion
RTopic<Message> topict2 = redisson2.getTopic("topic.t2");
topict2.publish(new Message("123"));
statusRecieved.await();
Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS));
redisson1.shutdown();
redisson2.shutdown();
}
use of org.redisson.api.listener.BasePatternStatusListener in project redisson by redisson.
the class RedissonTopicPatternTest method testListenerRemove.
@Test
public void testListenerRemove() throws InterruptedException {
RedissonClient redisson1 = BaseTest.createInstance();
RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
final CountDownLatch l = new CountDownLatch(1);
topic1.addListener(new BasePatternStatusListener() {
@Override
public void onPUnsubscribe(String pattern) {
Assert.assertEquals("topic.*", pattern);
l.countDown();
}
});
int id = topic1.addListener((pattern, channel, msg) -> {
Assert.fail();
});
RedissonClient redisson2 = BaseTest.createInstance();
RTopic<Message> topic2 = redisson2.getTopic("topic.t1");
topic1.removeListener(id);
topic2.publish(new Message("123"));
redisson1.shutdown();
redisson2.shutdown();
}
Aggregations