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,77 @@
/*
* 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.concurrent.TimeoutException;

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

import io.reactivex.rxjava4.core.RxJavaTest;
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.testsupport.*;

@Isolated
public class MaybeTimeoutIsolatedTest extends RxJavaTest {

@Test
public void onErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestObserver<Integer> to = pp1.singleElement().timeout(pp2.singleElement()).test();

final TestException ex = new TestException();

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

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}

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

TestObserverEx<Integer> to = pp1.singleElement().timeout(pp2.singleElement()).to(TestHelper.<Integer>testConsumer());

Runnable r1 = pp1::onComplete;
Runnable r2 = pp2::onComplete;

TestHelper.race(r1, r2);

to.assertSubscribed().assertNoValues();

if (!to.errors().isEmpty()) {
to.assertError(TimeoutException.class).assertNotComplete();
} else {
to.assertNoErrors().assertComplete();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.concurrent.TimeoutException;

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

import io.reactivex.rxjava4.core.RxJavaTest;
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.testsupport.*;

@Isolated
public class MaybeTimeoutPublisherIsolatedTest extends RxJavaTest {

@Test
public void onErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestObserver<Integer> to = pp1.singleElement().timeout(pp2).test();

final TestException ex = new TestException();

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

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}

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

TestObserverEx<Integer> to = pp1.singleElement().timeout(pp2).to(TestHelper.<Integer>testConsumer());

Runnable r1 = pp1::onComplete;
Runnable r2 = pp2::onComplete;

TestHelper.race(r1, r2);

to.assertSubscribed().assertNoValues();

if (!to.errors().isEmpty()) {
to.assertError(TimeoutException.class).assertNotComplete();
} else {
to.assertNoErrors().assertComplete();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import io.reactivex.rxjava4.disposables.Disposable;
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.testsupport.*;
import io.reactivex.rxjava4.testsupport.TestHelper;

public class MaybeTimeoutPublisherTest extends RxJavaTest {

Expand Down Expand Up @@ -156,53 +155,6 @@ public void dispose2() {
TestHelper.checkDisposed(pp1.singleElement().timeout(pp2, Maybe.just(1)));
}

@Test
public void onErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestObserver<Integer> to = pp1.singleElement().timeout(pp2).test();

final TestException ex = new TestException();

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

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}

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

TestObserverEx<Integer> to = pp1.singleElement().timeout(pp2).to(TestHelper.<Integer>testConsumer());

Runnable r1 = pp1::onComplete;
Runnable r2 = pp2::onComplete;

TestHelper.race(r1, r2);

to.assertSubscribed().assertNoValues();

if (!to.errors().isEmpty()) {
to.assertError(TimeoutException.class).assertNotComplete();
} else {
to.assertNoErrors().assertComplete();
}
}
}

@Test
public void badSourceOther() {
TestHelper.checkBadSourceFlowable(f -> Maybe.never().timeout(f, Maybe.just(1)), false, null, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import io.reactivex.rxjava4.disposables.Disposable;
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.schedulers.Schedulers;
import io.reactivex.rxjava4.subjects.MaybeSubject;
import io.reactivex.rxjava4.testsupport.*;
import io.reactivex.rxjava4.testsupport.TestHelper;

public class MaybeTimeoutTest extends RxJavaTest {

Expand Down Expand Up @@ -278,53 +277,6 @@ public void dispose2() {
TestHelper.checkDisposed(pp1.singleElement().timeout(pp2.singleElement(), Maybe.just(1)));
}

@Test
public void onErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();

TestObserver<Integer> to = pp1.singleElement().timeout(pp2.singleElement()).test();

final TestException ex = new TestException();

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

TestHelper.race(r1, r2);

to.assertFailure(TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}

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

TestObserverEx<Integer> to = pp1.singleElement().timeout(pp2.singleElement()).to(TestHelper.<Integer>testConsumer());

Runnable r1 = pp1::onComplete;
Runnable r2 = pp2::onComplete;

TestHelper.race(r1, r2);

to.assertSubscribed().assertNoValues();

if (!to.errors().isEmpty()) {
to.assertError(TimeoutException.class).assertNotComplete();
} else {
to.assertNoErrors().assertComplete();
}
}
}

@Test
public void mainSuccessAfterOtherSignal() {
MaybeSubject<Integer> ms = MaybeSubject.create();
Expand Down
Loading