aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-05-26 19:56:24 +0000
committerGravatar Yue Gan <yueg@google.com>2016-05-27 08:45:27 +0000
commit3724d92fb85e021b6b65c3edb77c61572baedc25 (patch)
tree7f6c2f47b84e01d603d73c8d46c0265ade4be65e /src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java
parenta4bfb3c49f164d47322b39c560a716b89788002b (diff)
Allow AQV users to inject arbitrary handling of classified errors.
-- MOS_MIGRATED_REVID=123347295
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java b/src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java
index 64fc9f3c7c..7c751fce36 100644
--- a/src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitorTest.java
@@ -347,8 +347,20 @@ public class AbstractQueueVisitorTest {
ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 3, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
- final AbstractQueueVisitor visitor =
- createQueueVisitorWithErrorClassification(executor, ErrorClassification.CRITICAL);
+ final AtomicBoolean throwableSeen = new AtomicBoolean(false);
+ ErrorHandler errorHandler = new ErrorHandler() {
+ @Override
+ public void handle(Throwable t, ErrorClassification classification) {
+ if (t == THROWABLE) {
+ assertThat(classification).isEqualTo(ErrorClassification.CRITICAL);
+ throwableSeen.compareAndSet(false, true);
+ } else {
+ fail();
+ }
+ }
+ };
+ final AbstractQueueVisitor visitor = createQueueVisitorWithConstantErrorClassification(
+ executor, ErrorClassification.CRITICAL, errorHandler);
final CountDownLatch latch1 = new CountDownLatch(1);
final AtomicBoolean wasInterrupted = new AtomicBoolean(false);
@@ -381,18 +393,31 @@ public class AbstractQueueVisitorTest {
assertTrue(wasInterrupted.get());
assertTrue(executor.isShutdown());
+ assertTrue(throwableSeen.get());
}
@Test
public void javaErrorConsideredCriticalNoMatterWhat() throws Exception {
ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
- AbstractQueueVisitor visitor =
- createQueueVisitorWithErrorClassification(executor, ErrorClassification.NOT_CRITICAL);
+ final Error error = new Error("bad!");
+ final AtomicBoolean criticalErrorSeen = new AtomicBoolean(false);
+ ErrorHandler errorHandler = new ErrorHandler() {
+ @Override
+ public void handle(Throwable t, ErrorClassification classification) {
+ if (t == error) {
+ assertThat(classification).isEqualTo(ErrorClassification.CRITICAL_AND_LOG);
+ criticalErrorSeen.compareAndSet(false, true);
+ } else {
+ fail();
+ }
+ }
+ };
+ AbstractQueueVisitor visitor = createQueueVisitorWithConstantErrorClassification(
+ executor, ErrorClassification.NOT_CRITICAL, errorHandler);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean sleepFinished = new AtomicBoolean(false);
final AtomicBoolean sleepInterrupted = new AtomicBoolean(false);
- final Error error = new Error("bad!");
Runnable errorRunnable = new Runnable() {
@Override
public void run() {
@@ -429,6 +454,7 @@ public class AbstractQueueVisitorTest {
assertTrue(sleepInterrupted.get());
assertFalse(sleepFinished.get());
assertEquals(error, thrownError);
+ assertTrue(criticalErrorSeen.get());
}
private Runnable throwingRunnable() {
@@ -536,8 +562,9 @@ public class AbstractQueueVisitorTest {
}
}
- private static AbstractQueueVisitor createQueueVisitorWithErrorClassification(
- ThreadPoolExecutor executor, final ErrorClassification classification) {
+ private static AbstractQueueVisitor createQueueVisitorWithConstantErrorClassification(
+ ThreadPoolExecutor executor, final ErrorClassification classification,
+ ErrorHandler errorHandler) {
return new AbstractQueueVisitor(
/*concurrent=*/ true,
executor,
@@ -549,6 +576,7 @@ public class AbstractQueueVisitorTest {
protected ErrorClassification classifyException(Exception e) {
return classification;
}
- });
+ },
+ errorHandler);
}
}