| 1 |
/************************************************************************ |
| 2 |
* Licensed under Public Domain (CC0) * |
| 3 |
* * |
| 4 |
* To the extent possible under law, the person who associated CC0 with * |
| 5 |
* this code has waived all copyright and related or neighboring * |
| 6 |
* rights to this code. * |
| 7 |
* * |
| 8 |
* You should have received a copy of the CC0 legalcode along with this * |
| 9 |
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.* |
| 10 |
************************************************************************/ |
| 11 |
|
| 12 |
package org.reactivestreams.tck.flow; |
| 13 |
|
| 14 |
import org.reactivestreams.tck.TestEnvironment; |
| 15 |
import org.testng.annotations.Test; |
| 16 |
|
| 17 |
import java.util.concurrent.*; |
| 18 |
|
| 19 |
@Test |
| 20 |
public class SubmissionPublisherTest extends FlowPublisherVerification<Integer> { |
| 21 |
|
| 22 |
public SubmissionPublisherTest() { |
| 23 |
super(new TestEnvironment()); |
| 24 |
} |
| 25 |
|
| 26 |
@Override |
| 27 |
public Flow.Publisher<Integer> createFlowPublisher(final long elements) { |
| 28 |
final SubmissionPublisher<Integer> sp = new SubmissionPublisher<Integer>(); |
| 29 |
|
| 30 |
Thread t = new Thread(new Runnable() { |
| 31 |
@Override |
| 32 |
public void run() { |
| 33 |
while (sp.getNumberOfSubscribers() == 0) { |
| 34 |
try { |
| 35 |
Thread.sleep(1); |
| 36 |
} catch (InterruptedException ex) { |
| 37 |
return; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
for (int i = 0; i < elements; i++) { |
| 42 |
sp.submit(i); |
| 43 |
} |
| 44 |
|
| 45 |
sp.close(); |
| 46 |
} |
| 47 |
}); |
| 48 |
t.setDaemon(true); |
| 49 |
t.start(); |
| 50 |
|
| 51 |
return sp; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public Flow.Publisher<Integer> createFailedFlowPublisher() { |
| 56 |
SubmissionPublisher<Integer> sp = new SubmissionPublisher<Integer>(); |
| 57 |
sp.closeExceptionally(new Exception()); |
| 58 |
return sp; |
| 59 |
} |
| 60 |
} |