use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonCodecTest method testJson.
@Test
public void testJson() {
Config config = createConfig();
config.setCodec(jsonCodec);
RedissonClient redisson = Redisson.create(config);
test(redisson);
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonCodecTest method testCbor.
@Test
public void testCbor() {
Config config = createConfig();
config.setCodec(cborCodec);
RedissonClient redisson = Redisson.create(config);
test(redisson);
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonMapTest method testStringCodec.
@Test
public void testStringCodec() {
Config config = createConfig();
config.setCodec(StringCodec.INSTANCE);
RedissonClient redisson = Redisson.create(config);
RMap<String, String> rmap = redisson.getMap("TestRMap01");
rmap.put("A", "1");
rmap.put("B", "2");
Iterator<Map.Entry<String, String>> iterator = rmap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> next = iterator.next();
assertThat(next).isIn(new AbstractMap.SimpleEntry("A", "1"), new AbstractMap.SimpleEntry("B", "2"));
}
redisson.shutdown();
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonMultiLockTest method createClient.
private RedissonClient createClient(NioEventLoopGroup group, String host) {
Config config1 = new Config();
config1.useSingleServer().setAddress(host);
config1.setEventLoopGroup(group);
RedissonClient client1 = Redisson.create(config1);
client1.getKeys().flushdb();
return client1;
}
use of org.redisson.api.RedissonClient in project redisson by redisson.
the class RedissonMultiLockTest method test.
@Test
public void test() throws IOException, InterruptedException {
RedisProcess redis1 = redisTestMultilockInstance();
RedisProcess redis2 = redisTestMultilockInstance();
RedisProcess redis3 = redisTestMultilockInstance();
NioEventLoopGroup group = new NioEventLoopGroup();
RedissonClient client1 = createClient(group, redis1.getRedisServerAddressAndPort());
RedissonClient client2 = createClient(group, redis2.getRedisServerAddressAndPort());
RedissonClient client3 = createClient(group, redis3.getRedisServerAddressAndPort());
final RLock lock1 = client1.getLock("lock1");
final RLock lock2 = client2.getLock("lock2");
final RLock lock3 = client3.getLock("lock3");
RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3);
lock.lock();
final AtomicBoolean executed = new AtomicBoolean();
Thread t = new Thread() {
@Override
public void run() {
RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3);
assertThat(lock.tryLock()).isFalse();
assertThat(lock.tryLock()).isFalse();
executed.set(true);
}
};
t.start();
t.join();
await().atMost(5, TimeUnit.SECONDS).until(() -> assertThat(executed.get()).isTrue());
lock.unlock();
client1.shutdown();
client2.shutdown();
client3.shutdown();
assertThat(redis1.stop()).isEqualTo(0);
assertThat(redis2.stop()).isEqualTo(0);
assertThat(redis3.stop()).isEqualTo(0);
}
Aggregations