38 |
|
return new TestSuite(SubmissionPublisherTest.class); |
39 |
|
} |
40 |
|
|
41 |
< |
// Factory for single thread pool in case commonPool parallelism is zero |
42 |
< |
static final class DaemonThreadFactory implements ThreadFactory { |
43 |
< |
public Thread newThread(Runnable r) { |
44 |
< |
Thread t = new Thread(r); |
45 |
< |
t.setDaemon(true); |
46 |
< |
return t; |
47 |
< |
} |
48 |
< |
} |
49 |
< |
|
50 |
< |
static final Executor basicExecutor = |
51 |
< |
(ForkJoinPool.getCommonPoolParallelism() > 1) ? |
52 |
< |
ForkJoinPool.commonPool() : |
53 |
< |
new ThreadPoolExecutor(1, 1, 60, SECONDS, |
54 |
< |
new LinkedBlockingQueue<Runnable>(), |
55 |
< |
new DaemonThreadFactory()); |
41 |
> |
final Executor basicExecutor = basicPublisher().getExecutor(); |
42 |
|
|
43 |
|
static SubmissionPublisher<Integer> basicPublisher() { |
44 |
< |
return new SubmissionPublisher<Integer>(basicExecutor, |
59 |
< |
Flow.defaultBufferSize()); |
44 |
> |
return new SubmissionPublisher<Integer>(); |
45 |
|
} |
46 |
|
|
47 |
|
static class SPException extends RuntimeException {} |
153 |
|
/** |
154 |
|
* A default-constructed SubmissionPublisher has no subscribers, |
155 |
|
* is not closed, has default buffer size, and uses the |
156 |
< |
* ForkJoinPool.commonPool executor |
156 |
> |
* defaultExecutor |
157 |
|
*/ |
158 |
|
public void testConstructor1() { |
159 |
|
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(); |
160 |
|
checkInitialState(p); |
176 |
– |
assertSame(p.getExecutor(), ForkJoinPool.commonPool()); |
161 |
|
assertEquals(p.getMaxBufferCapacity(), Flow.defaultBufferSize()); |
162 |
+ |
Executor e = p.getExecutor(), c = ForkJoinPool.commonPool(); |
163 |
+ |
if (ForkJoinPool.getCommonPoolParallelism() > 1) |
164 |
+ |
assertSame(e, c); |
165 |
+ |
else |
166 |
+ |
assertNotSame(e, c); |
167 |
|
} |
168 |
|
|
169 |
|
/** |
945 |
|
public void testConsume() { |
946 |
|
AtomicInteger sum = new AtomicInteger(); |
947 |
|
SubmissionPublisher<Integer> p = basicPublisher(); |
948 |
< |
CompletableFuture<Void> f = |
948 |
> |
CompletableFuture<Void> f = |
949 |
|
p.consume((Integer x) -> { sum.getAndAdd(x.intValue()); }); |
950 |
|
int n = 20; |
951 |
|
for (int i = 1; i <= n; ++i) |
963 |
|
try { |
964 |
|
CompletableFuture<Void> f = p.consume(null); |
965 |
|
shouldThrow(); |
966 |
< |
} catch(NullPointerException success) { |
978 |
< |
} |
966 |
> |
} catch (NullPointerException success) {} |
967 |
|
} |
968 |
|
|
969 |
|
/** |
979 |
|
p.submit(i); |
980 |
|
assertTrue(count.get() < n); |
981 |
|
} |
982 |
< |
|
982 |
> |
|
983 |
|
} |