Keep track of the exceptions instead of just flagging that an exception has occured.

This commit is contained in:
Martijn van Groningen 2014-03-12 16:27:57 +07:00
parent c841aa296a
commit d05b4ef769
1 changed files with 15 additions and 9 deletions

View File

@ -83,7 +83,7 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
final CountDownLatch start = new CountDownLatch(1);
final AtomicBoolean stop = new AtomicBoolean(false);
final AtomicInteger counts = new AtomicInteger(0);
final AtomicBoolean assertionFailure = new AtomicBoolean(false);
final AtomicReference<Throwable> exceptionHolder = new AtomicReference<Throwable>();
Thread[] threads = new Thread[5];
for (int i = 0; i < threads.length; i++) {
@ -118,11 +118,10 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
assertThat(convertFromTextArray(percolate.getMatches(), "index"), arrayContaining("test2"));
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (AssertionError e) {
assertionFailure.set(true);
} catch (Throwable e) {
exceptionHolder.set(e);
Thread.currentThread().interrupt();
}
}
@ -136,7 +135,11 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
thread.join();
}
assertThat(assertionFailure.get(), equalTo(false));
Throwable assertionError = exceptionHolder.get();
if (assertionError != null) {
assertionError.printStackTrace();
}
assertThat(assertionError + " should be null", assertionError, nullValue());
}
@Test
@ -147,7 +150,7 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
final int numPercolateThreads = 6;
final int numPercolatorOperationsPerThread = 1000;
final AtomicBoolean assertionFailure = new AtomicBoolean(false);
final Set<Throwable> exceptionsHolder = ConcurrentCollections.newConcurrentSet();
final CountDownLatch start = new CountDownLatch(1);
final AtomicInteger runningPercolateThreads = new AtomicInteger(numPercolateThreads);
final AtomicInteger type1 = new AtomicInteger();
@ -202,7 +205,7 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
assertThat(response.getVersion(), equalTo(1l));
}
} catch (Throwable t) {
assertionFailure.set(true);
exceptionsHolder.add(t);
logger.error("Error in indexing thread...", t);
}
}
@ -261,7 +264,7 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
}
}
} catch (Throwable t) {
assertionFailure.set(true);
exceptionsHolder.add(t);
logger.error("Error in percolate thread...", t);
} finally {
runningPercolateThreads.decrementAndGet();
@ -280,7 +283,10 @@ public class ConcurrentPercolatorTests extends ElasticsearchIntegrationTest {
thread.join();
}
assertThat(assertionFailure.get(), equalTo(false));
for (Throwable t : exceptionsHolder) {
logger.error("Unexpected exception {}", t.getMessage(), t);
}
assertThat(exceptionsHolder.isEmpty(), equalTo(true));
}
@Test