use of org.redisson.RedisRunner.KEYSPACE_EVENTS_OPTIONS in project redisson by redisson.
the class RedissonTopicTest method testReattachPatternTopicListenersOnClusterFailover.
@Test
public void testReattachPatternTopicListenersOnClusterFailover() throws Exception {
final KEYSPACE_EVENTS_OPTIONS[] keyspaceEvents = { KEYSPACE_EVENTS_OPTIONS.K, KEYSPACE_EVENTS_OPTIONS.E, KEYSPACE_EVENTS_OPTIONS.A };
final RedisRunner master = new RedisRunner().randomPort().randomDir().nosave().notifyKeyspaceEvents(keyspaceEvents);
final RedisRunner slave = new RedisRunner().randomPort().randomDir().nosave().notifyKeyspaceEvents(keyspaceEvents);
final ClusterRunner clusterRunner = new ClusterRunner().addNode(master, slave);
final ClusterProcesses process = clusterRunner.run();
final Config config = new Config();
config.useClusterServers().addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
final RedissonClient redisson = Redisson.create(config);
final AtomicInteger subscriptions = new AtomicInteger();
final AtomicInteger messagesReceived = new AtomicInteger();
final RPatternTopic topic = redisson.getPatternTopic("__keyspace*__:i*", StringCodec.INSTANCE);
topic.addListener(new PatternStatusListener() {
@Override
public void onPUnsubscribe(String pattern) {
}
@Override
public void onPSubscribe(String pattern) {
subscriptions.incrementAndGet();
}
});
topic.addListener(String.class, (pattern, channel, msg) -> messagesReceived.incrementAndGet());
assertThat(subscriptions.get()).isEqualTo(1);
sendCommands(redisson, "dummy").join();
await().atMost(30, TimeUnit.SECONDS).until(() -> messagesReceived.get() == 100);
failover(process, master, slave);
redisson.getBucket("i100").set("");
await().atMost(30, TimeUnit.SECONDS).until(() -> subscriptions.get() == 2);
await().atMost(5, TimeUnit.SECONDS).until(() -> messagesReceived.get() == 101);
redisson.shutdown();
process.shutdown();
}
Aggregations