| 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.Publisher; |
| 15 |
import org.reactivestreams.FlowAdapters; |
| 16 |
import org.reactivestreams.tck.PublisherVerification; |
| 17 |
import org.reactivestreams.tck.TestEnvironment; |
| 18 |
|
| 19 |
import java.util.concurrent.Flow; |
| 20 |
|
| 21 |
/** |
| 22 |
* Provides tests for verifying a Java 9+ {@link java.util.concurrent.Flow.Publisher} specification rules. |
| 23 |
* |
| 24 |
* @see java.util.concurrent.Flow.Publisher |
| 25 |
*/ |
| 26 |
public abstract class FlowPublisherVerification<T> extends PublisherVerification<T> { |
| 27 |
|
| 28 |
public FlowPublisherVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis) { |
| 29 |
super(env, publisherReferenceGCTimeoutMillis); |
| 30 |
} |
| 31 |
|
| 32 |
public FlowPublisherVerification(TestEnvironment env) { |
| 33 |
super(env); |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
final public Publisher<T> createPublisher(long elements) { |
| 38 |
final Flow.Publisher<T> flowPublisher = createFlowPublisher(elements); |
| 39 |
return FlowAdapters.toPublisher(flowPublisher); |
| 40 |
} |
| 41 |
/** |
| 42 |
* This is the main method you must implement in your test incarnation. |
| 43 |
* It must create a Publisher for a stream with exactly the given number of elements. |
| 44 |
* If `elements` is `Long.MAX_VALUE` the produced stream must be infinite. |
| 45 |
*/ |
| 46 |
public abstract Flow.Publisher<T> createFlowPublisher(long elements); |
| 47 |
|
| 48 |
@Override |
| 49 |
final public Publisher<T> createFailedPublisher() { |
| 50 |
final Flow.Publisher<T> failed = createFailedFlowPublisher(); |
| 51 |
if (failed == null) return null; // because `null` means "SKIP" in createFailedPublisher |
| 52 |
else return FlowAdapters.toPublisher(failed); |
| 53 |
} |
| 54 |
/** |
| 55 |
* By implementing this method, additional TCK tests concerning a "failed" publishers will be run. |
| 56 |
* |
| 57 |
* The expected behaviour of the {@link Flow.Publisher} returned by this method is hand out a subscription, |
| 58 |
* followed by signalling {@code onError} on it, as specified by Rule 1.9. |
| 59 |
* |
| 60 |
* If you ignore these additional tests, return {@code null} from this method. |
| 61 |
*/ |
| 62 |
public abstract Flow.Publisher<T> createFailedFlowPublisher(); |
| 63 |
} |