test/jdk/java/net/httpclient/reactivestreams-tck/org/reactivestreams/tck/flow/IdentityFlowProcessorVerification.java
author prappo
Tue, 02 Jul 2019 13:25:51 +0100
changeset 55546 3ae57bbf9585
permissions -rw-r--r--
8226602: Test convenience reactive primitives from java.net.http with RS TCK Reviewed-by: chegar, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55546
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     1
/*
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     4
 *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     8
 *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    13
 * accompanied this code).
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    14
 *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    18
 *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    21
 * questions.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    22
 */
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    23
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    24
package org.reactivestreams.tck.flow;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    25
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    26
import org.reactivestreams.*;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    27
import org.reactivestreams.tck.IdentityProcessorVerification;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    28
import org.reactivestreams.tck.TestEnvironment;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    29
import org.reactivestreams.tck.flow.support.SubscriberWhiteboxVerificationRules;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    30
import org.reactivestreams.tck.flow.support.PublisherVerificationRules;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    31
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    32
import java.util.concurrent.Flow;
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    33
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    34
public abstract class IdentityFlowProcessorVerification<T> extends IdentityProcessorVerification<T>
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    35
  implements SubscriberWhiteboxVerificationRules, PublisherVerificationRules {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    36
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    37
  public IdentityFlowProcessorVerification(TestEnvironment env) {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    38
    super(env);
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    39
  }
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    40
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    41
  public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis) {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    42
    super(env, publisherReferenceGCTimeoutMillis);
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    43
  }
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    44
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    45
  public IdentityFlowProcessorVerification(TestEnvironment env, long publisherReferenceGCTimeoutMillis, int processorBufferSize) {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    46
    super(env, publisherReferenceGCTimeoutMillis, processorBufferSize);
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    47
  }
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    48
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    49
  /**
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    50
   * By implementing this method, additional TCK tests concerning a "failed" Flow publishers will be run.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    51
   *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    52
   * The expected behaviour of the {@link Flow.Publisher} returned by this method is hand out a subscription,
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    53
   * followed by signalling {@code onError} on it, as specified by Rule 1.9.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    54
   *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    55
   * If you want to ignore these additional tests, return {@code null} from this method.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    56
   */
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    57
  protected abstract Flow.Publisher<T> createFailedFlowPublisher();
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    58
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    59
  /**
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    60
   * This is the main method you must implement in your test incarnation.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    61
   * It must create a {@link Flow.Processor}, which simply forwards all stream elements from its upstream
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    62
   * to its downstream. It must be able to internally buffer the given number of elements.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    63
   *
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    64
   * @param bufferSize number of elements the processor is required to be able to buffer.
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    65
   */
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    66
  protected abstract Flow.Processor<T,T> createIdentityFlowProcessor(int bufferSize);
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    67
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    68
  @Override
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    69
  public final Processor<T, T> createIdentityProcessor(int bufferSize) {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    70
    return FlowAdapters.toProcessor(createIdentityFlowProcessor(bufferSize));
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    71
  }
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    72
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    73
  @Override
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    74
  public final Publisher<T> createFailedPublisher() {
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    75
    Flow.Publisher<T> failed = createFailedFlowPublisher();
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    76
    if (failed == null) return null; // because `null` means "SKIP" in createFailedPublisher
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    77
    else return FlowAdapters.toPublisher(failed);
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    78
  }
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    79
3ae57bbf9585 8226602: Test convenience reactive primitives from java.net.http with RS TCK
prappo
parents:
diff changeset
    80
}