コード例 #1
0
ファイル: JedisClusterTest.java プロジェクト: TruSphere/jedis
  @Test
  public void testJedisClusterRunsWithMultithreaded()
      throws InterruptedException, ExecutionException, IOException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    final JedisCluster jc = new JedisCluster(jedisClusterNode);
    jc.set("foo", "bar");

    ThreadPoolExecutor executor =
        new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
    List<Future<String>> futures = new ArrayList<Future<String>>();
    for (int i = 0; i < 50; i++) {
      executor.submit(
          new Callable<String>() {
            @Override
            public String call() throws Exception {
              // FIXME : invalidate slot cache from JedisCluster to test
              // random connection also does work
              return jc.get("foo");
            }
          });
    }

    for (Future<String> future : futures) {
      String value = future.get();
      assertEquals("bar", value);
    }

    jc.close();
  }