Skip to content

Commit 20655c3

Browse files
Zsombor Erdődy-Nagyakarnokd
authored andcommitted
Add extra Maybe iterable Amb tests for overlapped emissions (#4567)
- Asserting that downstream will get the results of the first source that began emission, even if multiple sources have overlapped emissions - Testing Success and Error paths
1 parent 525bf58 commit 20655c3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/test/java/io/reactivex/maybe/MaybeTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,30 @@ public void ambIterable2SignalsSuccess() {
17001700
ts.assertResult(2);
17011701
}
17021702

1703+
@SuppressWarnings("unchecked")
1704+
@Test
1705+
public void ambIterable2SignalsSuccessWithOverlap() {
1706+
PublishProcessor<Integer> pp1 = PublishProcessor.create();
1707+
PublishProcessor<Integer> pp2 = PublishProcessor.create();
1708+
1709+
TestSubscriber<Integer> ts = Maybe.amb(Arrays.asList(pp1.toMaybe(), pp2.toMaybe()))
1710+
.test();
1711+
1712+
ts.assertEmpty();
1713+
1714+
assertTrue(pp1.hasSubscribers());
1715+
assertTrue(pp2.hasSubscribers());
1716+
1717+
pp2.onNext(2);
1718+
pp1.onNext(1);
1719+
pp2.onComplete();
1720+
1721+
assertFalse(pp1.hasSubscribers());
1722+
assertFalse(pp2.hasSubscribers());
1723+
1724+
ts.assertResult(2);
1725+
}
1726+
17031727
@SuppressWarnings("unchecked")
17041728
@Test
17051729
public void ambIterable1SignalsError() {
@@ -1744,6 +1768,29 @@ public void ambIterable2SignalsError() {
17441768
ts.assertFailure(TestException.class);
17451769
}
17461770

1771+
@SuppressWarnings("unchecked")
1772+
@Test
1773+
public void ambIterable2SignalsErrorWithOverlap() {
1774+
PublishProcessor<Integer> pp1 = PublishProcessor.create();
1775+
PublishProcessor<Integer> pp2 = PublishProcessor.create();
1776+
1777+
TestSubscriber<Integer> ts = Maybe.amb(Arrays.asList(pp1.toMaybe(), pp2.toMaybe()))
1778+
.test();
1779+
1780+
ts.assertEmpty();
1781+
1782+
assertTrue(pp1.hasSubscribers());
1783+
assertTrue(pp2.hasSubscribers());
1784+
1785+
pp2.onError(new TestException("2"));
1786+
pp1.onError(new TestException("1"));
1787+
1788+
assertFalse(pp1.hasSubscribers());
1789+
assertFalse(pp2.hasSubscribers());
1790+
1791+
ts.assertFailureAndMessage(TestException.class, "2");
1792+
}
1793+
17471794
@SuppressWarnings("unchecked")
17481795
@Test
17491796
public void ambIterable1SignalsComplete() {

0 commit comments

Comments
 (0)