From c147fe569169dc8ec2b45b8399d547d21c3e450a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 6 Jan 2016 20:00:11 -0500 Subject: [PATCH] Do not lose CacheTest failure stack traces --- .../common/cache/CacheTests.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java b/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java index a397b75a6aa..921c66f7acb 100644 --- a/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java +++ b/core/src/test/java/org/elasticsearch/common/cache/CacheTests.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutionException; @@ -44,6 +45,8 @@ import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; public class CacheTests extends ESTestCase { private int numberOfEntries; @@ -485,7 +488,7 @@ public class CacheTests extends ESTestCase { return value; }); } catch (ExecutionException e) { - fail(e.getMessage()); + throw new AssertionError(e); } } for (int i = 0; i < numberOfEntries; i++) { @@ -501,6 +504,8 @@ public class CacheTests extends ESTestCase { flags.set(j, false); } + CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); + CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads); for (int i = 0; i < numberOfThreads; i++) { Thread thread = new Thread(() -> { @@ -513,7 +518,8 @@ public class CacheTests extends ESTestCase { return Integer.toString(key); }); } catch (ExecutionException e) { - fail(e.getMessage()); + failures.add(e); + break; } } barrier.await(); @@ -528,6 +534,8 @@ public class CacheTests extends ESTestCase { barrier.await(); // wait for all threads to finish barrier.await(); + + assertThat(failures, is(empty())); } public void testComputeIfAbsentThrowsExceptionIfLoaderReturnsANullValue() { @@ -568,6 +576,8 @@ public class CacheTests extends ESTestCase { int numberOfThreads = randomIntBetween(2, 32); final Cache cache = CacheBuilder.builder().build(); + CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); + CyclicBarrier barrier = new CyclicBarrier(1 + numberOfThreads); CountDownLatch deadlockLatch = new CountDownLatch(numberOfThreads); List threads = new ArrayList<>(); @@ -592,7 +602,8 @@ public class CacheTests extends ESTestCase { } }); } catch (ExecutionException e) { - fail(e.getMessage()); + failures.add(e); + break; } } } finally { @@ -637,6 +648,8 @@ public class CacheTests extends ESTestCase { // shutdown the watchdog service scheduler.shutdown(); + assertThat(failures, is(empty())); + assertFalse("deadlock", deadlock.get()); }