Skip to content

Commit 6707327

Browse files
authored
Use ExecutorService.shutdownNow() in tests (#3922)
* Use ExecutorService.shutdownNow() * More ExecutorService.shutdownNow() and other changes
1 parent 9bddabd commit 6707327

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

Diff for: src/test/java/redis/clients/jedis/csc/ClientSideCacheFunctionalityTest.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ public void testSequentialAccess() throws InterruptedException {
331331
latch.await();
332332
}
333333

334+
executorService.shutdownNow();
335+
334336
// Verify the final value of "foo" in Redis
335337
String finalValue = control.get("foo");
336338
assertEquals(threadCount * iterations, Integer.parseInt(finalValue));
@@ -368,6 +370,8 @@ public void testConcurrentAccessWithStats() throws InterruptedException {
368370
latch.await();
369371
}
370372

373+
executorService.shutdownNow();
374+
371375
CacheStats stats = testCache.getStats();
372376
assertEquals(threadCount * iterations, stats.getMissCount() + stats.getHitCount());
373377
assertEquals(stats.getMissCount(), stats.getLoadCount());
@@ -385,26 +389,28 @@ public void testMaxSize() throws InterruptedException {
385389
// Create the shared mock instance of cache
386390
TestCache testCache = new TestCache(maxSize, map, DefaultCacheable.INSTANCE);
387391

388-
// Submit multiple threads to perform concurrent operations
389-
CountDownLatch latch = new CountDownLatch(threadCount);
390-
for (int i = 0; i < threadCount; i++) {
391-
executorService.submit(() -> {
392-
try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), testCache)) {
393-
for (int j = 0; j < iterations; j++) {
394-
// Simulate continious get and update operations and consume invalidation events meanwhile
395-
assertEquals("OK", jedis.set("foo" + j, "foo" + j));
396-
jedis.get("foo" + j);
392+
try (JedisPooled jedis = new JedisPooled(endpoint.getHostAndPort(), clientConfig.get(), testCache)) {
393+
// Submit multiple threads to perform concurrent operations
394+
CountDownLatch latch = new CountDownLatch(threadCount);
395+
for (int i = 0; i < threadCount; i++) {
396+
executorService.submit(() -> {
397+
try {
398+
for (int j = 0; j < iterations; j++) {
399+
// Simulate continious get and update operations and consume invalidation events meanwhile
400+
assertEquals("OK", jedis.set("foo" + j, "foo" + j));
401+
jedis.get("foo" + j);
402+
}
403+
} finally {
404+
latch.countDown();
397405
}
398-
} catch (Exception e) {
399-
e.printStackTrace();
400-
} finally {
401-
latch.countDown();
402-
}
403-
});
406+
});
407+
}
408+
409+
// wait for all threads to complete
410+
latch.await();
404411
}
405412

406-
// wait for all threads to complete
407-
latch.await();
413+
executorService.shutdownNow();
408414

409415
CacheStats stats = testCache.getStats();
410416

0 commit comments

Comments
 (0)