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();
}
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();
}
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);
}
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"));
}
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();
}
Aggregations