use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testCommandsOrdering.
@Test
public void testCommandsOrdering() throws InterruptedException {
RedissonClient redisson1 = BaseTest.createInstance();
RTopic<Long> topic1 = redisson1.getTopic("topic", LongCodec.INSTANCE);
AtomicBoolean stringMessageReceived = new AtomicBoolean();
topic1.addListener((channel, msg) -> {
assertThat(msg).isEqualTo(123);
stringMessageReceived.set(true);
});
topic1.publish(123L);
Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(stringMessageReceived);
redisson1.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testSyncCommands.
@Test
public void testSyncCommands() throws InterruptedException {
RedissonClient redisson = BaseTest.createInstance();
RTopic<String> topic = redisson.getTopic("system_bus");
RSet<String> redissonSet = redisson.getSet("set1");
CountDownLatch latch = new CountDownLatch(1);
topic.addListener((channel, msg) -> {
for (int j = 0; j < 1000; j++) {
System.out.println("start: " + j);
redissonSet.contains("" + j);
System.out.println("end: " + j);
}
latch.countDown();
});
topic.publish("sometext");
latch.await();
redisson.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testRemoveAllListeners.
@Test
public void testRemoveAllListeners() throws InterruptedException {
RedissonClient redisson = BaseTest.createInstance();
RTopic<Message> topic1 = redisson.getTopic("topic1");
for (int i = 0; i < 10; i++) {
topic1.addListener((channel, msg) -> {
Assert.fail();
});
}
topic1 = redisson.getTopic("topic1");
topic1.removeAllListeners();
topic1.publish(new Message("123"));
redisson.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testReattach.
@Test
public void testReattach() throws InterruptedException, IOException, ExecutionException, TimeoutException {
RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
final AtomicBoolean executed = new AtomicBoolean();
RTopic<Integer> topic = redisson.getTopic("topic");
topic.addListener(new MessageListener<Integer>() {
@Override
public void onMessage(String channel, Integer msg) {
if (msg == 1) {
executed.set(true);
}
}
});
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
Thread.sleep(1000);
redisson.getTopic("topic").publish(1);
await().atMost(5, TimeUnit.SECONDS).untilTrue(executed);
redisson.shutdown();
runner.stop();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonTopicTest method testLazyUnsubscribe.
@Test
public void testLazyUnsubscribe() throws InterruptedException {
final CountDownLatch messageRecieved = new CountDownLatch(1);
RedissonClient redisson1 = BaseTest.createInstance();
RTopic<Message> topic1 = redisson1.getTopic("topic");
int listenerId = topic1.addListener((channel, msg) -> {
Assert.fail();
});
Thread.sleep(1000);
topic1.removeListener(listenerId);
Thread.sleep(1000);
RedissonClient redisson2 = BaseTest.createInstance();
RTopic<Message> topic2 = redisson2.getTopic("topic");
topic2.addListener((channel, msg) -> {
Assert.assertEquals(new Message("123"), msg);
messageRecieved.countDown();
});
topic2.publish(new Message("123"));
Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS));
redisson1.shutdown();
redisson2.shutdown();
}
Aggregations