001/*************************************************** 002 * Licensed under MIT No Attribution (SPDX: MIT-0) * 003 ***************************************************/ 004 005package org.reactivestreams.tck.flow; 006 007import org.reactivestreams.*; 008import org.reactivestreams.tck.IdentityProcessorVerification; 009import org.reactivestreams.tck.TestEnvironment; 010import org.reactivestreams.tck.flow.support.SubscriberWhiteboxVerificationRules; 011import org.reactivestreams.tck.flow.support.PublisherVerificationRules; 012 013import java.util.concurrent.Flow; 014 015public abstract class IdentityFlowProcessorVerification<T> extends IdentityProcessorVerification<T> 016 implements SubscriberWhiteboxVerificationRules, PublisherVerificationRules { 017 018 public IdentityFlowProcessorVerification(TestEnvironment env) { 019 super(env); 020 } 021 022 public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis) { 023 super(env, publisherReferenceGCTimeoutMillis); 024 } 025 026 public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis, int processorBufferSize) { 027 super(env, publisherReferenceGCTimeoutMillis, processorBufferSize); 028 } 029 030 /** 031 * By implementing this method, additional TCK tests concerning a "failed" Flow publishers will be run. 032 * 033 * The expected behaviour of the {@link Flow.Publisher} returned by this method is hand out a subscription, 034 * followed by signalling {@code onError} on it, as specified by Rule 1.9. 035 * 036 * If you want to ignore these additional tests, return {@code null} from this method. 037 */ 038 protected abstract Flow.Publisher<T> createFailedFlowPublisher(); 039 040 /** 041 * This is the main method you must implement in your test incarnation. 042 * It must create a {@link Flow.Processor}, which simply forwards all stream elements from its upstream 043 * to its downstream. It must be able to internally buffer the given number of elements. 044 * 045 * @param bufferSize number of elements the processor is required to be able to buffer. 046 */ 047 protected abstract Flow.Processor<T,T> createIdentityFlowProcessor(int bufferSize); 048 049 @Override 050 public final Processor<T, T> createIdentityProcessor(int bufferSize) { 051 return FlowAdapters.toProcessor(createIdentityFlowProcessor(bufferSize)); 052 } 053 054 @Override 055 public final Publisher<T> createFailedPublisher() { 056 Flow.Publisher<T> failed = createFailedFlowPublisher(); 057 if (failed == null) return null; // because `null` means "SKIP" in createFailedPublisher 058 else return FlowAdapters.toPublisher(failed); 059 } 060 061}