Skip to content

Commit fe4e79b

Browse files
Remove expected error logging from the test console
1 parent cb3dc78 commit fe4e79b

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

test/com/linkedin/parseq/TestEngine.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.concurrent.ThreadPoolExecutor;
3232
import java.util.concurrent.TimeUnit;
3333

34+
import static com.linkedin.parseq.TestUtil.withDisabledLogging;
3435
import static org.testng.AssertJUnit.assertEquals;
3536
import static org.testng.AssertJUnit.assertFalse;
3637
import static org.testng.AssertJUnit.assertTrue;
@@ -190,8 +191,22 @@ public void testFailPlanExecution() throws InterruptedException
190191
// during submit to the underlying executor. We expect that it will be
191192
// cancelled.
192193
final Task<?> task = neverEndingBlockingTask();
193-
engine.run(task);
194-
assertTrue(task.await(5, TimeUnit.SECONDS));
194+
withDisabledLogging(new Runnable()
195+
{
196+
@Override
197+
public void run()
198+
{
199+
engine.run(task);
200+
try
201+
{
202+
assertTrue(task.await(5, TimeUnit.SECONDS));
203+
}
204+
catch (InterruptedException e)
205+
{
206+
// Ignore.
207+
}
208+
}
209+
});
195210
assertTrue(task.isFailed());
196211
assertTrue("Expected underlying exception to be instance of RejectedExecutionException, but was: " + task.getError().getCause(),
197212
task.getError().getCause() instanceof RejectedExecutionException);

test/com/linkedin/parseq/TestUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import com.linkedin.parseq.promise.Promise;
2020
import com.linkedin.parseq.promise.Promises;
21+
import org.apache.log4j.Level;
22+
import org.apache.log4j.LogManager;
23+
import org.apache.log4j.spi.LoggerRepository;
2124

2225
import static com.linkedin.parseq.Tasks.action;
2326
import static org.testng.AssertJUnit.assertTrue;
@@ -79,6 +82,22 @@ public static <T> Task<T> value(final String name, final T value)
7982
return new ValueTask<T>(name, value);
8083
}
8184

85+
public static void withDisabledLogging(final Runnable r)
86+
{
87+
// Note: this assumes we're using Log4J and needs to be fixed up if this changes.
88+
final LoggerRepository loggerRepo = LogManager.getLoggerRepository();
89+
final Level oldLevel = loggerRepo.getThreshold();
90+
loggerRepo.setThreshold(Level.OFF);
91+
try
92+
{
93+
r.run();
94+
}
95+
finally
96+
{
97+
loggerRepo.setThreshold(oldLevel);
98+
}
99+
}
100+
82101
private static class ValueTask<T> extends BaseTask<T>
83102
{
84103
private final T _value;

test/com/linkedin/parseq/promise/TestSettablePromise.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.TimeUnit;
2727
import java.util.concurrent.atomic.AtomicReference;
2828

29+
import static com.linkedin.parseq.TestUtil.withDisabledLogging;
2930
import static org.testng.AssertJUnit.*;
3031

3132
/**
@@ -339,7 +340,14 @@ public void onResolved(Promise<String> promise)
339340
}
340341
});
341342

342-
promise.done("Done!");
343+
withDisabledLogging(new Runnable() {
344+
@Override
345+
public void run()
346+
{
347+
promise.done("Done!");
348+
}
349+
});
350+
343351
assertTrue(promise.await(5, TimeUnit.SECONDS));
344352
assertEquals("Done!", promise.get());
345353
}
@@ -359,7 +367,14 @@ public void onResolved(Promise<String> promise)
359367
}
360368
});
361369

362-
promise.done("Done!");
370+
withDisabledLogging(new Runnable() {
371+
@Override
372+
public void run()
373+
{
374+
promise.done("Done!");
375+
}
376+
});
377+
363378
assertTrue(promise.await(5, TimeUnit.SECONDS));
364379
assertEquals("Done!", promise.get());
365380
}
@@ -373,13 +388,20 @@ public void testListenerThrowsErrorAfterPromiseDone() throws InterruptedExceptio
373388
promise.done("Done!");
374389
assertTrue(promise.await(5, TimeUnit.SECONDS));
375390

376-
// This should not throw
377-
promise.addListener(new PromiseListener<String>()
391+
withDisabledLogging(new Runnable()
378392
{
379393
@Override
380-
public void onResolved(Promise<String> promise)
394+
public void run()
381395
{
382-
throw new Error();
396+
// This should not throw
397+
promise.addListener(new PromiseListener<String>()
398+
{
399+
@Override
400+
public void onResolved(Promise<String> promise)
401+
{
402+
throw new Error();
403+
}
404+
});
383405
}
384406
});
385407
}

0 commit comments

Comments
 (0)