|
16 | 16 |
|
17 | 17 | package rx.internal.operators;
|
18 | 18 |
|
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | + |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.List; |
| 23 | +import java.util.concurrent.CopyOnWriteArrayList; |
| 24 | + |
19 | 25 | import org.junit.*;
|
20 | 26 |
|
21 | 27 | import rx.*;
|
22 | 28 | import rx.exceptions.*;
|
23 | 29 | import rx.functions.Action1;
|
24 | 30 | import rx.observers.TestSubscriber;
|
| 31 | +import rx.plugins.RxJavaHooks; |
25 | 32 | import rx.subjects.PublishSubject;
|
26 | 33 |
|
27 | 34 | public class OnSubscribeFromAsyncTest {
|
@@ -134,6 +141,75 @@ public void normalError() {
|
134 | 141 |
|
135 | 142 | Assert.assertEquals("fromAsync: could not emit value due to lack of requests", ts.getOnErrorEvents().get(0).getMessage());
|
136 | 143 | }
|
| 144 | + |
| 145 | + @Test |
| 146 | + public void overflowErrorIsNotFollowedByAnotherErrorDueToOnNextFromUpstream() { |
| 147 | + Action1<AsyncEmitter<Integer>> source = new Action1<AsyncEmitter<Integer>>(){ |
| 148 | + |
| 149 | + @Override |
| 150 | + public void call(AsyncEmitter<Integer> emitter) { |
| 151 | + emitter.onNext(1); |
| 152 | + //don't check for unsubscription |
| 153 | + emitter.onNext(2); |
| 154 | + }}; |
| 155 | + Observable.fromAsync(source, AsyncEmitter.BackpressureMode.ERROR).unsafeSubscribe(ts); |
| 156 | + |
| 157 | + ts.assertNoValues(); |
| 158 | + ts.assertError(MissingBackpressureException.class); |
| 159 | + ts.assertNotCompleted(); |
| 160 | + |
| 161 | + Assert.assertEquals("fromAsync: could not emit value due to lack of requests", ts.getOnErrorEvents().get(0).getMessage()); |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + public void overflowErrorIsNotFollowedByAnotherCompletedDueToCompletedFromUpstream() { |
| 166 | + Action1<AsyncEmitter<Integer>> source = new Action1<AsyncEmitter<Integer>>(){ |
| 167 | + |
| 168 | + @Override |
| 169 | + public void call(AsyncEmitter<Integer> emitter) { |
| 170 | + emitter.onNext(1); |
| 171 | + //don't check for unsubscription |
| 172 | + emitter.onCompleted(); |
| 173 | + }}; |
| 174 | + Observable.fromAsync(source, AsyncEmitter.BackpressureMode.ERROR).unsafeSubscribe(ts); |
| 175 | + |
| 176 | + ts.assertNoValues(); |
| 177 | + ts.assertError(MissingBackpressureException.class); |
| 178 | + ts.assertNotCompleted(); |
| 179 | + |
| 180 | + Assert.assertEquals("fromAsync: could not emit value due to lack of requests", ts.getOnErrorEvents().get(0).getMessage()); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + public void overflowErrorIsNotFollowedByAnotherErrorDueToOnErrorFromUpstreamAndSecondErrorIsReportedToHook() { |
| 185 | + try { |
| 186 | + final List<Throwable> list = new CopyOnWriteArrayList<Throwable>(); |
| 187 | + RxJavaHooks.setOnError(new Action1<Throwable>() { |
| 188 | + @Override |
| 189 | + public void call(Throwable t) { |
| 190 | + list.add(t); |
| 191 | + }}); |
| 192 | + final RuntimeException e = new RuntimeException(); |
| 193 | + Action1<AsyncEmitter<Integer>> source = new Action1<AsyncEmitter<Integer>>(){ |
| 194 | + |
| 195 | + @Override |
| 196 | + public void call(AsyncEmitter<Integer> emitter) { |
| 197 | + emitter.onNext(1); |
| 198 | + //don't check for unsubscription |
| 199 | + emitter.onError(e); |
| 200 | + }}; |
| 201 | + Observable.fromAsync(source, AsyncEmitter.BackpressureMode.ERROR).unsafeSubscribe(ts); |
| 202 | + |
| 203 | + ts.assertNoValues(); |
| 204 | + ts.assertError(MissingBackpressureException.class); |
| 205 | + ts.assertNotCompleted(); |
| 206 | + |
| 207 | + Assert.assertEquals("fromAsync: could not emit value due to lack of requests", ts.getOnErrorEvents().get(0).getMessage()); |
| 208 | + assertEquals(Arrays.asList(e), list); |
| 209 | + } finally { |
| 210 | + RxJavaHooks.reset(); |
| 211 | + } |
| 212 | + } |
137 | 213 |
|
138 | 214 | @Test
|
139 | 215 | public void errorBuffered() {
|
|
0 commit comments