Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.rxjava4.internal.operators.flowable;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;

import io.reactivex.rxjava4.core.Flowable;
import io.reactivex.rxjava4.core.RxJavaTest;
import io.reactivex.rxjava4.internal.functions.Functions;
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
import io.reactivex.rxjava4.processors.PublishProcessor;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class FlowableFlatMapIsolatedTest extends RxJavaTest {

@Test
public void innerCompleteCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();

final TestSubscriber<Integer> ts = Flowable.merge(Flowable.just(pp)).test();

Runnable r1 = pp::onComplete;

Runnable r2 = ts::cancel;

TestHelper.race(r1, r2);
}
}

@Test
public void cancelScalarDrainRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {

final PublishProcessor<Flowable<Integer>> pp = PublishProcessor.create();

final TestSubscriber<Integer> ts = pp.flatMap(Functions.<Flowable<Integer>>identity()).test(0);

Runnable r1 = ts::cancel;
Runnable r2 = pp::onComplete;

TestHelper.race(r1, r2);

assertTrue(errors.isEmpty(), errors.toString());
} finally {
RxJavaPlugins.reset();
}
}
}

@Test
public void cancelDrainRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
for (int j = 1; j < 50; j += 5) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {

final PublishProcessor<Flowable<Integer>> pp = PublishProcessor.create();

final TestSubscriber<Integer> ts = pp.flatMap(Functions.<Flowable<Integer>>identity()).test(0);

final PublishProcessor<Integer> just = PublishProcessor.create();
pp.onNext(just);

Runnable r1 = () -> {
ts.request(1);
ts.cancel();
};
Runnable r2 = () -> just.onNext(1);

TestHelper.race(r1, r2);

assertTrue(errors.isEmpty(), errors.toString());
} finally {
RxJavaPlugins.reset();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.rxjava4.internal.operators.flowable;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;

import io.reactivex.rxjava4.core.Flowable;
import io.reactivex.rxjava4.core.Maybe;
import io.reactivex.rxjava4.core.RxJavaTest;
import io.reactivex.rxjava4.internal.functions.Functions;
import io.reactivex.rxjava4.subjects.MaybeSubject;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class FlowableFlatMapMaybeIsolatedTest extends RxJavaTest {

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Flowable.just(1).concatWith(Flowable.<Integer>never())
.flatMapMaybe(Functions.justFunction(Maybe.just(2))).test(0);

Runnable r1 = () -> ts.request(1);
Runnable r2 = ts::cancel;

TestHelper.race(r1, r2);
}
}

@Test
public void successRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
MaybeSubject<Integer> ms1 = MaybeSubject.create();
MaybeSubject<Integer> ms2 = MaybeSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ms1, ms2).flatMapMaybe(v -> v)
.test();

TestHelper.race(
() -> ms1.onSuccess(1),
() -> ms2.onSuccess(1)
);

ts.assertResult(1, 1);
}
}

@Test
public void successCompleteRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
MaybeSubject<Integer> ms1 = MaybeSubject.create();
MaybeSubject<Integer> ms2 = MaybeSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ms1, ms2).flatMapMaybe(v -> v)
.test();

TestHelper.race(
() -> ms1.onSuccess(1),
ms2::onComplete
);

ts.assertResult(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,6 @@ public void errorDelayed() {
.assertFailure(TestException.class);
}

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Flowable.just(1).concatWith(Flowable.<Integer>never())
.flatMapMaybe(Functions.justFunction(Maybe.just(2))).test(0);

Runnable r1 = () -> ts.request(1);
Runnable r2 = ts::cancel;

TestHelper.race(r1, r2);
}
}

@Test
public void undeliverableUponCancel() {
TestHelper.checkUndeliverableUponCancel((FlowableConverter<Integer, Flowable<Integer>>) upstream ->
Expand All @@ -502,42 +489,6 @@ public void badRequest() {
TestHelper.assertBadRequestReported(Flowable.never().flatMapMaybe(_ -> Maybe.never()));
}

@Test
public void successRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
MaybeSubject<Integer> ms1 = MaybeSubject.create();
MaybeSubject<Integer> ms2 = MaybeSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ms1, ms2).flatMapMaybe(v -> v)
.test();

TestHelper.race(
() -> ms1.onSuccess(1),
() -> ms2.onSuccess(1)
);

ts.assertResult(1, 1);
}
}

@Test
public void successCompleteRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
MaybeSubject<Integer> ms1 = MaybeSubject.create();
MaybeSubject<Integer> ms2 = MaybeSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ms1, ms2).flatMapMaybe(v -> v)
.test();

TestHelper.race(
() -> ms1.onSuccess(1),
ms2::onComplete
);

ts.assertResult(1);
}
}

@Test
public void successShortcut() {
MaybeSubject<Integer> ms1 = MaybeSubject.create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.rxjava4.internal.operators.flowable;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;

import io.reactivex.rxjava4.core.Flowable;
import io.reactivex.rxjava4.core.RxJavaTest;
import io.reactivex.rxjava4.core.Single;
import io.reactivex.rxjava4.internal.functions.Functions;
import io.reactivex.rxjava4.subjects.SingleSubject;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class FlowableFlatMapSingleIsolatedTest extends RxJavaTest {

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Flowable.just(1).concatWith(Flowable.<Integer>never())
.flatMapSingle(Functions.justFunction(Single.just(2))).test(0);

Runnable r1 = () -> ts.request(1);
Runnable r2 = ts::cancel;

TestHelper.race(r1, r2);
}
}

@Test
public void successRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
SingleSubject<Integer> ss1 = SingleSubject.create();
SingleSubject<Integer> ss2 = SingleSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ss1, ss2).flatMapSingle(v -> v)
.test();

TestHelper.race(
() -> ss1.onSuccess(1),
() -> ss2.onSuccess(1)
);

ts.assertResult(1, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,6 @@ public void errorDelayed() {
.assertFailure(TestException.class);
}

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Flowable.just(1).concatWith(Flowable.<Integer>never())
.flatMapSingle(Functions.justFunction(Single.just(2))).test(0);

Runnable r1 = () -> ts.request(1);
Runnable r2 = ts::cancel;

TestHelper.race(r1, r2);
}
}

@Test
public void asyncFlattenErrorMaxConcurrency() {
Flowable.range(1, 1000)
Expand Down Expand Up @@ -425,24 +412,6 @@ public void badRequest() {
TestHelper.assertBadRequestReported(Flowable.never().flatMapSingle(_ -> Single.never()));
}

@Test
public void successRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
SingleSubject<Integer> ss1 = SingleSubject.create();
SingleSubject<Integer> ss2 = SingleSubject.create();

TestSubscriber<Integer> ts = Flowable.just(ss1, ss2).flatMapSingle(v -> v)
.test();

TestHelper.race(
() -> ss1.onSuccess(1),
() -> ss2.onSuccess(1)
);

ts.assertResult(1, 1);
}
}

@Test
public void successShortcut() {
SingleSubject<Integer> ss1 = SingleSubject.create();
Expand Down
Loading