| 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.*; |
| 15 |
import org.reactivestreams.tck.IdentityProcessorVerification; |
| 16 |
import org.reactivestreams.tck.TestEnvironment; |
| 17 |
import org.reactivestreams.tck.flow.support.SubscriberWhiteboxVerificationRules; |
| 18 |
import org.reactivestreams.tck.flow.support.PublisherVerificationRules; |
| 19 |
|
| 20 |
import java.util.concurrent.Flow; |
| 21 |
|
| 22 |
public abstract class IdentityFlowProcessorVerification<T> extends IdentityProcessorVerification<T> |
| 23 |
implements SubscriberWhiteboxVerificationRules, PublisherVerificationRules { |
| 24 |
|
| 25 |
public IdentityFlowProcessorVerification(TestEnvironment env) { |
| 26 |
super(env); |
| 27 |
} |
| 28 |
|
| 29 |
public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis) { |
| 30 |
super(env, publisherReferenceGCTimeoutMillis); |
| 31 |
} |
| 32 |
|
| 33 |
public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis, int processorBufferSize) { |
| 34 |
super(env, publisherReferenceGCTimeoutMillis, processorBufferSize); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* By implementing this method, additional TCK tests concerning a "failed" Flow publishers will be run. |
| 39 |
* |
| 40 |
* The expected behaviour of the {@link Flow.Publisher} returned by this method is hand out a subscription, |
| 41 |
* followed by signalling {@code onError} on it, as specified by Rule 1.9. |
| 42 |
* |
| 43 |
* If you want to ignore these additional tests, return {@code null} from this method. |
| 44 |
*/ |
| 45 |
protected abstract Flow.Publisher<T> createFailedFlowPublisher(); |
| 46 |
|
| 47 |
/** |
| 48 |
* This is the main method you must implement in your test incarnation. |
| 49 |
* It must create a {@link Flow.Processor}, which simply forwards all stream elements from its upstream |
| 50 |
* to its downstream. It must be able to internally buffer the given number of elements. |
| 51 |
* |
| 52 |
* @param bufferSize number of elements the processor is required to be able to buffer. |
| 53 |
*/ |
| 54 |
protected abstract Flow.Processor<T,T> createIdentityFlowProcessor(int bufferSize); |
| 55 |
|
| 56 |
@Override |
| 57 |
public final Processor<T, T> createIdentityProcessor(int bufferSize) { |
| 58 |
return FlowAdapters.toProcessor(createIdentityFlowProcessor(bufferSize)); |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public final Publisher<T> createFailedPublisher() { |
| 63 |
Flow.Publisher<T> failed = createFailedFlowPublisher(); |
| 64 |
if (failed == null) return null; // because `null` means "SKIP" in createFailedPublisher |
| 65 |
else return FlowAdapters.toPublisher(failed); |
| 66 |
} |
| 67 |
|
| 68 |
} |