Source:
<code>public void testConcurrentPubSub() throws Exception { Jedis subscriber1 = new Jedis("localhost", ports[0]); Jedis subscriber2 = new Jedis("localhost", ports[1]); CountDownLatch latch = new CountDownLatch(2); MockSubscriber mockSubscriber1 = new MockSubscriber(latch); MockSubscriber mockSubscriber2 = new MockSubscriber(latch); Runnable runnable1 = () -> subscriber1.subscribe(mockSubscriber1, CHANNEL_NAME); Thread subscriberThread1 = new Thread(runnable1); subscriberThread1.start(); Runnable runnable2 = () -> subscriber2.subscribe(mockSubscriber2, CHANNEL_NAME); Thread subscriberThread2 = new Thread(runnable2); subscriberThread2.start(); assertThat(latch.await(2, TimeUnit.SECONDS)) .as("channel subscription was not received") .isTrue(); int CLIENT_COUNT = 10; int ITERATIONS = 1000; List<Jedis> clients = new ArrayList<>(); <START> List<Thread> threads = new ArrayList<>(); <END> for (int i = 0; i < CLIENT_COUNT; i++) { Jedis client = new Jedis("localhost", ports[i % 2]); clients.add(client); Runnable runnable = () -> { for (int j = 0; j < ITERATIONS; j++) { client.publish(CHANNEL_NAME, "hello"); } }; threads.add(new Thread(runnable)); } threads.forEach(Thread::start); for (Thread thread : threads) { thread.join(); } mockSubscriber1.unsubscribe(CHANNEL_NAME); mockSubscriber2.unsubscribe(CHANNEL_NAME); GeodeAwaitility.await().untilAsserted(subscriberThread1::join); GeodeAwaitility.await().untilAsserted(subscriberThread2::join); assertThat(mockSubscriber1.getReceivedMessages().size()).isEqualTo(CLIENT_COUNT * ITERATIONS); assertThat(mockSubscriber2.getReceivedMessages().size()).isEqualTo(CLIENT_COUNT * ITERATIONS); }</code><technical_language>ExecutorPool a specific list of Threads..</technical_language>

Target:
public void testConcurrentPubSub() throws Exception { int CLIENT_COUNT = 10; int ITERATIONS = 1000; Jedis subscriber1 = new Jedis("localhost", ports[0]); Jedis subscriber2 = new Jedis("localhost", ports[1]); CountDownLatch latch = new CountDownLatch(2); MockSubscriber mockSubscriber1 = new MockSubscriber(latch); MockSubscriber mockSubscriber2 = new MockSubscriber(latch); Future<Void> subscriber1Future = executor.submit( () -> subscriber1.subscribe(mockSubscriber1, CHANNEL_NAME)); Future<Void> subscriber2Future = executor.submit( () -> subscriber2.subscribe(mockSubscriber2, CHANNEL_NAME)); assertThat(latch.await(30, TimeUnit.SECONDS)) .as("channel subscription was not received") .isTrue(); List<Future<Void>> futures = new LinkedList<>(); for (int i = 0; i < CLIENT_COUNT; i++) { Jedis client = new Jedis("localhost", ports[i % 2]); Callable<Void> callable = () -> { for (int j = 0; j < ITERATIONS; j++) { client.publish(CHANNEL_NAME, "hello"); } return null; }; futures.add(executor.submit(callable)); } for (Future<Void> future : futures) { GeodeAwaitility.await().untilAsserted(future::get); } mockSubscriber1.unsubscribe(CHANNEL_NAME); mockSubscriber2.unsubscribe(CHANNEL_NAME); GeodeAwaitility.await().untilAsserted(subscriber1Future::get); GeodeAwaitility.await().untilAsserted(subscriber2Future::get); assertThat(mockSubscriber1.getReceivedMessages().size()).isEqualTo(CLIENT_COUNT * ITERATIONS); assertThat(mockSubscriber2.getReceivedMessages().size()).isEqualTo(CLIENT_COUNT * ITERATIONS); }