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,88 @@
/*
* 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.completable;

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 CompletableAmbIsolatedTest 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<Void> to = Completable.amb(Arrays.asList(pp0.ignoreElements(), pp1.ignoreElements()))
.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 Completable source = Completable.ambArray(ps.ignoreElements(), Completable.never(), Completable.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 @@ -74,63 +74,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<Void> to = Completable.amb(Arrays.asList(pp0.ignoreElements(), pp1.ignoreElements()))
.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 Completable source = Completable.ambArray(ps.ignoreElements(), Completable.never(), Completable.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 ambWithOrder() {
Completable error = Completable.error(new RuntimeException());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.completable;

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

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.observers.TestObserver;
import io.reactivex.rxjava4.subjects.PublishSubject;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class CompletableCacheIsolatedTest extends RxJavaTest {

@Test
public void subscribeRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
PublishSubject<Integer> ps = PublishSubject.create();

final Completable c = ps.ignoreElements().cache();

final TestObserver<Void> to1 = new TestObserver<>();

final TestObserver<Void> to2 = new TestObserver<>();

Runnable r1 = () -> c.subscribe(to1);
Runnable r2 = () -> c.subscribe(to2);

TestHelper.race(r1, r2);

ps.onComplete();

to1.assertResult();
to2.assertResult();
}
}

@Test
public void subscribeDisposeRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
PublishSubject<Integer> ps = PublishSubject.create();

final Completable c = ps.ignoreElements().cache();

final TestObserver<Void> to1 = c.test();

final TestObserver<Void> to2 = new TestObserver<>();

Runnable r1 = to1::dispose;
Runnable r2 = () -> c.subscribe(to2);

TestHelper.race(r1, r2);

ps.onComplete();

to1.assertEmpty();
to2.assertResult();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.reactivex.rxjava4.internal.disposables.EmptyDisposable;
import io.reactivex.rxjava4.observers.TestObserver;
import io.reactivex.rxjava4.subjects.PublishSubject;
import io.reactivex.rxjava4.testsupport.TestHelper;

public class CompletableCacheTest extends RxJavaTest implements Consumer<Object>, Action {

Expand Down Expand Up @@ -167,52 +166,6 @@ public void dispose() {
to4.assertEmpty();
}

@Test
public void subscribeRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
PublishSubject<Integer> ps = PublishSubject.create();

final Completable c = ps.ignoreElements().cache();

final TestObserver<Void> to1 = new TestObserver<>();

final TestObserver<Void> to2 = new TestObserver<>();

Runnable r1 = () -> c.subscribe(to1);
Runnable r2 = () -> c.subscribe(to2);

TestHelper.race(r1, r2);

ps.onComplete();

to1.assertResult();
to2.assertResult();
}
}

@Test
public void subscribeDisposeRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
PublishSubject<Integer> ps = PublishSubject.create();

final Completable c = ps.ignoreElements().cache();

final TestObserver<Void> to1 = c.test();

final TestObserver<Void> to2 = new TestObserver<>();

Runnable r1 = to1::dispose;
Runnable r2 = () -> c.subscribe(to2);

TestHelper.race(r1, r2);

ps.onComplete();

to1.assertEmpty();
to2.assertResult();
}
}

@Test
public void doubleDispose() {
PublishSubject<Integer> ps = PublishSubject.create();
Expand Down
Loading