| 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.rxjava3.internal.subscribers; |
| 15 |
|
| 16 |
import org.junit.Test; |
| 17 |
|
| 18 |
import io.reactivex.rxjava3.core.RxJavaTest; |
| 19 |
import io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription; |
| 20 |
import io.reactivex.rxjava3.subscribers.TestSubscriber; |
| 21 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 22 |
|
| 23 |
public class SinglePostCompleteSubscriberTest extends RxJavaTest { |
| 24 |
|
| 25 |
@Test |
| 26 |
public void requestCompleteRace() { |
| 27 |
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { |
| 28 |
final TestSubscriber<Integer> ts = new TestSubscriber<>(0L); |
| 29 |
|
| 30 |
final SinglePostCompleteSubscriber<Integer, Integer> spc = new SinglePostCompleteSubscriber<Integer, Integer>(ts) { |
| 31 |
private static final long serialVersionUID = -2848918821531562637L; |
| 32 |
|
| 33 |
@Override |
| 34 |
public void onNext(Integer t) { |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
public void onError(Throwable t) { |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public void onComplete() { |
| 43 |
complete(1); |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
spc.onSubscribe(new BooleanSubscription()); |
| 48 |
|
| 49 |
Runnable r1 = new Runnable() { |
| 50 |
@Override |
| 51 |
public void run() { |
| 52 |
spc.onComplete(); |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
Runnable r2 = new Runnable() { |
| 57 |
@Override |
| 58 |
public void run() { |
| 59 |
ts.request(1); |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
TestHelper.race(r1, r2); |
| 64 |
|
| 65 |
ts.assertResult(1); |
| 66 |
} |
| 67 |
} |
| 68 |
} |