예제 #1
0
  //    @Test
  public void testMultiThreads() throws IOException, InterruptedException {
    RedisProcess redis1 = redisTestMultilockInstance(6320);

    Config config1 = new Config();
    config1.useSingleServer().setAddress("127.0.0.1:6320");
    RedissonClient client = Redisson.create(config1);

    RLock lock1 = client.getLock("lock1");
    RLock lock2 = client.getLock("lock2");
    RLock lock3 = client.getLock("lock3");

    Thread t =
        new Thread() {
          public void run() {
            RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3);
            lock.lock();

            try {
              Thread.sleep(3000);
            } catch (InterruptedException e) {
            }

            lock.unlock();
          };
        };
    t.start();
    t.join(1000);

    RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3);
    lock.lock();
    lock.unlock();

    assertThat(redis1.stop()).isEqualTo(0);
  }
예제 #2
0
 @Test(expected = WriteRedisConnectionException.class)
 public void testSer() {
   Config config = new Config();
   config.useSingleServer().setAddress("127.0.0.1:6379");
   config.setCodec(new SerializationCodec());
   RedissonClient r = Redisson.create(config);
   r.getMap("test").put("1", new Dummy());
 }
예제 #3
0
 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;
 }
예제 #4
0
  @Test
  public void testShutdown() {
    Config config = new Config();
    config.useSingleServer().setAddress("127.0.0.1:6379");

    RedissonClient r = Redisson.create(config);
    Assert.assertFalse(r.isShuttingDown());
    Assert.assertFalse(r.isShutdown());
    r.shutdown();
    Assert.assertTrue(r.isShuttingDown());
    Assert.assertTrue(r.isShutdown());
  }
예제 #5
0
  @Test
  public void testConnectionListener() throws IOException, InterruptedException, TimeoutException {

    Process p = runRedis();

    final Waiter onConnectWaiter = new Waiter();
    final Waiter onDisconnectWaiter = new Waiter();

    Config config = new Config();
    config.useSingleServer().setAddress("127.0.0.1:6319").setFailedAttempts(1).setRetryAttempts(1);
    config.setConnectionListener(
        new ConnectionListener() {

          @Override
          public void onDisconnect(InetSocketAddress addr) {
            onDisconnectWaiter.assertEquals(new InetSocketAddress("127.0.0.1", 6319), addr);
            onDisconnectWaiter.resume();
          }

          @Override
          public void onConnect(InetSocketAddress addr) {
            onConnectWaiter.assertEquals(new InetSocketAddress("127.0.0.1", 6319), addr);
            onConnectWaiter.resume();
          }
        });

    RedissonClient r = Redisson.create(config);
    r.getBucket("1").get();

    p.destroy();
    Assert.assertEquals(1, p.waitFor());

    try {
      r.getBucket("1").get();
    } catch (Exception e) {
    }

    p = runRedis();

    r.getBucket("1").get();

    r.shutdown();

    p.destroy();
    Assert.assertEquals(1, p.waitFor());

    onConnectWaiter.await(1, TimeUnit.SECONDS, 2);
    onDisconnectWaiter.await();
  }