Search in sources :

Example 81 with RedissonClient

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

the class RedissonBoundedBlockingQueueTest method testPollAsyncReattach.

@Test
public void testPollAsyncReattach() 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);
    RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("queue:pollany");
    RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
    f.await(1, TimeUnit.SECONDS);
    runner.stop();
    runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
    assertThat(queue1.trySetCapacity(15)).isTrue();
    queue1.put(123);
    // check connection rotation
    for (int i = 0; i < 10; i++) {
        queue1.put(i);
    }
    assertThat(queue1.size()).isEqualTo(10);
    Integer result = f.get(1, TimeUnit.SECONDS);
    assertThat(result).isEqualTo(123);
    redisson.shutdown();
    runner.stop();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RedissonClient(org.redisson.api.RedissonClient) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 82 with RedissonClient

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

the class RedissonBoundedBlockingQueueTest method testTakeAsyncCancel.

@Test
public void testTakeAsyncCancel() {
    Config config = createConfig();
    config.useSingleServer().setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);
    RedissonClient redisson = Redisson.create(config);
    redisson.getKeys().flushall();
    RBoundedBlockingQueue<Integer> queue1 = redisson.getBoundedBlockingQueue("testTakeAsyncCancel");
    assertThat(queue1.trySetCapacity(15)).isTrue();
    for (int i = 0; i < 10; i++) {
        RFuture<Integer> f = queue1.takeAsync();
        f.cancel(true);
    }
    assertThat(queue1.add(1)).isTrue();
    assertThat(queue1.add(2)).isTrue();
    assertThat(queue1.size()).isEqualTo(2);
    redisson.shutdown();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 83 with RedissonClient

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

the class RedissonCodecTest method testMsgPack.

@Test
public void testMsgPack() {
    Config config = createConfig();
    config.setCodec(msgPackCodec);
    RedissonClient redisson = Redisson.create(config);
    test(redisson);
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 84 with RedissonClient

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

the class RedissonCodecTest method testAvro.

@Test
public void testAvro() throws IOException {
    AvroMapper am = new AvroMapper();
    AvroSchema schema = am.schemaFor(TestObject.class);
    Codec avroCodec = new AvroJacksonCodec(TestObject.class, schema);
    Config config = createConfig();
    config.setCodec(avroCodec);
    RedissonClient redisson = Redisson.create(config);
    RBucket<TestObject> b = redisson.getBucket("bucket");
    b.set(new TestObject("1", "2"));
    assertThat(b.get()).isEqualTo(new TestObject("1", "2"));
}
Also used : Codec(org.redisson.client.codec.Codec) JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) KryoCodec(org.redisson.codec.KryoCodec) MsgPackJacksonCodec(org.redisson.codec.MsgPackJacksonCodec) SnappyCodec(org.redisson.codec.SnappyCodec) JsonJacksonMapValueCodec(org.redisson.client.codec.JsonJacksonMapValueCodec) SerializationCodec(org.redisson.codec.SerializationCodec) LZ4Codec(org.redisson.codec.LZ4Codec) SmileJacksonCodec(org.redisson.codec.SmileJacksonCodec) CborJacksonCodec(org.redisson.codec.CborJacksonCodec) FstCodec(org.redisson.codec.FstCodec) AvroJacksonCodec(org.redisson.codec.AvroJacksonCodec) AvroSchema(com.fasterxml.jackson.dataformat.avro.AvroSchema) AvroJacksonCodec(org.redisson.codec.AvroJacksonCodec) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) AvroMapper(com.fasterxml.jackson.dataformat.avro.AvroMapper) Test(org.junit.Test)

Example 85 with RedissonClient

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

the class RedissonCodecTest method testListOfStrings.

@Test
public void testListOfStrings() {
    Config config = createConfig();
    config.setCodec(new JsonJacksonCodec());
    RedissonClient redisson = Redisson.create(config);
    RMap<String, List<String>> map = redisson.getMap("list of strings", jsonListOfStringCodec);
    map.put("foo", new ArrayList<String>(Arrays.asList("bar")));
    RMap<String, List<String>> map2 = redisson.getMap("list of strings", jsonListOfStringCodec);
    assertThat(map2).isEqualTo(map);
    redisson.shutdown();
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) ArrayList(java.util.ArrayList) List(java.util.List) 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