|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-present, RxJava Contributors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 | + * compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 | + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 | + * the License for the specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package io.reactivex.rxjava4.internal.subscribers; |
| 15 | + |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | +import org.junit.jupiter.api.parallel.Isolated; |
| 18 | + |
| 19 | +import io.reactivex.rxjava4.core.RxJavaTest; |
| 20 | +import io.reactivex.rxjava4.exceptions.TestException; |
| 21 | +import io.reactivex.rxjava4.internal.subscriptions.BooleanSubscription; |
| 22 | +import io.reactivex.rxjava4.testsupport.SuppressUndeliverable; |
| 23 | +import io.reactivex.rxjava4.testsupport.TestHelper; |
| 24 | + |
| 25 | +@Isolated |
| 26 | +public class FutureSubscriberIsolatedTest extends RxJavaTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void cancelRace() { |
| 30 | + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { |
| 31 | + final FutureSubscriber<Integer> fs = new FutureSubscriber<>(); |
| 32 | + |
| 33 | + Runnable r = () -> fs.cancel(false); |
| 34 | + |
| 35 | + TestHelper.race(r, r); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + @SuppressUndeliverable |
| 41 | + public void onErrorCancelRace() { |
| 42 | + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { |
| 43 | + final FutureSubscriber<Integer> fs = new FutureSubscriber<>(); |
| 44 | + |
| 45 | + final TestException ex = new TestException(); |
| 46 | + |
| 47 | + Runnable r1 = () -> fs.cancel(false); |
| 48 | + |
| 49 | + Runnable r2 = () -> fs.onError(ex); |
| 50 | + |
| 51 | + TestHelper.race(r1, r2); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + @SuppressUndeliverable |
| 57 | + public void onCompleteCancelRace() { |
| 58 | + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { |
| 59 | + final FutureSubscriber<Integer> fs = new FutureSubscriber<>(); |
| 60 | + |
| 61 | + if (i % 3 == 0) { |
| 62 | + fs.onSubscribe(new BooleanSubscription()); |
| 63 | + } |
| 64 | + |
| 65 | + if (i % 2 == 0) { |
| 66 | + fs.onNext(1); |
| 67 | + } |
| 68 | + |
| 69 | + Runnable r1 = () -> fs.cancel(false); |
| 70 | + |
| 71 | + Runnable r2 = fs::onComplete; |
| 72 | + |
| 73 | + TestHelper.race(r1, r2); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments