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,89 @@
/*
* 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.maybe;

import java.util.*;

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

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.exceptions.TestException;
import io.reactivex.rxjava4.observers.TestObserver;
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
import io.reactivex.rxjava4.processors.PublishProcessor;
import io.reactivex.rxjava4.subjects.*;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class MaybeAmbIsolatedTest extends RxJavaTest {

@Test
public void innerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp0 = PublishProcessor.create();
final PublishProcessor<Integer> pp1 = PublishProcessor.create();

final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement()))
.test();

final TestException ex = new TestException();

Runnable r1 = () -> pp0.onError(ex);

Runnable r2 = () -> pp1.onError(ex);

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);

if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}

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

try {

final Subject<Integer> ps = ReplaySubject.create();
ps.onNext(1);

final Maybe<Integer> source = Maybe.ambArray(ps.singleElement(),
Maybe.<Integer>never(), Maybe.<Integer>never(), null);

Runnable r1 = source::test;

Runnable r2 = ps::onComplete;

TestHelper.race(r1, r2);

if (!errors.isEmpty()) {
TestHelper.assertError(errors, 0, NullPointerException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.reactivex.rxjava4.functions.Consumer;
import io.reactivex.rxjava4.internal.functions.Functions;
import io.reactivex.rxjava4.observers.TestObserver;
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
import io.reactivex.rxjava4.processors.PublishProcessor;
import io.reactivex.rxjava4.schedulers.Schedulers;
import io.reactivex.rxjava4.subjects.*;
Expand Down Expand Up @@ -74,36 +73,6 @@ public void dispose() {
assertFalse(pp2.hasSubscribers());
}

@Test
public void innerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp0 = PublishProcessor.create();
final PublishProcessor<Integer> pp1 = PublishProcessor.create();

final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement()))
.test();

final TestException ex = new TestException();

Runnable r1 = () -> pp0.onError(ex);

Runnable r2 = () -> pp1.onError(ex);

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);

if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}

@Test
public void disposeNoFurtherSignals() {
var to = Maybe.ambArray(new Maybe<>() /* NFI */ {
Expand Down Expand Up @@ -190,34 +159,6 @@ public void noWinnerCompleteDispose() throws Exception {
}
}

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

try {

final Subject<Integer> ps = ReplaySubject.create();
ps.onNext(1);

final Maybe<Integer> source = Maybe.ambArray(ps.singleElement(),
Maybe.<Integer>never(), Maybe.<Integer>never(), null);

Runnable r1 = source::test;

Runnable r2 = ps::onComplete;

TestHelper.race(r1, r2);

if (!errors.isEmpty()) {
TestHelper.assertError(errors, 0, NullPointerException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}

@Test
public void maybeSourcesInIterable() {
MaybeSource<Integer> source = observer -> Maybe.just(1).subscribe(observer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.maybe;

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

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.core.config.StandardBufferedConfig;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class MaybeConcatArrayIsolatedTest extends RxJavaTest {

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Maybe.concatArray(Maybe.just(1), Maybe.just(2))
.test(0L);

Runnable r1 = ts::cancel;

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

TestHelper.race(r1, r2);
}
}

@Test
public void requestCancelRaceDelayError() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Maybe.concatArray(StandardBufferedConfig.DELAY_ERRORS, Maybe.just(1), Maybe.just(2))
.test(0L);

Runnable r1 = ts::cancel;

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

TestHelper.race(r1, r2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,6 @@ public void backpressureDelayError() {
ts.assertResult(1, 2);
}

@Test
public void requestCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Maybe.concatArray(Maybe.just(1), Maybe.just(2))
.test(0L);

Runnable r1 = ts::cancel;

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

TestHelper.race(r1, r2);
}
}

@Test
public void requestCancelRaceDelayError() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = Maybe.concatArray(StandardBufferedConfig.DELAY_ERRORS, Maybe.just(1), Maybe.just(2))
.test(0L);

Runnable r1 = ts::cancel;

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

TestHelper.race(r1, r2);
}
}

@Test
public void errorAfterTermination() {
List<Throwable> errors = TestHelper.trackPluginErrors();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.maybe;

import java.util.Collections;

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

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.processors.PublishProcessor;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class MaybeConcatIterableIsolatedTest extends RxJavaTest {

@Test
public void successCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {

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

final TestSubscriber<Integer> ts = Maybe.concat(Collections.singletonList(pp.singleElement()))
.test();

pp.onNext(1);

Runnable r1 = ts::cancel;

Runnable r2 = pp::onComplete;

TestHelper.race(r1, r2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import io.reactivex.rxjava4.exceptions.TestException;
import io.reactivex.rxjava4.functions.Function;
import io.reactivex.rxjava4.internal.util.CrashingMappedIterable;
import io.reactivex.rxjava4.processors.PublishProcessor;
import io.reactivex.rxjava4.subjects.MaybeSubject;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

public class MaybeConcatIterableTest extends RxJavaTest {
Expand Down Expand Up @@ -55,25 +53,6 @@ public void error() {
.assertFailure(TestException.class, 1);
}

@Test
public void successCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {

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

final TestSubscriber<Integer> ts = Maybe.concat(Collections.singletonList(pp.singleElement()))
.test();

pp.onNext(1);

Runnable r1 = ts::cancel;

Runnable r2 = pp::onComplete;

TestHelper.race(r1, r2);
}
}

@Test
public void hasNextThrows() {
Maybe.concat(new CrashingMappedIterable<>(100, 1, 100, _ -> Maybe.just(1)))
Expand Down
Loading