@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(); }
@Test public void testCloseable() throws IOException { Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>(); jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort())); JedisCluster jc = null; try { jc = new JedisCluster(jedisClusterNode); jc.set("51", "foo"); } finally { if (jc != null) { jc.close(); } } Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator(); while (poolIterator.hasNext()) { JedisPool pool = poolIterator.next(); try { pool.getResource(); fail("JedisCluster's internal pools should be already destroyed"); } catch (JedisConnectionException e) { // ok to go... } } }