--- jsr166/src/test/tck/SubmissionPublisherTest.java 2015/09/12 11:25:15 1.10 +++ jsr166/src/test/tck/SubmissionPublisherTest.java 2015/09/12 17:18:13 1.12 @@ -38,25 +38,10 @@ public class SubmissionPublisherTest ext return new TestSuite(SubmissionPublisherTest.class); } - // Factory for single thread pool in case commonPool parallelism is zero - static final class DaemonThreadFactory implements ThreadFactory { - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - } - } - - static final Executor basicExecutor = - (ForkJoinPool.getCommonPoolParallelism() > 1) ? - ForkJoinPool.commonPool() : - new ThreadPoolExecutor(1, 1, 60, SECONDS, - new LinkedBlockingQueue(), - new DaemonThreadFactory()); - + final Executor basicExecutor = basicPublisher().getExecutor(); + static SubmissionPublisher basicPublisher() { - return new SubmissionPublisher(basicExecutor, - Flow.defaultBufferSize()); + return new SubmissionPublisher(); } static class SPException extends RuntimeException {} @@ -168,13 +153,17 @@ public class SubmissionPublisherTest ext /** * A default-constructed SubmissionPublisher has no subscribers, * is not closed, has default buffer size, and uses the - * ForkJoinPool.commonPool executor + * defaultExecutor */ public void testConstructor1() { SubmissionPublisher p = new SubmissionPublisher(); checkInitialState(p); - assertSame(p.getExecutor(), ForkJoinPool.commonPool()); assertEquals(p.getMaxBufferCapacity(), Flow.defaultBufferSize()); + Executor e = p.getExecutor(), c = ForkJoinPool.commonPool(); + if (ForkJoinPool.getCommonPoolParallelism() > 1) + assertSame(e, c); + else + assertNotSame(e, c); } /** @@ -956,7 +945,7 @@ public class SubmissionPublisherTest ext public void testConsume() { AtomicInteger sum = new AtomicInteger(); SubmissionPublisher p = basicPublisher(); - CompletableFuture f = + CompletableFuture f = p.consume((Integer x) -> { sum.getAndAdd(x.intValue()); }); int n = 20; for (int i = 1; i <= n; ++i) @@ -974,8 +963,7 @@ public class SubmissionPublisherTest ext try { CompletableFuture f = p.consume(null); shouldThrow(); - } catch(NullPointerException success) { - } + } catch (NullPointerException success) {} } /** @@ -991,5 +979,5 @@ public class SubmissionPublisherTest ext p.submit(i); assertTrue(count.get() < n); } - + }