Search in sources :

Example 36 with RedissonClient

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

the class RedissonTest method testShutdown.

@Test
public void testShutdown() {
    Config config = new Config();
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedissonClient r = Redisson.create(config);
    Assert.assertFalse(r.isShuttingDown());
    Assert.assertFalse(r.isShutdown());
    r.shutdown();
    Assert.assertTrue(r.isShuttingDown());
    Assert.assertTrue(r.isShutdown());
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 37 with RedissonClient

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

the class RedissonTest method testSingleConfigYAML.

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

Example 38 with RedissonClient

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

the class RedissonTest method testMemoryCommand.

@Test(expected = RedisOutOfMemoryException.class)
public void testMemoryCommand() throws IOException, InterruptedException {
    RedisProcess p = redisTestSmallMemory();
    Config config = new Config();
    config.useSingleServer().setAddress(p.getRedisServerAddressAndPort()).setTimeout(100000);
    RedissonClient r = null;
    try {
        r = Redisson.create(config);
        r.getKeys().flushall();
        for (int i = 0; i < 10000; i++) {
            r.getMap("test").fastPut("" + i, "" + i);
        }
    } finally {
        r.shutdown();
        p.stop();
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 39 with RedissonClient

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

the class RedissonTest method testMemoryScript.

@Test(expected = RedisOutOfMemoryException.class)
public void testMemoryScript() throws IOException, InterruptedException {
    RedisProcess p = redisTestSmallMemory();
    Config config = new Config();
    config.useSingleServer().setAddress(p.getRedisServerAddressAndPort()).setTimeout(100000);
    RedissonClient r = null;
    try {
        r = Redisson.create(config);
        r.getKeys().flushall();
        for (int i = 0; i < 10000; i++) {
            r.getMap("test").put("" + i, "" + i);
        }
    } finally {
        r.shutdown();
        p.stop();
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 40 with RedissonClient

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

the class RedissonTest method testSmallPool.

@Test
public void testSmallPool() throws InterruptedException {
    Config config = new Config();
    config.useSingleServer().setConnectionMinimumIdleSize(3).setConnectionPoolSize(3).setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedissonClient localRedisson = Redisson.create(config);
    RMap<String, String> map = localRedisson.getMap("test");
    ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    long start = System.currentTimeMillis();
    int iterations = 500_000;
    for (int i = 0; i < iterations; i++) {
        final int j = i;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                map.put("" + j, "" + j);
            }
        });
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(10, TimeUnit.MINUTES));
    assertThat(map.size()).isEqualTo(iterations);
    localRedisson.shutdown();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) ExecutorService(java.util.concurrent.ExecutorService) 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