| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.operators.observable; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import java.lang.reflect.Method; |
| 19 |
import java.util.*; |
| 20 |
import java.util.concurrent.*; |
| 21 |
import java.util.concurrent.atomic.AtomicInteger; |
| 22 |
|
| 23 |
import org.junit.Test; |
| 24 |
|
| 25 |
import io.reactivex.rxjava3.annotations.NonNull; |
| 26 |
import io.reactivex.rxjava3.core.*; |
| 27 |
import io.reactivex.rxjava3.core.Observable; |
| 28 |
import io.reactivex.rxjava3.core.Observer; |
| 29 |
import io.reactivex.rxjava3.disposables.Disposable; |
| 30 |
import io.reactivex.rxjava3.exceptions.*; |
| 31 |
import io.reactivex.rxjava3.functions.*; |
| 32 |
import io.reactivex.rxjava3.internal.disposables.EmptyDisposable; |
| 33 |
import io.reactivex.rxjava3.internal.functions.Functions; |
| 34 |
import io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler; |
| 35 |
import io.reactivex.rxjava3.observers.*; |
| 36 |
import io.reactivex.rxjava3.plugins.RxJavaPlugins; |
| 37 |
import io.reactivex.rxjava3.schedulers.Schedulers; |
| 38 |
import io.reactivex.rxjava3.subjects.*; |
| 39 |
import io.reactivex.rxjava3.testsupport.*; |
| 40 |
|
| 41 |
public class ObservableConcatMapSchedulerTest { |
| 42 |
|
| 43 |
@Test |
| 44 |
public void boundaryFusion() { |
| 45 |
Observable.range(1, 10000) |
| 46 |
.observeOn(Schedulers.single()) |
| 47 |
.map(new Function<Integer, String>() { |
| 48 |
@Override |
| 49 |
public String apply(Integer t) throws Exception { |
| 50 |
String name = Thread.currentThread().getName(); |
| 51 |
if (name.contains("RxSingleScheduler")) { |
| 52 |
return "RxSingleScheduler"; |
| 53 |
} |
| 54 |
return name; |
| 55 |
} |
| 56 |
}) |
| 57 |
.concatMap(new Function<String, ObservableSource<? extends Object>>() { |
| 58 |
@Override |
| 59 |
public ObservableSource<? extends Object> apply(String v) |
| 60 |
throws Exception { |
| 61 |
return Observable.just(v); |
| 62 |
} |
| 63 |
}, 2, ImmediateThinScheduler.INSTANCE) |
| 64 |
.observeOn(Schedulers.computation()) |
| 65 |
.distinct() |
| 66 |
.test() |
| 67 |
.awaitDone(5, TimeUnit.SECONDS) |
| 68 |
.assertResult("RxSingleScheduler"); |
| 69 |
} |
| 70 |
|
| 71 |
@Test |
| 72 |
public void boundaryFusionDelayError() { |
| 73 |
Observable.range(1, 10000) |
| 74 |
.observeOn(Schedulers.single()) |
| 75 |
.map(new Function<Integer, String>() { |
| 76 |
@Override |
| 77 |
public String apply(Integer t) throws Exception { |
| 78 |
String name = Thread.currentThread().getName(); |
| 79 |
if (name.contains("RxSingleScheduler")) { |
| 80 |
return "RxSingleScheduler"; |
| 81 |
} |
| 82 |
return name; |
| 83 |
} |
| 84 |
}) |
| 85 |
.concatMapDelayError(new Function<String, ObservableSource<? extends Object>>() { |
| 86 |
@Override |
| 87 |
public ObservableSource<? extends Object> apply(String v) |
| 88 |
throws Exception { |
| 89 |
return Observable.just(v); |
| 90 |
} |
| 91 |
}, true, 2, ImmediateThinScheduler.INSTANCE) |
| 92 |
.observeOn(Schedulers.computation()) |
| 93 |
.distinct() |
| 94 |
.test() |
| 95 |
.awaitDone(5, TimeUnit.SECONDS) |
| 96 |
.assertResult("RxSingleScheduler"); |
| 97 |
} |
| 98 |
|
| 99 |
@Test |
| 100 |
public void pollThrows() { |
| 101 |
Observable.just(1) |
| 102 |
.map(new Function<Integer, Integer>() { |
| 103 |
@Override |
| 104 |
public Integer apply(Integer v) throws Exception { |
| 105 |
throw new TestException(); |
| 106 |
} |
| 107 |
}) |
| 108 |
.compose(TestHelper.<Integer>observableStripBoundary()) |
| 109 |
.concatMap(new Function<Integer, ObservableSource<Integer>>() { |
| 110 |
@Override |
| 111 |
public ObservableSource<Integer> apply(Integer v) |
| 112 |
throws Exception { |
| 113 |
return Observable.just(v); |
| 114 |
} |
| 115 |
}, 2, ImmediateThinScheduler.INSTANCE) |
| 116 |
.test() |
| 117 |
.assertFailure(TestException.class); |
| 118 |
} |
| 119 |
|
| 120 |
@Test |
| 121 |
public void pollThrowsDelayError() { |
| 122 |
Observable.just(1) |
| 123 |
.map(new Function<Integer, Integer>() { |
| 124 |
@Override |
| 125 |
public Integer apply(Integer v) throws Exception { |
| 126 |
throw new TestException(); |
| 127 |
} |
| 128 |
}) |
| 129 |
.compose(TestHelper.<Integer>observableStripBoundary()) |
| 130 |
.concatMapDelayError(new Function<Integer, ObservableSource<Integer>>() { |
| 131 |
@Override |
| 132 |
public ObservableSource<Integer> apply(Integer v) |
| 133 |
throws Exception { |
| 134 |
return Observable.just(v); |
| 135 |
} |
| 136 |
}, true, 2, ImmediateThinScheduler.INSTANCE) |
| 137 |
.test() |
| 138 |
.assertFailure(TestException.class); |
| 139 |
} |
| 140 |
|
| 141 |
@Test |
| 142 |
public void noCancelPrevious() { |
| 143 |
final AtomicInteger counter = new AtomicInteger(); |
| 144 |
|
| 145 |
Observable.range(1, 5) |
| 146 |
.concatMap(new Function<Integer, Observable<Integer>>() { |
| 147 |
@Override |
| 148 |
public Observable<Integer> apply(Integer v) throws Exception { |
| 149 |
return Observable.just(v).doOnDispose(new Action() { |
| 150 |
@Override |
| 151 |
public void run() throws Exception { |
| 152 |
counter.getAndIncrement(); |
| 153 |
} |
| 154 |
}); |
| 155 |
} |
| 156 |
}, 2, ImmediateThinScheduler.INSTANCE) |
| 157 |
.test() |
| 158 |
.assertResult(1, 2, 3, 4, 5); |
| 159 |
|
| 160 |
assertEquals(0, counter.get()); |
| 161 |
} |
| 162 |
|
| 163 |
@Test |
| 164 |
public void delayErrorCallableTillTheEnd() { |
| 165 |
Observable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) |
| 166 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 167 |
@Override public Observable<Integer> apply(final Integer integer) throws Exception { |
| 168 |
return Observable.fromCallable(new Callable<Integer>() { |
| 169 |
@Override public Integer call() throws Exception { |
| 170 |
if (integer >= 100) { |
| 171 |
throw new NullPointerException("test null exp"); |
| 172 |
} |
| 173 |
return integer; |
| 174 |
} |
| 175 |
}); |
| 176 |
} |
| 177 |
}, true, 2, ImmediateThinScheduler.INSTANCE) |
| 178 |
.test() |
| 179 |
.assertFailure(CompositeException.class, 1, 2, 3, 23, 32); |
| 180 |
} |
| 181 |
|
| 182 |
@Test |
| 183 |
public void delayErrorCallableEager() { |
| 184 |
Observable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) |
| 185 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 186 |
@Override public Observable<Integer> apply(final Integer integer) throws Exception { |
| 187 |
return Observable.fromCallable(new Callable<Integer>() { |
| 188 |
@Override public Integer call() throws Exception { |
| 189 |
if (integer >= 100) { |
| 190 |
throw new NullPointerException("test null exp"); |
| 191 |
} |
| 192 |
return integer; |
| 193 |
} |
| 194 |
}); |
| 195 |
} |
| 196 |
}, false, 2, ImmediateThinScheduler.INSTANCE) |
| 197 |
.test() |
| 198 |
.assertFailure(NullPointerException.class, 1, 2, 3); |
| 199 |
} |
| 200 |
|
| 201 |
@Test |
| 202 |
public void mapperScheduled() { |
| 203 |
TestObserver<String> to = Observable.just(1) |
| 204 |
.concatMap(new Function<Integer, Observable<String>>() { |
| 205 |
@Override |
| 206 |
public Observable<String> apply(Integer t) throws Throwable { |
| 207 |
return Observable.just(Thread.currentThread().getName()); |
| 208 |
} |
| 209 |
}, 2, Schedulers.single()) |
| 210 |
.test() |
| 211 |
.awaitDone(5, TimeUnit.SECONDS) |
| 212 |
.assertValueCount(1) |
| 213 |
.assertNoErrors() |
| 214 |
.assertComplete(); |
| 215 |
|
| 216 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 217 |
} |
| 218 |
|
| 219 |
@Test |
| 220 |
public void mapperScheduledHidden() { |
| 221 |
TestObserver<String> to = Observable.just(1) |
| 222 |
.concatMap(new Function<Integer, Observable<String>>() { |
| 223 |
@Override |
| 224 |
public Observable<String> apply(Integer t) throws Throwable { |
| 225 |
return Observable.just(Thread.currentThread().getName()).hide(); |
| 226 |
} |
| 227 |
}, 2, Schedulers.single()) |
| 228 |
.test() |
| 229 |
.awaitDone(5, TimeUnit.SECONDS) |
| 230 |
.assertValueCount(1) |
| 231 |
.assertNoErrors() |
| 232 |
.assertComplete(); |
| 233 |
|
| 234 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 235 |
} |
| 236 |
|
| 237 |
@Test |
| 238 |
public void mapperDelayErrorScheduled() { |
| 239 |
TestObserver<String> to = Observable.just(1) |
| 240 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 241 |
@Override |
| 242 |
public Observable<String> apply(Integer t) throws Throwable { |
| 243 |
return Observable.just(Thread.currentThread().getName()); |
| 244 |
} |
| 245 |
}, false, 2, Schedulers.single()) |
| 246 |
.test() |
| 247 |
.awaitDone(5, TimeUnit.SECONDS) |
| 248 |
.assertValueCount(1) |
| 249 |
.assertNoErrors() |
| 250 |
.assertComplete(); |
| 251 |
|
| 252 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 253 |
} |
| 254 |
|
| 255 |
@Test |
| 256 |
public void mapperDelayErrorScheduledHidden() { |
| 257 |
TestObserver<String> to = Observable.just(1) |
| 258 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 259 |
@Override |
| 260 |
public Observable<String> apply(Integer t) throws Throwable { |
| 261 |
return Observable.just(Thread.currentThread().getName()).hide(); |
| 262 |
} |
| 263 |
}, false, 2, Schedulers.single()) |
| 264 |
.test() |
| 265 |
.awaitDone(5, TimeUnit.SECONDS) |
| 266 |
.assertValueCount(1) |
| 267 |
.assertNoErrors() |
| 268 |
.assertComplete(); |
| 269 |
|
| 270 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 271 |
} |
| 272 |
|
| 273 |
@Test |
| 274 |
public void mapperDelayError2Scheduled() { |
| 275 |
TestObserver<String> to = Observable.just(1) |
| 276 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 277 |
@Override |
| 278 |
public Observable<String> apply(Integer t) throws Throwable { |
| 279 |
return Observable.just(Thread.currentThread().getName()); |
| 280 |
} |
| 281 |
}, true, 2, Schedulers.single()) |
| 282 |
.test() |
| 283 |
.awaitDone(5, TimeUnit.SECONDS) |
| 284 |
.assertValueCount(1) |
| 285 |
.assertNoErrors() |
| 286 |
.assertComplete(); |
| 287 |
|
| 288 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 289 |
} |
| 290 |
|
| 291 |
@Test |
| 292 |
public void mapperDelayError2ScheduledHidden() { |
| 293 |
TestObserver<String> to = Observable.just(1) |
| 294 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 295 |
@Override |
| 296 |
public Observable<String> apply(Integer t) throws Throwable { |
| 297 |
return Observable.just(Thread.currentThread().getName()).hide(); |
| 298 |
} |
| 299 |
}, true, 2, Schedulers.single()) |
| 300 |
.test() |
| 301 |
.awaitDone(5, TimeUnit.SECONDS) |
| 302 |
.assertValueCount(1) |
| 303 |
.assertNoErrors() |
| 304 |
.assertComplete(); |
| 305 |
|
| 306 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 307 |
} |
| 308 |
|
| 309 |
@Test |
| 310 |
public void issue2890NoStackoverflow() throws InterruptedException, TimeoutException { |
| 311 |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
| 312 |
final Scheduler sch = Schedulers.from(executor); |
| 313 |
|
| 314 |
Function<Integer, Observable<Integer>> func = new Function<Integer, Observable<Integer>>() { |
| 315 |
@Override |
| 316 |
public Observable<Integer> apply(Integer t) { |
| 317 |
Observable<Integer> flowable = Observable.just(t) |
| 318 |
.subscribeOn(sch) |
| 319 |
; |
| 320 |
Subject<Integer> processor = UnicastSubject.create(); |
| 321 |
flowable.subscribe(processor); |
| 322 |
return processor; |
| 323 |
} |
| 324 |
}; |
| 325 |
|
| 326 |
int n = 5000; |
| 327 |
final AtomicInteger counter = new AtomicInteger(); |
| 328 |
|
| 329 |
Observable.range(1, n).concatMap(func, 2, ImmediateThinScheduler.INSTANCE).subscribe(new DefaultObserver<Integer>() { |
| 330 |
@Override |
| 331 |
public void onNext(Integer t) { |
| 332 |
// Consume after sleep for 1 ms |
| 333 |
try { |
| 334 |
Thread.sleep(1); |
| 335 |
} catch (InterruptedException e) { |
| 336 |
// ignored |
| 337 |
} |
| 338 |
if (counter.getAndIncrement() % 100 == 0) { |
| 339 |
System.out.print("testIssue2890NoStackoverflow -> "); |
| 340 |
System.out.println(counter.get()); |
| 341 |
}; |
| 342 |
} |
| 343 |
|
| 344 |
@Override |
| 345 |
public void onComplete() { |
| 346 |
executor.shutdown(); |
| 347 |
} |
| 348 |
|
| 349 |
@Override |
| 350 |
public void onError(Throwable e) { |
| 351 |
executor.shutdown(); |
| 352 |
} |
| 353 |
}); |
| 354 |
|
| 355 |
long awaitTerminationTimeout = 100_000; |
| 356 |
if (!executor.awaitTermination(awaitTerminationTimeout, TimeUnit.MILLISECONDS)) { |
| 357 |
throw new TimeoutException("Completed " + counter.get() + "/" + n + " before timed out after " |
| 358 |
+ awaitTerminationTimeout + " milliseconds."); |
| 359 |
} |
| 360 |
|
| 361 |
assertEquals(n, counter.get()); |
| 362 |
} |
| 363 |
|
| 364 |
@Test |
| 365 |
public void concatMapRangeAsyncLoopIssue2876() { |
| 366 |
final long durationSeconds = 2; |
| 367 |
final long startTime = System.currentTimeMillis(); |
| 368 |
for (int i = 0;; i++) { |
| 369 |
//only run this for a max of ten seconds |
| 370 |
if (System.currentTimeMillis() - startTime > TimeUnit.SECONDS.toMillis(durationSeconds)) { |
| 371 |
return; |
| 372 |
} |
| 373 |
if (i % 1000 == 0) { |
| 374 |
System.out.println("concatMapRangeAsyncLoop > " + i); |
| 375 |
} |
| 376 |
TestObserverEx<Integer> to = new TestObserverEx<>(); |
| 377 |
Observable.range(0, 1000) |
| 378 |
.concatMap(new Function<Integer, Observable<Integer>>() { |
| 379 |
@Override |
| 380 |
public Observable<Integer> apply(Integer t) { |
| 381 |
return Observable.fromIterable(Arrays.asList(t)); |
| 382 |
} |
| 383 |
}, 2, ImmediateThinScheduler.INSTANCE) |
| 384 |
.observeOn(Schedulers.computation()).subscribe(to); |
| 385 |
|
| 386 |
to.awaitDone(2500, TimeUnit.MILLISECONDS); |
| 387 |
to.assertTerminated(); |
| 388 |
to.assertNoErrors(); |
| 389 |
assertEquals(1000, to.values().size()); |
| 390 |
assertEquals((Integer)999, to.values().get(999)); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
@SuppressWarnings("unchecked") |
| 395 |
@Test |
| 396 |
public void concatArray() throws Exception { |
| 397 |
for (int i = 2; i < 10; i++) { |
| 398 |
Observable<Integer>[] obs = new Observable[i]; |
| 399 |
Arrays.fill(obs, Observable.just(1)); |
| 400 |
|
| 401 |
Integer[] expected = new Integer[i]; |
| 402 |
Arrays.fill(expected, 1); |
| 403 |
|
| 404 |
Method m = Observable.class.getMethod("concatArray", ObservableSource[].class); |
| 405 |
|
| 406 |
TestObserver<Integer> to = TestObserver.create(); |
| 407 |
|
| 408 |
((Observable<Integer>)m.invoke(null, new Object[]{obs})).subscribe(to); |
| 409 |
|
| 410 |
to.assertValues(expected); |
| 411 |
to.assertNoErrors(); |
| 412 |
to.assertComplete(); |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
| 417 |
@Test |
| 418 |
public void concatMapJustJust() { |
| 419 |
TestObserver<Integer> to = TestObserver.create(); |
| 420 |
|
| 421 |
Observable.just(Observable.just(1)).concatMap((Function)Functions.identity(), 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 422 |
|
| 423 |
to.assertValue(1); |
| 424 |
to.assertNoErrors(); |
| 425 |
to.assertComplete(); |
| 426 |
} |
| 427 |
|
| 428 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
| 429 |
@Test |
| 430 |
public void concatMapJustRange() { |
| 431 |
TestObserver<Integer> to = TestObserver.create(); |
| 432 |
|
| 433 |
Observable.just(Observable.range(1, 5)).concatMap((Function)Functions.identity(), 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 434 |
|
| 435 |
to.assertValues(1, 2, 3, 4, 5); |
| 436 |
to.assertNoErrors(); |
| 437 |
to.assertComplete(); |
| 438 |
} |
| 439 |
|
| 440 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
| 441 |
@Test |
| 442 |
public void concatMapDelayErrorJustJust() { |
| 443 |
TestObserver<Integer> to = TestObserver.create(); |
| 444 |
|
| 445 |
Observable.just(Observable.just(1)).concatMapDelayError((Function)Functions.identity(), true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 446 |
|
| 447 |
to.assertValue(1); |
| 448 |
to.assertNoErrors(); |
| 449 |
to.assertComplete(); |
| 450 |
} |
| 451 |
|
| 452 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
| 453 |
@Test |
| 454 |
public void concatMapDelayErrorJustRange() { |
| 455 |
TestObserver<Integer> to = TestObserver.create(); |
| 456 |
|
| 457 |
Observable.just(Observable.range(1, 5)).concatMapDelayError((Function)Functions.identity(), true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 458 |
|
| 459 |
to.assertValues(1, 2, 3, 4, 5); |
| 460 |
to.assertNoErrors(); |
| 461 |
to.assertComplete(); |
| 462 |
} |
| 463 |
|
| 464 |
@SuppressWarnings("unchecked") |
| 465 |
@Test |
| 466 |
public void startWithArray() throws Exception { |
| 467 |
for (int i = 2; i < 10; i++) { |
| 468 |
Object[] obs = new Object[i]; |
| 469 |
Arrays.fill(obs, 1); |
| 470 |
|
| 471 |
Integer[] expected = new Integer[i]; |
| 472 |
Arrays.fill(expected, 1); |
| 473 |
|
| 474 |
Method m = Observable.class.getMethod("startWithArray", Object[].class); |
| 475 |
|
| 476 |
TestObserver<Integer> to = TestObserver.create(); |
| 477 |
|
| 478 |
((Observable<Integer>)m.invoke(Observable.empty(), new Object[]{obs})).subscribe(to); |
| 479 |
|
| 480 |
to.assertValues(expected); |
| 481 |
to.assertNoErrors(); |
| 482 |
to.assertComplete(); |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
static final class InfiniteIterator implements Iterator<Integer>, Iterable<Integer> { |
| 487 |
|
| 488 |
int count; |
| 489 |
|
| 490 |
@Override |
| 491 |
public boolean hasNext() { |
| 492 |
return true; |
| 493 |
} |
| 494 |
|
| 495 |
@Override |
| 496 |
public Integer next() { |
| 497 |
return count++; |
| 498 |
} |
| 499 |
|
| 500 |
@Override |
| 501 |
public void remove() { |
| 502 |
} |
| 503 |
|
| 504 |
@Override |
| 505 |
public Iterator<Integer> iterator() { |
| 506 |
return this; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
@Test |
| 511 |
public void concatMapDelayError() { |
| 512 |
Observable.just(Observable.just(1), Observable.just(2)) |
| 513 |
.concatMapDelayError(Functions.<Observable<Integer>>identity(), true, 2, ImmediateThinScheduler.INSTANCE) |
| 514 |
.test() |
| 515 |
.assertResult(1, 2); |
| 516 |
} |
| 517 |
|
| 518 |
@Test |
| 519 |
public void concatMapDelayErrorJustSource() { |
| 520 |
Observable.just(0) |
| 521 |
.concatMapDelayError(new Function<Object, Observable<Integer>>() { |
| 522 |
@Override |
| 523 |
public Observable<Integer> apply(Object v) throws Exception { |
| 524 |
return Observable.just(1); |
| 525 |
} |
| 526 |
}, true, 16, ImmediateThinScheduler.INSTANCE) |
| 527 |
.test() |
| 528 |
.assertResult(1); |
| 529 |
|
| 530 |
} |
| 531 |
|
| 532 |
@Test |
| 533 |
public void concatMapJustSource() { |
| 534 |
Observable.just(0).hide() |
| 535 |
.concatMap(new Function<Object, Observable<Integer>>() { |
| 536 |
@Override |
| 537 |
public Observable<Integer> apply(Object v) throws Exception { |
| 538 |
return Observable.just(1); |
| 539 |
} |
| 540 |
}, 16, ImmediateThinScheduler.INSTANCE) |
| 541 |
.test() |
| 542 |
.assertResult(1); |
| 543 |
} |
| 544 |
|
| 545 |
@Test |
| 546 |
public void concatMapJustSourceDelayError() { |
| 547 |
Observable.just(0).hide() |
| 548 |
.concatMapDelayError(new Function<Object, Observable<Integer>>() { |
| 549 |
@Override |
| 550 |
public Observable<Integer> apply(Object v) throws Exception { |
| 551 |
return Observable.just(1); |
| 552 |
} |
| 553 |
}, false, 16, ImmediateThinScheduler.INSTANCE) |
| 554 |
.test() |
| 555 |
.assertResult(1); |
| 556 |
} |
| 557 |
|
| 558 |
@Test |
| 559 |
public void concatMapEmpty() { |
| 560 |
Observable.just(1).hide() |
| 561 |
.concatMap(Functions.justFunction(Observable.empty()), 2, ImmediateThinScheduler.INSTANCE) |
| 562 |
.test() |
| 563 |
.assertResult(); |
| 564 |
} |
| 565 |
|
| 566 |
@Test |
| 567 |
public void concatMapEmptyDelayError() { |
| 568 |
Observable.just(1).hide() |
| 569 |
.concatMapDelayError(Functions.justFunction(Observable.empty()), true, 2, ImmediateThinScheduler.INSTANCE) |
| 570 |
.test() |
| 571 |
.assertResult(); |
| 572 |
} |
| 573 |
|
| 574 |
@Test |
| 575 |
public void doubleOnSubscribe() { |
| 576 |
TestHelper.checkDoubleOnSubscribeObservable(new Function<Observable<Object>, ObservableSource<Integer>>() { |
| 577 |
@Override |
| 578 |
public ObservableSource<Integer> apply(Observable<Object> f) throws Exception { |
| 579 |
return f.concatMap(Functions.justFunction(Observable.just(2)), 2, ImmediateThinScheduler.INSTANCE); |
| 580 |
} |
| 581 |
}); |
| 582 |
TestHelper.checkDoubleOnSubscribeObservable(new Function<Observable<Object>, ObservableSource<Integer>>() { |
| 583 |
@Override |
| 584 |
public ObservableSource<Integer> apply(Observable<Object> f) throws Exception { |
| 585 |
return f.concatMapDelayError(Functions.justFunction(Observable.just(2)), true, 2, ImmediateThinScheduler.INSTANCE); |
| 586 |
} |
| 587 |
}); |
| 588 |
} |
| 589 |
|
| 590 |
@Test |
| 591 |
public void immediateInnerNextOuterError() { |
| 592 |
final PublishSubject<Integer> ps = PublishSubject.create(); |
| 593 |
|
| 594 |
final TestObserverEx<Integer> to = new TestObserverEx<Integer>() { |
| 595 |
@Override |
| 596 |
public void onNext(Integer t) { |
| 597 |
super.onNext(t); |
| 598 |
if (t == 1) { |
| 599 |
ps.onError(new TestException("First")); |
| 600 |
} |
| 601 |
} |
| 602 |
}; |
| 603 |
|
| 604 |
ps.concatMap(Functions.justFunction(Observable.just(1)), 2, ImmediateThinScheduler.INSTANCE) |
| 605 |
.subscribe(to); |
| 606 |
|
| 607 |
ps.onNext(1); |
| 608 |
|
| 609 |
assertFalse(ps.hasObservers()); |
| 610 |
|
| 611 |
to.assertFailureAndMessage(TestException.class, "First", 1); |
| 612 |
} |
| 613 |
|
| 614 |
@Test |
| 615 |
public void immediateInnerNextOuterError2() { |
| 616 |
final PublishSubject<Integer> ps = PublishSubject.create(); |
| 617 |
|
| 618 |
final TestObserverEx<Integer> to = new TestObserverEx<Integer>() { |
| 619 |
@Override |
| 620 |
public void onNext(Integer t) { |
| 621 |
super.onNext(t); |
| 622 |
if (t == 1) { |
| 623 |
ps.onError(new TestException("First")); |
| 624 |
} |
| 625 |
} |
| 626 |
}; |
| 627 |
|
| 628 |
ps.concatMap(Functions.justFunction(Observable.just(1).hide()), 2, ImmediateThinScheduler.INSTANCE) |
| 629 |
.subscribe(to); |
| 630 |
|
| 631 |
ps.onNext(1); |
| 632 |
|
| 633 |
assertFalse(ps.hasObservers()); |
| 634 |
|
| 635 |
to.assertFailureAndMessage(TestException.class, "First", 1); |
| 636 |
} |
| 637 |
|
| 638 |
@Test |
| 639 |
public void concatMapInnerError() { |
| 640 |
Observable.just(1).hide() |
| 641 |
.concatMap(Functions.justFunction(Observable.error(new TestException())), 2, ImmediateThinScheduler.INSTANCE) |
| 642 |
.test() |
| 643 |
.assertFailure(TestException.class); |
| 644 |
} |
| 645 |
|
| 646 |
@Test |
| 647 |
public void concatMapInnerErrorDelayError() { |
| 648 |
Observable.just(1).hide() |
| 649 |
.concatMapDelayError(Functions.justFunction(Observable.error(new TestException())), true, 2, ImmediateThinScheduler.INSTANCE) |
| 650 |
.test() |
| 651 |
.assertFailure(TestException.class); |
| 652 |
} |
| 653 |
|
| 654 |
@Test |
| 655 |
public void badSource() { |
| 656 |
TestHelper.checkBadSourceObservable(new Function<Observable<Integer>, Object>() { |
| 657 |
@Override |
| 658 |
public Object apply(Observable<Integer> f) throws Exception { |
| 659 |
return f.concatMap(Functions.justFunction(Observable.just(1).hide()), 2, ImmediateThinScheduler.INSTANCE); |
| 660 |
} |
| 661 |
}, true, 1, 1, 1); |
| 662 |
} |
| 663 |
|
| 664 |
@Test |
| 665 |
public void badInnerSource() { |
| 666 |
@SuppressWarnings("rawtypes") |
| 667 |
final Observer[] ts0 = { null }; |
| 668 |
TestObserverEx<Integer> to = Observable.just(1).hide().concatMap(Functions.justFunction(new Observable<Integer>() { |
| 669 |
@Override |
| 670 |
protected void subscribeActual(Observer<? super Integer> o) { |
| 671 |
ts0[0] = o; |
| 672 |
o.onSubscribe(Disposable.empty()); |
| 673 |
o.onError(new TestException("First")); |
| 674 |
} |
| 675 |
}), 2, ImmediateThinScheduler.INSTANCE) |
| 676 |
.to(TestHelper.<Integer>testConsumer()); |
| 677 |
|
| 678 |
to.assertFailureAndMessage(TestException.class, "First"); |
| 679 |
|
| 680 |
List<Throwable> errors = TestHelper.trackPluginErrors(); |
| 681 |
try { |
| 682 |
ts0[0].onError(new TestException("Second")); |
| 683 |
|
| 684 |
TestHelper.assertUndeliverable(errors, 0, TestException.class); |
| 685 |
} finally { |
| 686 |
RxJavaPlugins.reset(); |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
@Test |
| 691 |
public void badInnerSourceDelayError() { |
| 692 |
@SuppressWarnings("rawtypes") |
| 693 |
final Observer[] ts0 = { null }; |
| 694 |
TestObserverEx<Integer> to = Observable.just(1).hide().concatMapDelayError(Functions.justFunction(new Observable<Integer>() { |
| 695 |
@Override |
| 696 |
protected void subscribeActual(Observer<? super Integer> o) { |
| 697 |
ts0[0] = o; |
| 698 |
o.onSubscribe(Disposable.empty()); |
| 699 |
o.onError(new TestException("First")); |
| 700 |
} |
| 701 |
}), true, 2, ImmediateThinScheduler.INSTANCE) |
| 702 |
.to(TestHelper.<Integer>testConsumer()); |
| 703 |
|
| 704 |
to.assertFailureAndMessage(TestException.class, "First"); |
| 705 |
|
| 706 |
List<Throwable> errors = TestHelper.trackPluginErrors(); |
| 707 |
try { |
| 708 |
ts0[0].onError(new TestException("Second")); |
| 709 |
|
| 710 |
TestHelper.assertUndeliverable(errors, 0, TestException.class); |
| 711 |
} finally { |
| 712 |
RxJavaPlugins.reset(); |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
@Test |
| 717 |
public void badSourceDelayError() { |
| 718 |
TestHelper.checkBadSourceObservable(new Function<Observable<Integer>, Object>() { |
| 719 |
@Override |
| 720 |
public Object apply(Observable<Integer> f) throws Exception { |
| 721 |
return f.concatMapDelayError(Functions.justFunction(Observable.just(1).hide()), true, 2, ImmediateThinScheduler.INSTANCE); |
| 722 |
} |
| 723 |
}, true, 1, 1, 1); |
| 724 |
} |
| 725 |
|
| 726 |
@Test |
| 727 |
public void fusedCrash() { |
| 728 |
Observable.range(1, 2) |
| 729 |
.map(new Function<Integer, Object>() { |
| 730 |
@Override |
| 731 |
public Object apply(Integer v) throws Exception { throw new TestException(); } |
| 732 |
}) |
| 733 |
.concatMap(Functions.justFunction(Observable.just(1)), 2, ImmediateThinScheduler.INSTANCE) |
| 734 |
.test() |
| 735 |
.assertFailure(TestException.class); |
| 736 |
} |
| 737 |
|
| 738 |
@Test |
| 739 |
public void fusedCrashDelayError() { |
| 740 |
Observable.range(1, 2) |
| 741 |
.map(new Function<Integer, Object>() { |
| 742 |
@Override |
| 743 |
public Object apply(Integer v) throws Exception { throw new TestException(); } |
| 744 |
}) |
| 745 |
.concatMapDelayError(Functions.justFunction(Observable.just(1)), true, 2, ImmediateThinScheduler.INSTANCE) |
| 746 |
.test() |
| 747 |
.assertFailure(TestException.class); |
| 748 |
} |
| 749 |
|
| 750 |
@Test |
| 751 |
public void callableCrash() { |
| 752 |
Observable.just(1).hide() |
| 753 |
.concatMap(Functions.justFunction(Observable.fromCallable(new Callable<Object>() { |
| 754 |
@Override |
| 755 |
public Object call() throws Exception { |
| 756 |
throw new TestException(); |
| 757 |
} |
| 758 |
})), 2, ImmediateThinScheduler.INSTANCE) |
| 759 |
.test() |
| 760 |
.assertFailure(TestException.class); |
| 761 |
} |
| 762 |
|
| 763 |
@Test |
| 764 |
public void callableCrashDelayError() { |
| 765 |
Observable.just(1).hide() |
| 766 |
.concatMapDelayError(Functions.justFunction(Observable.fromCallable(new Callable<Object>() { |
| 767 |
@Override |
| 768 |
public Object call() throws Exception { |
| 769 |
throw new TestException(); |
| 770 |
} |
| 771 |
})), true, 2, ImmediateThinScheduler.INSTANCE) |
| 772 |
.test() |
| 773 |
.assertFailure(TestException.class); |
| 774 |
} |
| 775 |
|
| 776 |
@Test |
| 777 |
public void dispose() { |
| 778 |
TestHelper.checkDisposed(Observable.range(1, 2) |
| 779 |
.concatMap(Functions.justFunction(Observable.just(1)), 2, ImmediateThinScheduler.INSTANCE)); |
| 780 |
|
| 781 |
TestHelper.checkDisposed(Observable.range(1, 2) |
| 782 |
.concatMapDelayError(Functions.justFunction(Observable.just(1)), true, 2, ImmediateThinScheduler.INSTANCE)); |
| 783 |
} |
| 784 |
|
| 785 |
@Test |
| 786 |
public void notVeryEnd() { |
| 787 |
Observable.range(1, 2) |
| 788 |
.concatMapDelayError(Functions.justFunction(Observable.error(new TestException())), false, 16, ImmediateThinScheduler.INSTANCE) |
| 789 |
.test() |
| 790 |
.assertFailure(TestException.class); |
| 791 |
} |
| 792 |
|
| 793 |
@Test |
| 794 |
public void error() { |
| 795 |
Observable.error(new TestException()) |
| 796 |
.concatMapDelayError(Functions.justFunction(Observable.just(2)), false, 16, ImmediateThinScheduler.INSTANCE) |
| 797 |
.test() |
| 798 |
.assertFailure(TestException.class); |
| 799 |
} |
| 800 |
|
| 801 |
@Test |
| 802 |
public void mapperThrows() { |
| 803 |
Observable.range(1, 2) |
| 804 |
.concatMap(new Function<Integer, ObservableSource<Object>>() { |
| 805 |
@Override |
| 806 |
public ObservableSource<Object> apply(Integer v) throws Exception { |
| 807 |
throw new TestException(); |
| 808 |
} |
| 809 |
}, 2, ImmediateThinScheduler.INSTANCE) |
| 810 |
.test() |
| 811 |
.assertFailure(TestException.class); |
| 812 |
} |
| 813 |
|
| 814 |
@Test |
| 815 |
public void mainErrors() { |
| 816 |
PublishSubject<Integer> source = PublishSubject.create(); |
| 817 |
|
| 818 |
TestObserver<Integer> to = TestObserver.create(); |
| 819 |
|
| 820 |
source.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 821 |
@Override |
| 822 |
public Observable<Integer> apply(Integer v) { |
| 823 |
return Observable.range(v, 2); |
| 824 |
} |
| 825 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 826 |
|
| 827 |
source.onNext(1); |
| 828 |
source.onNext(2); |
| 829 |
source.onError(new TestException()); |
| 830 |
|
| 831 |
to.assertValues(1, 2, 2, 3); |
| 832 |
to.assertError(TestException.class); |
| 833 |
to.assertNotComplete(); |
| 834 |
} |
| 835 |
|
| 836 |
@Test |
| 837 |
public void innerErrors() { |
| 838 |
final Observable<Integer> inner = Observable.range(1, 2) |
| 839 |
.concatWith(Observable.<Integer>error(new TestException())); |
| 840 |
|
| 841 |
TestObserver<Integer> to = TestObserver.create(); |
| 842 |
|
| 843 |
Observable.range(1, 3).concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 844 |
@Override |
| 845 |
public Observable<Integer> apply(Integer v) { |
| 846 |
return inner; |
| 847 |
} |
| 848 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 849 |
|
| 850 |
to.assertValues(1, 2, 1, 2, 1, 2); |
| 851 |
to.assertError(CompositeException.class); |
| 852 |
to.assertNotComplete(); |
| 853 |
} |
| 854 |
|
| 855 |
@Test |
| 856 |
public void singleInnerErrors() { |
| 857 |
final Observable<Integer> inner = Observable.range(1, 2).concatWith(Observable.<Integer>error(new TestException())); |
| 858 |
|
| 859 |
TestObserver<Integer> to = TestObserver.create(); |
| 860 |
|
| 861 |
Observable.just(1) |
| 862 |
.hide() // prevent scalar optimization |
| 863 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 864 |
@Override |
| 865 |
public Observable<Integer> apply(Integer v) { |
| 866 |
return inner; |
| 867 |
} |
| 868 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 869 |
|
| 870 |
to.assertValues(1, 2); |
| 871 |
to.assertError(TestException.class); |
| 872 |
to.assertNotComplete(); |
| 873 |
} |
| 874 |
|
| 875 |
@Test |
| 876 |
public void innerNull() { |
| 877 |
TestObserver<Integer> to = TestObserver.create(); |
| 878 |
|
| 879 |
Observable.just(1) |
| 880 |
.hide() // prevent scalar optimization |
| 881 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 882 |
@Override |
| 883 |
public Observable<Integer> apply(Integer v) { |
| 884 |
return null; |
| 885 |
} |
| 886 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 887 |
|
| 888 |
to.assertNoValues(); |
| 889 |
to.assertError(NullPointerException.class); |
| 890 |
to.assertNotComplete(); |
| 891 |
} |
| 892 |
|
| 893 |
@Test |
| 894 |
public void innerThrows() { |
| 895 |
TestObserver<Integer> to = TestObserver.create(); |
| 896 |
|
| 897 |
Observable.just(1) |
| 898 |
.hide() // prevent scalar optimization |
| 899 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 900 |
@Override |
| 901 |
public Observable<Integer> apply(Integer v) { |
| 902 |
throw new TestException(); |
| 903 |
} |
| 904 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 905 |
|
| 906 |
to.assertNoValues(); |
| 907 |
to.assertError(TestException.class); |
| 908 |
to.assertNotComplete(); |
| 909 |
} |
| 910 |
|
| 911 |
@Test |
| 912 |
public void innerWithEmpty() { |
| 913 |
TestObserver<Integer> to = TestObserver.create(); |
| 914 |
|
| 915 |
Observable.range(1, 3) |
| 916 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 917 |
@Override |
| 918 |
public Observable<Integer> apply(Integer v) { |
| 919 |
return v == 2 ? Observable.<Integer>empty() : Observable.range(1, 2); |
| 920 |
} |
| 921 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 922 |
|
| 923 |
to.assertValues(1, 2, 1, 2); |
| 924 |
to.assertNoErrors(); |
| 925 |
to.assertComplete(); |
| 926 |
} |
| 927 |
|
| 928 |
@Test |
| 929 |
public void innerWithScalar() { |
| 930 |
TestObserver<Integer> to = TestObserver.create(); |
| 931 |
|
| 932 |
Observable.range(1, 3) |
| 933 |
.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 934 |
@Override |
| 935 |
public Observable<Integer> apply(Integer v) { |
| 936 |
return v == 2 ? Observable.just(3) : Observable.range(1, 2); |
| 937 |
} |
| 938 |
}, true, 2, ImmediateThinScheduler.INSTANCE).subscribe(to); |
| 939 |
|
| 940 |
to.assertValues(1, 2, 3, 1, 2); |
| 941 |
to.assertNoErrors(); |
| 942 |
to.assertComplete(); |
| 943 |
} |
| 944 |
|
| 945 |
@Test |
| 946 |
public void mapperScheduledLong() { |
| 947 |
TestObserver<String> to = Observable.range(1, 1000) |
| 948 |
.hide() |
| 949 |
.observeOn(Schedulers.computation()) |
| 950 |
.concatMap(new Function<Integer, Observable<String>>() { |
| 951 |
@Override |
| 952 |
public Observable<String> apply(Integer t) throws Throwable { |
| 953 |
return Observable.just(Thread.currentThread().getName()) |
| 954 |
.repeat(1000) |
| 955 |
.observeOn(Schedulers.io()); |
| 956 |
} |
| 957 |
}, 2, Schedulers.single()) |
| 958 |
.distinct() |
| 959 |
.test() |
| 960 |
.awaitDone(5, TimeUnit.SECONDS) |
| 961 |
.assertValueCount(1) |
| 962 |
.assertNoErrors() |
| 963 |
.assertComplete(); |
| 964 |
|
| 965 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 966 |
} |
| 967 |
|
| 968 |
@Test |
| 969 |
public void mapperDelayErrorScheduledLong() { |
| 970 |
TestObserver<String> to = Observable.range(1, 1000) |
| 971 |
.hide() |
| 972 |
.observeOn(Schedulers.computation()) |
| 973 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 974 |
@Override |
| 975 |
public Observable<String> apply(Integer t) throws Throwable { |
| 976 |
return Observable.just(Thread.currentThread().getName()) |
| 977 |
.repeat(1000) |
| 978 |
.observeOn(Schedulers.io()); |
| 979 |
} |
| 980 |
}, false, 2, Schedulers.single()) |
| 981 |
.distinct() |
| 982 |
.test() |
| 983 |
.awaitDone(5, TimeUnit.SECONDS) |
| 984 |
.assertValueCount(1) |
| 985 |
.assertNoErrors() |
| 986 |
.assertComplete(); |
| 987 |
|
| 988 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 989 |
} |
| 990 |
|
| 991 |
@Test |
| 992 |
public void mapperDelayError2ScheduledLong() { |
| 993 |
TestObserver<String> to = Observable.range(1, 1000) |
| 994 |
.hide() |
| 995 |
.observeOn(Schedulers.computation()) |
| 996 |
.concatMapDelayError(new Function<Integer, Observable<String>>() { |
| 997 |
@Override |
| 998 |
public Observable<String> apply(Integer t) throws Throwable { |
| 999 |
return Observable.just(Thread.currentThread().getName()) |
| 1000 |
.repeat(1000) |
| 1001 |
.observeOn(Schedulers.io()); |
| 1002 |
} |
| 1003 |
}, true, 2, Schedulers.single()) |
| 1004 |
.distinct() |
| 1005 |
.test() |
| 1006 |
.awaitDone(5, TimeUnit.SECONDS) |
| 1007 |
.assertValueCount(1) |
| 1008 |
.assertNoErrors() |
| 1009 |
.assertComplete(); |
| 1010 |
|
| 1011 |
assertTrue(to.values().toString(), to.values().get(0).startsWith("RxSingleScheduler-")); |
| 1012 |
} |
| 1013 |
|
| 1014 |
@Test |
| 1015 |
public void undeliverableUponCancel() { |
| 1016 |
TestHelper.checkUndeliverableUponCancel(new ObservableConverter<Integer, Observable<Integer>>() { |
| 1017 |
@Override |
| 1018 |
public Observable<Integer> apply(Observable<Integer> upstream) { |
| 1019 |
return upstream.concatMap(new Function<Integer, Observable<Integer>>() { |
| 1020 |
@Override |
| 1021 |
public Observable<Integer> apply(Integer v) throws Throwable { |
| 1022 |
return Observable.just(v).hide(); |
| 1023 |
} |
| 1024 |
}, 2, ImmediateThinScheduler.INSTANCE); |
| 1025 |
} |
| 1026 |
}); |
| 1027 |
} |
| 1028 |
|
| 1029 |
@Test |
| 1030 |
public void undeliverableUponCancelDelayError() { |
| 1031 |
TestHelper.checkUndeliverableUponCancel(new ObservableConverter<Integer, Observable<Integer>>() { |
| 1032 |
@Override |
| 1033 |
public Observable<Integer> apply(Observable<Integer> upstream) { |
| 1034 |
return upstream.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 1035 |
@Override |
| 1036 |
public Observable<Integer> apply(Integer v) throws Throwable { |
| 1037 |
return Observable.just(v).hide(); |
| 1038 |
} |
| 1039 |
}, false, 2, ImmediateThinScheduler.INSTANCE); |
| 1040 |
} |
| 1041 |
}); |
| 1042 |
} |
| 1043 |
|
| 1044 |
@Test |
| 1045 |
public void undeliverableUponCancelDelayErrorTillEnd() { |
| 1046 |
TestHelper.checkUndeliverableUponCancel(new ObservableConverter<Integer, Observable<Integer>>() { |
| 1047 |
@Override |
| 1048 |
public Observable<Integer> apply(Observable<Integer> upstream) { |
| 1049 |
return upstream.concatMapDelayError(new Function<Integer, Observable<Integer>>() { |
| 1050 |
@Override |
| 1051 |
public Observable<Integer> apply(Integer v) throws Throwable { |
| 1052 |
return Observable.just(v).hide(); |
| 1053 |
} |
| 1054 |
}, true, 2, ImmediateThinScheduler.INSTANCE); |
| 1055 |
} |
| 1056 |
}); |
| 1057 |
} |
| 1058 |
|
| 1059 |
@Test |
| 1060 |
public void fusionRejected() { |
| 1061 |
TestObserverEx<Object> to = new TestObserverEx<>(); |
| 1062 |
|
| 1063 |
TestHelper.rejectObservableFusion() |
| 1064 |
.concatMap(v -> Observable.never(), 2, ImmediateThinScheduler.INSTANCE) |
| 1065 |
.subscribe(to); |
| 1066 |
} |
| 1067 |
|
| 1068 |
@Test |
| 1069 |
public void fusionRejectedDelayErrorr() { |
| 1070 |
TestObserverEx<Object> to = new TestObserverEx<>(); |
| 1071 |
|
| 1072 |
TestHelper.rejectObservableFusion() |
| 1073 |
.concatMapDelayError(v -> Observable.never(), true, 2, ImmediateThinScheduler.INSTANCE) |
| 1074 |
.subscribe(to); |
| 1075 |
} |
| 1076 |
|
| 1077 |
@Test |
| 1078 |
public void scalarInnerJustDisposeDelayError() { |
| 1079 |
TestObserver<Integer> to = new TestObserver<>(); |
| 1080 |
|
| 1081 |
Observable.just(1) |
| 1082 |
.hide() |
| 1083 |
.concatMapDelayError(v -> Observable.fromCallable(() -> { |
| 1084 |
to.dispose(); |
| 1085 |
return 1; |
| 1086 |
}), true, 2, ImmediateThinScheduler.INSTANCE) |
| 1087 |
.subscribe(to); |
| 1088 |
|
| 1089 |
to.assertEmpty(); |
| 1090 |
} |
| 1091 |
|
| 1092 |
static final class EmptyDisposingObservable extends Observable<Object> |
| 1093 |
implements Supplier<Object> { |
| 1094 |
final TestObserver<Object> to; |
| 1095 |
EmptyDisposingObservable(TestObserver<Object> to) { |
| 1096 |
this.to = to; |
| 1097 |
} |
| 1098 |
|
| 1099 |
@Override |
| 1100 |
protected void subscribeActual(@NonNull Observer<? super @NonNull Object> observer) { |
| 1101 |
EmptyDisposable.complete(observer); |
| 1102 |
} |
| 1103 |
|
| 1104 |
@Override |
| 1105 |
public @NonNull Object get() throws Throwable { |
| 1106 |
to.dispose(); |
| 1107 |
return null; |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
@Test |
| 1112 |
public void scalarInnerEmptyDisposeDelayError() { |
| 1113 |
TestObserver<Object> to = new TestObserver<>(); |
| 1114 |
|
| 1115 |
Observable.just(1) |
| 1116 |
.hide() |
| 1117 |
.concatMapDelayError(v -> new EmptyDisposingObservable(to), |
| 1118 |
true, 2, ImmediateThinScheduler.INSTANCE |
| 1119 |
) |
| 1120 |
.subscribe(to); |
| 1121 |
|
| 1122 |
to.assertEmpty(); |
| 1123 |
} |
| 1124 |
} |