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
481 changes: 41 additions & 440 deletions src/main/java/io/reactivex/rxjava4/core/Single.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.core.config;

import io.reactivex.rxjava4.internal.functions.ObjectHelper;

/**
* Configuration record for Single.merge() operators.
* @param delayErrors should the error propagation be delayed?
* @param maxConcurrency the number of source sequences run concurrently
* @since 4.0.0
*/
public record SingleMergeConfig(boolean delayErrors, int maxConcurrency) {

/**
* The default config with no error delay and Integer#MAX_VALUE as the maximum concurrency setting.
*/
public static final SingleMergeConfig DEFAULT = new SingleMergeConfig(false, Integer.MAX_VALUE);

/**
* The default config with error delay and Integer#MAX_VALUE as the maximum concurrency setting.
*/
public static final SingleMergeConfig DELAY_ERRORS = new SingleMergeConfig(true, Integer.MAX_VALUE);

/**
* Constructs a configuration record.
* @param delayErrors should the error propagation be delayed?
*/
public SingleMergeConfig(boolean delayErrors) {
this(delayErrors, Integer.MAX_VALUE);
}

/**
* Constructs a configuration record.
* @param maxConcurrency the number of source sequences run concurrently
*/
public SingleMergeConfig(int maxConcurrency) {
this(false, maxConcurrency);
}

/**
* Constructs a configuration record.
* @param delayErrors should the error propagation be delayed?
* @param maxConcurrency the number of source sequences run concurrently
*/
public SingleMergeConfig(boolean delayErrors, int maxConcurrency) {
ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency");
this.delayErrors = delayErrors;
this.maxConcurrency = maxConcurrency;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.core.config;

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

import org.junit.jupiter.api.Test;

import io.reactivex.rxjava4.core.RxJavaTest;

public class SingleMergeConfigTest extends RxJavaTest {

@Test
public void validation() {
assertTrue(new SingleMergeConfig(true).delayErrors(), "delayErrors - true");
assertFalse(new SingleMergeConfig(false).delayErrors(), "delayErrors - false");
assertEquals(5, new SingleMergeConfig(5).maxConcurrency(), "maxConcurrency - 5");
assertEquals(5, new SingleMergeConfig(true, 5).maxConcurrency(), "maxConcurrency both - true, 5");
assertEquals(5, new SingleMergeConfig(false, 5).maxConcurrency(), "maxConcurrency both - false, 5");
assertTrue(new SingleMergeConfig(true, 5).delayErrors(), "delayErrors both - true, 5");
assertFalse(new SingleMergeConfig(false, 5).delayErrors(), "delayErrors both - false, 5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -995,16 +995,16 @@ public void combineLatestDelayErrorIterableOfSourcesWithError() {
.assertFailure(TestException.class, "[1, 2]");
}

// @SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void combineLatestArrayEmpty() {
assertSame(Flowable.empty(), Flowable.combineLatestArray(new Flowable[0], Functions.<Object[]>identity(), 16));
assertSame(Flowable.empty(), Flowable.combineLatestArray(new Flowable[0], (Function)Functions.identity(), 16));
}

// @SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void combineLatestDelayErrorEmpty() {
assertSame(Flowable.empty(), Flowable.combineLatestArrayDelayError(new Flowable[0], Functions.<Object[]>identity(), 16));
assertSame(Flowable.empty(), Flowable.combineLatestArrayDelayError(new Flowable[0], (Function)Functions.identity(), 16));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.Test;

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.core.config.SingleMergeConfig;
import io.reactivex.rxjava4.exceptions.TestException;

public class SingleMergeArrayTest extends RxJavaTest {
Expand All @@ -36,14 +37,14 @@ public void error() {

@Test
public void normalDelayError() {
Single.mergeArrayDelayError(Single.just(1), Single.just(2), Single.just(3))
Single.mergeArray(SingleMergeConfig.DELAY_ERRORS, Single.just(1), Single.just(2), Single.just(3))
.test()
.assertResult(1, 2, 3);
}

@Test
public void errorDelayError() {
Single.mergeArrayDelayError(Single.just(1), Single.error(new TestException()), Single.just(3))
Single.mergeArray(SingleMergeConfig.DELAY_ERRORS, Single.just(1), Single.error(new TestException()), Single.just(3))
.test()
.assertFailure(TestException.class, 1, 3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.Test;

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.core.config.SingleMergeConfig;
import io.reactivex.rxjava4.exceptions.TestException;
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
import io.reactivex.rxjava4.testsupport.TestHelper;
Expand All @@ -36,21 +37,21 @@ public void mergeSingleSingle() {

@Test
public void merge2() {
Single.merge(Single.just(1), Single.just(2))
Single.mergeArray(Single.just(1), Single.just(2))
.test()
.assertResult(1, 2);
}

@Test
public void merge3() {
Single.merge(Single.just(1), Single.just(2), Single.just(3))
Single.mergeArray(Single.just(1), Single.just(2), Single.just(3))
.test()
.assertResult(1, 2, 3);
}

@Test
public void merge4() {
Single.merge(Single.just(1), Single.just(2), Single.just(3), Single.just(4))
Single.mergeArray(Single.just(1), Single.just(2), Single.just(3), Single.just(4))
.test()
.assertResult(1, 2, 3, 4);
}
Expand All @@ -62,7 +63,7 @@ public void mergeErrors() {
Single<Integer> source1 = Single.error(new TestException("First"));
Single<Integer> source2 = Single.error(new TestException("Second"));

Single.merge(source1, source2)
Single.mergeArray(source1, source2)
.to(TestHelper.<Integer>testConsumer())
.assertFailureAndMessage(TestException.class, "First");

Expand All @@ -74,29 +75,30 @@ public void mergeErrors() {

@Test
public void mergeDelayErrorIterable() {
Single.mergeDelayError(Arrays.asList(
Single.merge(Arrays.asList(
Single.just(1),
Single.<Integer>error(new TestException()),
Single.just(2))
Single.just(2)), SingleMergeConfig.DELAY_ERRORS
)
.test()
.assertFailure(TestException.class, 1, 2);
}

@Test
public void mergeDelayErrorPublisher() {
Single.mergeDelayError(Flowable.just(
Single.merge(Flowable.just(
Single.just(1),
Single.<Integer>error(new TestException()),
Single.just(2))
Single.just(2)), SingleMergeConfig.DELAY_ERRORS
)
.test()
.assertFailure(TestException.class, 1, 2);
}

@Test
public void mergeDelayError2() {
Single.mergeDelayError(
Single.mergeArray(
SingleMergeConfig.DELAY_ERRORS,
Single.just(1),
Single.<Integer>error(new TestException())
)
Expand All @@ -106,7 +108,8 @@ public void mergeDelayError2() {

@Test
public void mergeDelayError2ErrorFirst() {
Single.mergeDelayError(
Single.mergeArray(
SingleMergeConfig.DELAY_ERRORS,
Single.<Integer>error(new TestException()),
Single.just(1)
)
Expand All @@ -116,7 +119,8 @@ public void mergeDelayError2ErrorFirst() {

@Test
public void mergeDelayError3() {
Single.mergeDelayError(
Single.mergeArray(
SingleMergeConfig.DELAY_ERRORS,
Single.just(1),
Single.<Integer>error(new TestException()),
Single.just(2)
Expand All @@ -127,7 +131,8 @@ public void mergeDelayError3() {

@Test
public void mergeDelayError4() {
Single.mergeDelayError(
Single.mergeArray(
SingleMergeConfig.DELAY_ERRORS,
Single.just(1),
Single.<Integer>error(new TestException()),
Single.just(2),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/reactivex/rxjava4/single/SingleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void merge() {
Single<String> a = Single.just("A");
Single<String> b = Single.just("B");

Single.merge(a, b).subscribe(ts);
Single.mergeArray(a, b).subscribe(ts);
ts.assertValueSequence(Arrays.asList("A", "B"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ public void checkParallelFlowable() {

defaultValues.put(SingleConcatConfig.class, SingleConcatConfig.DEFAULT);
defaultValues.put(SingleConcatEagerConfig.class, SingleConcatEagerConfig.DEFAULT);
defaultValues.put(SingleMergeConfig.class, SingleMergeConfig.DEFAULT);

@SuppressWarnings("rawtypes")
class MixedConverters implements FlowableConverter, ObservableConverter, SingleConverter,
Expand Down