|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.utils.async; |
| 17 | + |
| 18 | +import java.util.concurrent.CompletableFuture; |
| 19 | +import org.reactivestreams.Subscriber; |
| 20 | +import org.reactivestreams.Subscription; |
| 21 | +import org.reactivestreams.tck.SubscriberWhiteboxVerification; |
| 22 | +import org.reactivestreams.tck.TestEnvironment; |
| 23 | + |
| 24 | +public class SequentialSubscriberTckTest extends SubscriberWhiteboxVerification<Integer> { |
| 25 | + protected SequentialSubscriberTckTest() { |
| 26 | + super(new TestEnvironment()); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public Subscriber<Integer> createSubscriber(WhiteboxSubscriberProbe<Integer> probe) { |
| 31 | + CompletableFuture<Void> future = new CompletableFuture<>(); |
| 32 | + return new SequentialSubscriber<Integer>(i -> {}, future) { |
| 33 | + @Override |
| 34 | + public void onError(Throwable throwable) { |
| 35 | + super.onError(throwable); |
| 36 | + probe.registerOnError(throwable); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void onSubscribe(Subscription subscription) { |
| 41 | + super.onSubscribe(subscription); |
| 42 | + probe.registerOnSubscribe(new SubscriberPuppet() { |
| 43 | + @Override |
| 44 | + public void triggerRequest(long elements) { |
| 45 | + subscription.request(elements); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void signalCancel() { |
| 50 | + subscription.cancel(); |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onNext(Integer nextItems) { |
| 57 | + super.onNext(nextItems); |
| 58 | + probe.registerOnNext(nextItems); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void onComplete() { |
| 63 | + super.onComplete(); |
| 64 | + probe.registerOnComplete(); |
| 65 | + } |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public Integer createElement(int i) { |
| 71 | + return i; |
| 72 | + } |
| 73 | +} |
0 commit comments