|
5 | 5 | import java.util.Iterator;
|
6 | 6 | import java.util.List;
|
7 | 7 | import java.util.Set;
|
| 8 | +import java.util.concurrent.ArrayBlockingQueue; |
| 9 | +import java.util.concurrent.BlockingQueue; |
| 10 | +import java.util.concurrent.Callable; |
| 11 | +import java.util.concurrent.ExecutionException; |
| 12 | +import java.util.concurrent.Future; |
| 13 | +import java.util.concurrent.ThreadPoolExecutor; |
| 14 | +import java.util.concurrent.TimeUnit; |
8 | 15 |
|
9 | 16 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
10 | 17 | import org.junit.After;
|
@@ -335,6 +342,33 @@ public void testCloseable() {
|
335 | 342 | }
|
336 | 343 | }
|
337 | 344 |
|
| 345 | + @Test |
| 346 | + public void testJedisClusterRunsWithMultithreaded() throws InterruptedException, ExecutionException { |
| 347 | + Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>(); |
| 348 | + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); |
| 349 | + final JedisCluster jc = new JedisCluster(jedisClusterNode); |
| 350 | + jc.set("foo", "bar"); |
| 351 | + |
| 352 | + ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
| 353 | + List<Future<String>> futures = new ArrayList<Future<String>>(); |
| 354 | + for (int i = 0 ; i < 50 ; i++) { |
| 355 | + executor.submit(new Callable<String>() { |
| 356 | + @Override |
| 357 | + public String call() throws Exception { |
| 358 | + // FIXME : invalidate slot cache from JedisCluster to test random connection also does work |
| 359 | + return jc.get("foo"); |
| 360 | + } |
| 361 | + }); |
| 362 | + } |
| 363 | + |
| 364 | + for (Future<String> future : futures) { |
| 365 | + String value = future.get(); |
| 366 | + assertEquals("bar", value); |
| 367 | + } |
| 368 | + |
| 369 | + jc.close(); |
| 370 | + } |
| 371 | + |
338 | 372 | private static String getNodeServingSlotRange(String infoOutput) {
|
339 | 373 | // f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0 1394372400827 0 connected 5461-10922
|
340 | 374 | for (String infoLine : infoOutput.split("\n")) {
|
|
0 commit comments