Search in sources :

Example 1 with PatternStatusListener

use of org.redisson.api.listener.PatternStatusListener in project redisson by redisson.

the class RedissonTopicPatternTest method testConcurrentTopic.

@Test
public void testConcurrentTopic() throws Exception {
    Config config = BaseTest.createConfig();
    RedissonClient redisson = Redisson.create(config);
    int threads = 30;
    int loops = 50000;
    ExecutorService executor = Executors.newFixedThreadPool(threads);
    List<Future<?>> futures = new ArrayList<>();
    for (int i = 0; i < threads; i++) {
        Runnable worker = new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < loops; j++) {
                    RPatternTopic<String> t = redisson.getPatternTopic("PUBSUB*");
                    int listenerId = t.addListener(new PatternStatusListener() {

                        @Override
                        public void onPUnsubscribe(String channel) {
                        }

                        @Override
                        public void onPSubscribe(String channel) {
                        }
                    });
                    redisson.getTopic("PUBSUB_" + j).publish("message");
                    t.removeListener(listenerId);
                }
            }
        };
        Future<?> s = executor.submit(worker);
        futures.add(s);
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(threads * loops * 1000, TimeUnit.SECONDS));
    for (Future<?> future : futures) {
        future.get();
    }
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) ArrayList(java.util.ArrayList) RedissonClient(org.redisson.api.RedissonClient) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) BasePatternStatusListener(org.redisson.api.listener.BasePatternStatusListener) PatternStatusListener(org.redisson.api.listener.PatternStatusListener) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Test (org.junit.Test)1 RedissonClient (org.redisson.api.RedissonClient)1 BasePatternStatusListener (org.redisson.api.listener.BasePatternStatusListener)1 PatternStatusListener (org.redisson.api.listener.PatternStatusListener)1 Config (org.redisson.config.Config)1