コード例 #1
0
ファイル: RedissonTest.java プロジェクト: forndb/redisson
  @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());
  }
コード例 #2
0
ファイル: RedissonTest.java プロジェクト: forndb/redisson
  @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();
  }
コード例 #3
0
  @Test
  public void testSingleCountDownAwait_SingleInstance() throws InterruptedException {
    final int iterations = Runtime.getRuntime().availableProcessors() * 3;

    RedissonClient redisson = BaseTest.createInstance();
    final RCountDownLatch latch = redisson.getCountDownLatch("latch");
    latch.trySetCount(iterations);

    final AtomicInteger counter = new AtomicInteger();
    ExecutorService executor = Executors.newScheduledThreadPool(iterations);
    for (int i = 0; i < iterations; i++) {
      executor.execute(
          () -> {
            try {
              latch.await();
              Assert.assertEquals(0, latch.getCount());
              Assert.assertEquals(iterations, counter.get());
            } catch (InterruptedException e) {
              Assert.fail();
            }
          });
    }

    ExecutorService countDownExecutor = Executors.newFixedThreadPool(iterations);
    for (int i = 0; i < iterations; i++) {
      countDownExecutor.execute(
          () -> {
            latch.countDown();
            counter.incrementAndGet();
          });
    }

    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));

    redisson.shutdown();
  }