Search in sources :

Example 41 with RedissonClient

use of org.redisson.api.RedissonClient in project redisson by redisson.

the class RedissonTest method testManyConnections.

@Test
public void testManyConnections() {
    Assume.assumeFalse(RedissonRuntimeEnvironment.isTravis);
    Config redisConfig = new Config();
    redisConfig.useSingleServer().setConnectionMinimumIdleSize(10000).setConnectionPoolSize(10000).setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedissonClient r = Redisson.create(redisConfig);
    r.shutdown();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 42 with RedissonClient

use of org.redisson.api.RedissonClient in project redisson by redisson.

the class RedissonTest method testSingleConfigJSON.

@Test
public void testSingleConfigJSON() throws IOException {
    RedissonClient r = BaseTest.createInstance();
    String t = r.getConfig().toJSON();
    Config c = Config.fromJSON(t);
    assertThat(c.toJSON()).isEqualTo(t);
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 43 with RedissonClient

use of org.redisson.api.RedissonClient 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();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) BasePatternStatusListener(org.redisson.api.listener.BasePatternStatusListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 44 with RedissonClient

use of org.redisson.api.RedissonClient in project redisson by redisson.

the class RedissonTopicPatternTest method testLazyUnsubscribe.

@Test
public void testLazyUnsubscribe() throws InterruptedException {
    final CountDownLatch messageRecieved = new CountDownLatch(1);
    RedissonClient redisson1 = BaseTest.createInstance();
    RPatternTopic<Message> topic1 = redisson1.getPatternTopic("topic.*");
    int listenerId = topic1.addListener((pattern, channel, msg) -> {
        Assert.fail();
    });
    Thread.sleep(1000);
    topic1.removeListener(listenerId);
    Thread.sleep(1000);
    RedissonClient redisson2 = BaseTest.createInstance();
    RPatternTopic<Message> topic2 = redisson2.getPatternTopic("topic.*");
    topic2.addListener((pattern, channel, msg) -> {
        Assert.assertEquals("topic.*", pattern);
        Assert.assertEquals("topic.t1", channel);
        Assert.assertEquals(new Message("123"), msg);
        messageRecieved.countDown();
    });
    RTopic<Message> topic3 = redisson2.getTopic("topic.t1");
    topic3.publish(new Message("123"));
    messageRecieved.await();
    redisson1.shutdown();
    redisson2.shutdown();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 45 with RedissonClient

use of org.redisson.api.RedissonClient 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

RedissonClient (org.redisson.api.RedissonClient)95 Test (org.junit.Test)87 Config (org.redisson.config.Config)44 RedisProcess (org.redisson.RedisRunner.RedisProcess)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 CountDownLatch (java.util.concurrent.CountDownLatch)15 ExecutorService (java.util.concurrent.ExecutorService)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 RLock (org.redisson.api.RLock)10 IOException (java.io.IOException)9 ExecutionException (java.util.concurrent.ExecutionException)9 NotSerializableException (java.io.NotSerializableException)8 RemoteServiceAckTimeoutException (org.redisson.remote.RemoteServiceAckTimeoutException)8 RemoteServiceTimeoutException (org.redisson.remote.RemoteServiceTimeoutException)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 RemoteInvocationOptions (org.redisson.api.RemoteInvocationOptions)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 BasePatternStatusListener (org.redisson.api.listener.BasePatternStatusListener)3 SerializationCodec (org.redisson.codec.SerializationCodec)3