|
3 | 3 | import org.reactivestreams.Publisher;
|
4 | 4 | import org.reactivestreams.Subscriber;
|
5 | 5 | import org.reactivestreams.Subscription;
|
6 |
| -import org.reactivestreams.example.unicast.InfiniteIncrementNumberPublisher; |
7 |
| -import org.reactivestreams.example.unicast.NumberIterablePublisher; |
8 | 6 | import org.reactivestreams.tck.Annotations.Additional;
|
9 | 7 | import org.reactivestreams.tck.TestEnvironment.*;
|
10 |
| -import org.reactivestreams.tck.support.Function; |
11 | 8 | import org.reactivestreams.tck.support.Optional;
|
12 | 9 | import org.reactivestreams.tck.support.TestException;
|
13 |
| -import org.reactivestreams.tck.support.UnableToProvidePublisherException; |
14 | 10 | import org.testng.SkipException;
|
15 | 11 | import org.testng.annotations.AfterClass;
|
16 | 12 | import org.testng.annotations.BeforeClass;
|
17 | 13 | import org.testng.annotations.BeforeMethod;
|
18 |
| -import org.testng.annotations.BeforeTest; |
19 | 14 | import org.testng.annotations.Test;
|
20 | 15 |
|
21 |
| -import java.lang.reflect.ParameterizedType; |
22 | 16 | import java.util.concurrent.ExecutorService;
|
23 | 17 | import java.util.concurrent.Executors;
|
24 | 18 |
|
|
33 | 27 | * @see org.reactivestreams.Subscriber
|
34 | 28 | * @see org.reactivestreams.Subscription
|
35 | 29 | */
|
36 |
| -public abstract class SubscriberWhiteboxVerification<T> { |
| 30 | +public abstract class SubscriberWhiteboxVerification<T> extends WithHelperPublisher<T> { |
37 | 31 |
|
38 | 32 | private final TestEnvironment env;
|
39 | 33 |
|
@@ -61,63 +55,7 @@ protected SubscriberWhiteboxVerification(TestEnvironment env) {
|
61 | 55 | private ExecutorService publisherExecutor;
|
62 | 56 | @BeforeClass public void startPublisherExecutorService() { publisherExecutor = Executors.newFixedThreadPool(4); }
|
63 | 57 | @AfterClass public void shutdownPublisherExecutorService() { if (publisherExecutor != null) publisherExecutor.shutdown(); }
|
64 |
| - public ExecutorService publisherExecutorService() { return publisherExecutor; } |
65 |
| - |
66 |
| - /** |
67 |
| - * Returns the Class of the {@code <T>} type parameter with which this SubscriberVerification was instanciated. |
68 |
| - * This is used to validate if the default provided helper {@link Publisher} can drive the tests for the tested |
69 |
| - * {@link Subscriber} or not. |
70 |
| - * |
71 |
| - * @see #createHelperPublisher(long) |
72 |
| - */ |
73 |
| - @SuppressWarnings("unchecked") |
74 |
| - public Class<T> elementClass() { |
75 |
| - return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; |
76 |
| - } |
77 |
| - |
78 |
| - /** |
79 |
| - * Validates if the required element type is able to be signalled by the default Publisher. |
80 |
| - * <p> |
81 |
| - * If it is able to create such Publisher returns {@code true}, |
82 |
| - * otherwise throws an {@link org.reactivestreams.tck.support.UnableToProvidePublisherException}. |
83 |
| - */ |
84 |
| - @BeforeTest public boolean validateAbilityToProvidePublisher() { |
85 |
| - if (!elementClass().isAssignableFrom(Integer.class)) { |
86 |
| - throw new UnableToProvidePublisherException(String.format("Unable to provide Publisher of `%s` elements (can only emit `java.lang.Integer`)!", elementClass().getCanonicalName())); |
87 |
| - } else return true; |
88 |
| - } |
89 |
| - |
90 |
| - /** |
91 |
| - * Helper method required for creating the Publisher to which the tested Subscriber will be subscribed and tested against. |
92 |
| - * <p> |
93 |
| - * By default an <b>Asynchronous Integer signalling Publisher</b> is provided, however if this SubscriberVerification |
94 |
| - * was created using a different type (and your Subscriber is only able to consume those signals (e.g. "MyMessage")) |
95 |
| - * the default provided Publisher will NOT be able to generate those messages and will fail the entire test class and |
96 |
| - * asking you to provide a custom {@link Publisher} which is able to generate elements of type {@code T}. |
97 |
| - * <p> |
98 |
| - * When implementing a custom helper Publisher it MUST emit the exact number of elements asked for (via the {@code elements} |
99 |
| - * parameter) and MUST also must treat the following numbers of elements in these specific ways: |
100 |
| - * <ul> |
101 |
| - * <li> |
102 |
| - * If {@code elements} is {@code Long.MAX_VALUE} the produced stream must be infinite. |
103 |
| - * </li> |
104 |
| - * <li> |
105 |
| - * If {@code elements} is {@code 0} the {@code Publisher} should signal {@code onComplete} immediatly. |
106 |
| - * In other words, it should represent a "completed stream". |
107 |
| - * </li> |
108 |
| - * </ul> |
109 |
| - */ |
110 |
| - @SuppressWarnings("unchecked") |
111 |
| - public Publisher<T> createHelperPublisher(long elements) { |
112 |
| - if (validateAbilityToProvidePublisher()) { |
113 |
| - // we can safely provide the Integer based Publishers |
114 |
| - if (elements > Integer.MAX_VALUE) { |
115 |
| - return (Publisher<T>) new InfiniteIncrementNumberPublisher(publisherExecutorService()); |
116 |
| - } else { |
117 |
| - return (Publisher<T>) new NumberIterablePublisher(0, (int)elements, publisherExecutorService()); |
118 |
| - } |
119 |
| - } else throw new RuntimeException("Unreachable. `validateAbilityToProvidePublisher` should have thrown!"); |
120 |
| - } |
| 58 | + @Override public ExecutorService publisherExecutorService() { return publisherExecutor; } |
121 | 59 |
|
122 | 60 | ////////////////////// TEST ENV CLEANUP /////////////////////////////////////
|
123 | 61 |
|
|
0 commit comments