| 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.flowable; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
import static org.mockito.ArgumentMatchers.*; |
| 18 |
import static org.mockito.Mockito.*; |
| 19 |
|
| 20 |
import java.util.*; |
| 21 |
import java.util.concurrent.*; |
| 22 |
import java.util.concurrent.atomic.*; |
| 23 |
|
| 24 |
import org.junit.*; |
| 25 |
import org.mockito.InOrder; |
| 26 |
import org.reactivestreams.*; |
| 27 |
|
| 28 |
import io.reactivex.rxjava3.core.*; |
| 29 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 30 |
import io.reactivex.rxjava3.functions.*; |
| 31 |
import io.reactivex.rxjava3.internal.functions.Functions; |
| 32 |
import io.reactivex.rxjava3.processors.PublishProcessor; |
| 33 |
import io.reactivex.rxjava3.schedulers.*; |
| 34 |
import io.reactivex.rxjava3.subscribers.*; |
| 35 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 36 |
|
| 37 |
public class FlowableDelayTest extends RxJavaTest { |
| 38 |
private Subscriber<Long> subscriber; |
| 39 |
private Subscriber<Long> subscriber2; |
| 40 |
|
| 41 |
private TestScheduler scheduler; |
| 42 |
|
| 43 |
@Before |
| 44 |
public void before() { |
| 45 |
subscriber = TestHelper.mockSubscriber(); |
| 46 |
subscriber2 = TestHelper.mockSubscriber(); |
| 47 |
|
| 48 |
scheduler = new TestScheduler(); |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
public void delay() { |
| 53 |
Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); |
| 54 |
Flowable<Long> delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); |
| 55 |
delayed.subscribe(subscriber); |
| 56 |
|
| 57 |
InOrder inOrder = inOrder(subscriber); |
| 58 |
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); |
| 59 |
verify(subscriber, never()).onNext(anyLong()); |
| 60 |
verify(subscriber, never()).onComplete(); |
| 61 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 62 |
|
| 63 |
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); |
| 64 |
inOrder.verify(subscriber, times(1)).onNext(0L); |
| 65 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 66 |
verify(subscriber, never()).onComplete(); |
| 67 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 68 |
|
| 69 |
scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS); |
| 70 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 71 |
verify(subscriber, never()).onComplete(); |
| 72 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 73 |
|
| 74 |
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); |
| 75 |
inOrder.verify(subscriber, times(1)).onNext(1L); |
| 76 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 77 |
verify(subscriber, never()).onComplete(); |
| 78 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 79 |
|
| 80 |
scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS); |
| 81 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 82 |
verify(subscriber, never()).onComplete(); |
| 83 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 84 |
|
| 85 |
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); |
| 86 |
inOrder.verify(subscriber, times(1)).onNext(2L); |
| 87 |
verify(subscriber, times(1)).onComplete(); |
| 88 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 89 |
} |
| 90 |
|
| 91 |
@Test |
| 92 |
public void longDelay() { |
| 93 |
Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); |
| 94 |
Flowable<Long> delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); |
| 95 |
delayed.subscribe(subscriber); |
| 96 |
|
| 97 |
InOrder inOrder = inOrder(subscriber); |
| 98 |
|
| 99 |
scheduler.advanceTimeTo(5999L, TimeUnit.MILLISECONDS); |
| 100 |
verify(subscriber, never()).onNext(anyLong()); |
| 101 |
verify(subscriber, never()).onComplete(); |
| 102 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 103 |
|
| 104 |
scheduler.advanceTimeTo(6000L, TimeUnit.MILLISECONDS); |
| 105 |
inOrder.verify(subscriber, times(1)).onNext(0L); |
| 106 |
scheduler.advanceTimeTo(6999L, TimeUnit.MILLISECONDS); |
| 107 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 108 |
scheduler.advanceTimeTo(7000L, TimeUnit.MILLISECONDS); |
| 109 |
inOrder.verify(subscriber, times(1)).onNext(1L); |
| 110 |
scheduler.advanceTimeTo(7999L, TimeUnit.MILLISECONDS); |
| 111 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 112 |
scheduler.advanceTimeTo(8000L, TimeUnit.MILLISECONDS); |
| 113 |
inOrder.verify(subscriber, times(1)).onNext(2L); |
| 114 |
inOrder.verify(subscriber, times(1)).onComplete(); |
| 115 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 116 |
inOrder.verify(subscriber, never()).onComplete(); |
| 117 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 118 |
} |
| 119 |
|
| 120 |
@Test |
| 121 |
public void delayWithError() { |
| 122 |
Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler) |
| 123 |
.map(new Function<Long, Long>() { |
| 124 |
@Override |
| 125 |
public Long apply(Long value) { |
| 126 |
if (value == 1L) { |
| 127 |
throw new RuntimeException("error!"); |
| 128 |
} |
| 129 |
return value; |
| 130 |
} |
| 131 |
}); |
| 132 |
Flowable<Long> delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); |
| 133 |
delayed.subscribe(subscriber); |
| 134 |
|
| 135 |
InOrder inOrder = inOrder(subscriber); |
| 136 |
|
| 137 |
scheduler.advanceTimeTo(1999L, TimeUnit.MILLISECONDS); |
| 138 |
verify(subscriber, never()).onNext(anyLong()); |
| 139 |
verify(subscriber, never()).onComplete(); |
| 140 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 141 |
|
| 142 |
scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS); |
| 143 |
inOrder.verify(subscriber, times(1)).onError(any(Throwable.class)); |
| 144 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 145 |
verify(subscriber, never()).onComplete(); |
| 146 |
|
| 147 |
scheduler.advanceTimeTo(5000L, TimeUnit.MILLISECONDS); |
| 148 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 149 |
inOrder.verify(subscriber, never()).onError(any(Throwable.class)); |
| 150 |
verify(subscriber, never()).onComplete(); |
| 151 |
} |
| 152 |
|
| 153 |
@Test |
| 154 |
public void delayWithMultipleSubscriptions() { |
| 155 |
Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); |
| 156 |
Flowable<Long> delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); |
| 157 |
delayed.subscribe(subscriber); |
| 158 |
delayed.subscribe(subscriber2); |
| 159 |
|
| 160 |
InOrder inOrder = inOrder(subscriber); |
| 161 |
InOrder inOrder2 = inOrder(subscriber2); |
| 162 |
|
| 163 |
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); |
| 164 |
verify(subscriber, never()).onNext(anyLong()); |
| 165 |
verify(subscriber2, never()).onNext(anyLong()); |
| 166 |
|
| 167 |
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); |
| 168 |
inOrder.verify(subscriber, times(1)).onNext(0L); |
| 169 |
inOrder2.verify(subscriber2, times(1)).onNext(0L); |
| 170 |
|
| 171 |
scheduler.advanceTimeTo(2499L, TimeUnit.MILLISECONDS); |
| 172 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 173 |
inOrder2.verify(subscriber2, never()).onNext(anyLong()); |
| 174 |
|
| 175 |
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); |
| 176 |
inOrder.verify(subscriber, times(1)).onNext(1L); |
| 177 |
inOrder2.verify(subscriber2, times(1)).onNext(1L); |
| 178 |
|
| 179 |
verify(subscriber, never()).onComplete(); |
| 180 |
verify(subscriber2, never()).onComplete(); |
| 181 |
|
| 182 |
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); |
| 183 |
inOrder.verify(subscriber, times(1)).onNext(2L); |
| 184 |
inOrder2.verify(subscriber2, times(1)).onNext(2L); |
| 185 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 186 |
inOrder2.verify(subscriber2, never()).onNext(anyLong()); |
| 187 |
inOrder.verify(subscriber, times(1)).onComplete(); |
| 188 |
inOrder2.verify(subscriber2, times(1)).onComplete(); |
| 189 |
|
| 190 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 191 |
verify(subscriber2, never()).onError(any(Throwable.class)); |
| 192 |
} |
| 193 |
|
| 194 |
@Test |
| 195 |
public void delaySubscription() { |
| 196 |
Flowable<Integer> result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); |
| 197 |
|
| 198 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 199 |
InOrder inOrder = inOrder(subscriber); |
| 200 |
|
| 201 |
result.subscribe(subscriber); |
| 202 |
|
| 203 |
inOrder.verify(subscriber, never()).onNext(any()); |
| 204 |
inOrder.verify(subscriber, never()).onComplete(); |
| 205 |
|
| 206 |
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); |
| 207 |
|
| 208 |
inOrder.verify(subscriber, times(1)).onNext(1); |
| 209 |
inOrder.verify(subscriber, times(1)).onNext(2); |
| 210 |
inOrder.verify(subscriber, times(1)).onNext(3); |
| 211 |
inOrder.verify(subscriber, times(1)).onComplete(); |
| 212 |
|
| 213 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 214 |
} |
| 215 |
|
| 216 |
@Test |
| 217 |
public void delaySubscriptionCancelBeforeTime() { |
| 218 |
Flowable<Integer> result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); |
| 219 |
|
| 220 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 221 |
TestSubscriber<Object> ts = new TestSubscriber<>(subscriber); |
| 222 |
|
| 223 |
result.subscribe(ts); |
| 224 |
ts.cancel(); |
| 225 |
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); |
| 226 |
|
| 227 |
verify(subscriber, never()).onNext(any()); |
| 228 |
verify(subscriber, never()).onComplete(); |
| 229 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 230 |
} |
| 231 |
|
| 232 |
@Test |
| 233 |
public void delayWithFlowableNormal1() { |
| 234 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 235 |
final List<PublishProcessor<Integer>> delays = new ArrayList<>(); |
| 236 |
final int n = 10; |
| 237 |
for (int i = 0; i < n; i++) { |
| 238 |
PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 239 |
delays.add(delay); |
| 240 |
} |
| 241 |
|
| 242 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 243 |
@Override |
| 244 |
public Flowable<Integer> apply(Integer t1) { |
| 245 |
return delays.get(t1); |
| 246 |
} |
| 247 |
}; |
| 248 |
|
| 249 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 250 |
InOrder inOrder = inOrder(subscriber); |
| 251 |
|
| 252 |
source.delay(delayFunc).subscribe(subscriber); |
| 253 |
|
| 254 |
for (int i = 0; i < n; i++) { |
| 255 |
source.onNext(i); |
| 256 |
delays.get(i).onNext(i); |
| 257 |
inOrder.verify(subscriber).onNext(i); |
| 258 |
} |
| 259 |
source.onComplete(); |
| 260 |
|
| 261 |
inOrder.verify(subscriber).onComplete(); |
| 262 |
inOrder.verifyNoMoreInteractions(); |
| 263 |
|
| 264 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 265 |
} |
| 266 |
|
| 267 |
@Test |
| 268 |
public void delayWithFlowableSingleSend1() { |
| 269 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 270 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 271 |
|
| 272 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 273 |
|
| 274 |
@Override |
| 275 |
public Flowable<Integer> apply(Integer t1) { |
| 276 |
return delay; |
| 277 |
} |
| 278 |
}; |
| 279 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 280 |
InOrder inOrder = inOrder(subscriber); |
| 281 |
|
| 282 |
source.delay(delayFunc).subscribe(subscriber); |
| 283 |
|
| 284 |
source.onNext(1); |
| 285 |
delay.onNext(1); |
| 286 |
delay.onNext(2); |
| 287 |
|
| 288 |
inOrder.verify(subscriber).onNext(1); |
| 289 |
inOrder.verifyNoMoreInteractions(); |
| 290 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 291 |
} |
| 292 |
|
| 293 |
@Test |
| 294 |
public void delayWithFlowableSourceThrows() { |
| 295 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 296 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 297 |
|
| 298 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 299 |
|
| 300 |
@Override |
| 301 |
public Flowable<Integer> apply(Integer t1) { |
| 302 |
return delay; |
| 303 |
} |
| 304 |
}; |
| 305 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 306 |
InOrder inOrder = inOrder(subscriber); |
| 307 |
|
| 308 |
source.delay(delayFunc).subscribe(subscriber); |
| 309 |
source.onNext(1); |
| 310 |
source.onError(new TestException()); |
| 311 |
delay.onNext(1); |
| 312 |
|
| 313 |
inOrder.verify(subscriber).onError(any(TestException.class)); |
| 314 |
inOrder.verifyNoMoreInteractions(); |
| 315 |
verify(subscriber, never()).onNext(any()); |
| 316 |
verify(subscriber, never()).onComplete(); |
| 317 |
} |
| 318 |
|
| 319 |
@Test |
| 320 |
public void delayWithFlowableDelayFunctionThrows() { |
| 321 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 322 |
|
| 323 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 324 |
|
| 325 |
@Override |
| 326 |
public Flowable<Integer> apply(Integer t1) { |
| 327 |
throw new TestException(); |
| 328 |
} |
| 329 |
}; |
| 330 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 331 |
InOrder inOrder = inOrder(subscriber); |
| 332 |
|
| 333 |
source.delay(delayFunc).subscribe(subscriber); |
| 334 |
source.onNext(1); |
| 335 |
|
| 336 |
inOrder.verify(subscriber).onError(any(TestException.class)); |
| 337 |
inOrder.verifyNoMoreInteractions(); |
| 338 |
verify(subscriber, never()).onNext(any()); |
| 339 |
verify(subscriber, never()).onComplete(); |
| 340 |
} |
| 341 |
|
| 342 |
@Test |
| 343 |
public void delayWithFlowableDelayThrows() { |
| 344 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 345 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 346 |
|
| 347 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 348 |
|
| 349 |
@Override |
| 350 |
public Flowable<Integer> apply(Integer t1) { |
| 351 |
return delay; |
| 352 |
} |
| 353 |
}; |
| 354 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 355 |
InOrder inOrder = inOrder(subscriber); |
| 356 |
|
| 357 |
source.delay(delayFunc).subscribe(subscriber); |
| 358 |
source.onNext(1); |
| 359 |
delay.onError(new TestException()); |
| 360 |
|
| 361 |
inOrder.verify(subscriber).onError(any(TestException.class)); |
| 362 |
inOrder.verifyNoMoreInteractions(); |
| 363 |
verify(subscriber, never()).onNext(any()); |
| 364 |
verify(subscriber, never()).onComplete(); |
| 365 |
} |
| 366 |
|
| 367 |
@Test |
| 368 |
public void delayWithFlowableSubscriptionNormal() { |
| 369 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 370 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 371 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 372 |
|
| 373 |
@Override |
| 374 |
public Flowable<Integer> apply(Integer t1) { |
| 375 |
return delay; |
| 376 |
} |
| 377 |
}; |
| 378 |
|
| 379 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 380 |
InOrder inOrder = inOrder(subscriber); |
| 381 |
|
| 382 |
source.delay(delay, delayFunc).subscribe(subscriber); |
| 383 |
|
| 384 |
source.onNext(1); |
| 385 |
delay.onNext(1); |
| 386 |
|
| 387 |
source.onNext(2); |
| 388 |
delay.onNext(2); |
| 389 |
|
| 390 |
inOrder.verify(subscriber).onNext(2); |
| 391 |
inOrder.verifyNoMoreInteractions(); |
| 392 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 393 |
verify(subscriber, never()).onComplete(); |
| 394 |
} |
| 395 |
|
| 396 |
@Test |
| 397 |
public void delayWithFlowableSubscriptionFunctionThrows() { |
| 398 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 399 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 400 |
Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() { |
| 401 |
@Override |
| 402 |
public Flowable<Integer> get() { |
| 403 |
throw new TestException(); |
| 404 |
} |
| 405 |
}; |
| 406 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 407 |
|
| 408 |
@Override |
| 409 |
public Flowable<Integer> apply(Integer t1) { |
| 410 |
return delay; |
| 411 |
} |
| 412 |
}; |
| 413 |
|
| 414 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 415 |
InOrder inOrder = inOrder(subscriber); |
| 416 |
|
| 417 |
source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); |
| 418 |
|
| 419 |
source.onNext(1); |
| 420 |
delay.onNext(1); |
| 421 |
|
| 422 |
source.onNext(2); |
| 423 |
|
| 424 |
inOrder.verify(subscriber).onError(any(TestException.class)); |
| 425 |
inOrder.verifyNoMoreInteractions(); |
| 426 |
verify(subscriber, never()).onNext(any()); |
| 427 |
verify(subscriber, never()).onComplete(); |
| 428 |
} |
| 429 |
|
| 430 |
@Test |
| 431 |
public void delayWithFlowableSubscriptionThrows() { |
| 432 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 433 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 434 |
Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() { |
| 435 |
@Override |
| 436 |
public Flowable<Integer> get() { |
| 437 |
return delay; |
| 438 |
} |
| 439 |
}; |
| 440 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 441 |
|
| 442 |
@Override |
| 443 |
public Flowable<Integer> apply(Integer t1) { |
| 444 |
return delay; |
| 445 |
} |
| 446 |
}; |
| 447 |
|
| 448 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 449 |
InOrder inOrder = inOrder(subscriber); |
| 450 |
|
| 451 |
source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); |
| 452 |
|
| 453 |
source.onNext(1); |
| 454 |
delay.onError(new TestException()); |
| 455 |
|
| 456 |
source.onNext(2); |
| 457 |
|
| 458 |
inOrder.verify(subscriber).onError(any(TestException.class)); |
| 459 |
inOrder.verifyNoMoreInteractions(); |
| 460 |
verify(subscriber, never()).onNext(any()); |
| 461 |
verify(subscriber, never()).onComplete(); |
| 462 |
} |
| 463 |
|
| 464 |
@Test |
| 465 |
public void delayWithFlowableEmptyDelayer() { |
| 466 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 467 |
|
| 468 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 469 |
|
| 470 |
@Override |
| 471 |
public Flowable<Integer> apply(Integer t1) { |
| 472 |
return Flowable.empty(); |
| 473 |
} |
| 474 |
}; |
| 475 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 476 |
InOrder inOrder = inOrder(subscriber); |
| 477 |
|
| 478 |
source.delay(delayFunc).subscribe(subscriber); |
| 479 |
|
| 480 |
source.onNext(1); |
| 481 |
source.onComplete(); |
| 482 |
|
| 483 |
inOrder.verify(subscriber).onNext(1); |
| 484 |
inOrder.verify(subscriber).onComplete(); |
| 485 |
inOrder.verifyNoMoreInteractions(); |
| 486 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 487 |
} |
| 488 |
|
| 489 |
@Test |
| 490 |
public void delayWithFlowableSubscriptionRunCompletion() { |
| 491 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 492 |
final PublishProcessor<Integer> sdelay = PublishProcessor.create(); |
| 493 |
final PublishProcessor<Integer> delay = PublishProcessor.create(); |
| 494 |
Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() { |
| 495 |
@Override |
| 496 |
public Flowable<Integer> get() { |
| 497 |
return sdelay; |
| 498 |
} |
| 499 |
}; |
| 500 |
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() { |
| 501 |
|
| 502 |
@Override |
| 503 |
public Flowable<Integer> apply(Integer t1) { |
| 504 |
return delay; |
| 505 |
} |
| 506 |
}; |
| 507 |
|
| 508 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 509 |
InOrder inOrder = inOrder(subscriber); |
| 510 |
|
| 511 |
source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber); |
| 512 |
|
| 513 |
source.onNext(1); |
| 514 |
sdelay.onComplete(); |
| 515 |
|
| 516 |
source.onNext(2); |
| 517 |
delay.onNext(2); |
| 518 |
|
| 519 |
inOrder.verify(subscriber).onNext(2); |
| 520 |
inOrder.verifyNoMoreInteractions(); |
| 521 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 522 |
verify(subscriber, never()).onComplete(); |
| 523 |
} |
| 524 |
|
| 525 |
@Test |
| 526 |
public void delayWithFlowableAsTimed() { |
| 527 |
Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); |
| 528 |
|
| 529 |
final Flowable<Long> delayer = Flowable.timer(500L, TimeUnit.MILLISECONDS, scheduler); |
| 530 |
|
| 531 |
Function<Long, Flowable<Long>> delayFunc = new Function<Long, Flowable<Long>>() { |
| 532 |
@Override |
| 533 |
public Flowable<Long> apply(Long t1) { |
| 534 |
return delayer; |
| 535 |
} |
| 536 |
}; |
| 537 |
|
| 538 |
Flowable<Long> delayed = source.delay(delayFunc); |
| 539 |
delayed.subscribe(subscriber); |
| 540 |
|
| 541 |
InOrder inOrder = inOrder(subscriber); |
| 542 |
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); |
| 543 |
verify(subscriber, never()).onNext(anyLong()); |
| 544 |
verify(subscriber, never()).onComplete(); |
| 545 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 546 |
|
| 547 |
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS); |
| 548 |
inOrder.verify(subscriber, times(1)).onNext(0L); |
| 549 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 550 |
verify(subscriber, never()).onComplete(); |
| 551 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 552 |
|
| 553 |
scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS); |
| 554 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 555 |
verify(subscriber, never()).onComplete(); |
| 556 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 557 |
|
| 558 |
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS); |
| 559 |
inOrder.verify(subscriber, times(1)).onNext(1L); |
| 560 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 561 |
verify(subscriber, never()).onComplete(); |
| 562 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 563 |
|
| 564 |
scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS); |
| 565 |
inOrder.verify(subscriber, never()).onNext(anyLong()); |
| 566 |
verify(subscriber, never()).onComplete(); |
| 567 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 568 |
|
| 569 |
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS); |
| 570 |
inOrder.verify(subscriber, times(1)).onNext(2L); |
| 571 |
verify(subscriber, times(1)).onComplete(); |
| 572 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 573 |
} |
| 574 |
|
| 575 |
@Test |
| 576 |
public void delayWithFlowableReorder() { |
| 577 |
int n = 3; |
| 578 |
|
| 579 |
PublishProcessor<Integer> source = PublishProcessor.create(); |
| 580 |
final List<PublishProcessor<Integer>> subjects = new ArrayList<>(); |
| 581 |
for (int i = 0; i < n; i++) { |
| 582 |
subjects.add(PublishProcessor.<Integer> create()); |
| 583 |
} |
| 584 |
|
| 585 |
Flowable<Integer> result = source.delay(new Function<Integer, Flowable<Integer>>() { |
| 586 |
|
| 587 |
@Override |
| 588 |
public Flowable<Integer> apply(Integer t1) { |
| 589 |
return subjects.get(t1); |
| 590 |
} |
| 591 |
}); |
| 592 |
|
| 593 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 594 |
InOrder inOrder = inOrder(subscriber); |
| 595 |
|
| 596 |
result.subscribe(subscriber); |
| 597 |
|
| 598 |
for (int i = 0; i < n; i++) { |
| 599 |
source.onNext(i); |
| 600 |
} |
| 601 |
source.onComplete(); |
| 602 |
|
| 603 |
inOrder.verify(subscriber, never()).onNext(anyInt()); |
| 604 |
inOrder.verify(subscriber, never()).onComplete(); |
| 605 |
|
| 606 |
for (int i = n - 1; i >= 0; i--) { |
| 607 |
subjects.get(i).onComplete(); |
| 608 |
inOrder.verify(subscriber).onNext(i); |
| 609 |
} |
| 610 |
|
| 611 |
inOrder.verify(subscriber).onComplete(); |
| 612 |
|
| 613 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 614 |
} |
| 615 |
|
| 616 |
@Test |
| 617 |
public void delayEmitsEverything() { |
| 618 |
Flowable<Integer> source = Flowable.range(1, 5); |
| 619 |
Flowable<Integer> delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); |
| 620 |
delayed = delayed.doOnEach(new Consumer<Notification<Integer>>() { |
| 621 |
|
| 622 |
@Override |
| 623 |
public void accept(Notification<Integer> t1) { |
| 624 |
System.out.println(t1); |
| 625 |
} |
| 626 |
|
| 627 |
}); |
| 628 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 629 |
delayed.subscribe(ts); |
| 630 |
// all will be delivered after 500ms since range does not delay between them |
| 631 |
scheduler.advanceTimeBy(500L, TimeUnit.MILLISECONDS); |
| 632 |
ts.assertValues(1, 2, 3, 4, 5); |
| 633 |
} |
| 634 |
|
| 635 |
@Test |
| 636 |
public void backpressureWithTimedDelay() { |
| 637 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 638 |
Flowable.range(1, Flowable.bufferSize() * 2) |
| 639 |
.delay(100, TimeUnit.MILLISECONDS) |
| 640 |
.observeOn(Schedulers.computation()) |
| 641 |
.map(new Function<Integer, Integer>() { |
| 642 |
|
| 643 |
int c; |
| 644 |
|
| 645 |
@Override |
| 646 |
public Integer apply(Integer t) { |
| 647 |
if (c++ <= 0) { |
| 648 |
try { |
| 649 |
Thread.sleep(500); |
| 650 |
} catch (InterruptedException e) { |
| 651 |
} |
| 652 |
} |
| 653 |
return t; |
| 654 |
} |
| 655 |
|
| 656 |
}).subscribe(ts); |
| 657 |
|
| 658 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 659 |
ts.assertNoErrors(); |
| 660 |
assertEquals(Flowable.bufferSize() * 2, ts.values().size()); |
| 661 |
} |
| 662 |
|
| 663 |
@Test |
| 664 |
public void backpressureWithSubscriptionTimedDelay() { |
| 665 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 666 |
Flowable.range(1, Flowable.bufferSize() * 2) |
| 667 |
.delaySubscription(100, TimeUnit.MILLISECONDS) |
| 668 |
.delay(100, TimeUnit.MILLISECONDS) |
| 669 |
.observeOn(Schedulers.computation()) |
| 670 |
.map(new Function<Integer, Integer>() { |
| 671 |
|
| 672 |
int c; |
| 673 |
|
| 674 |
@Override |
| 675 |
public Integer apply(Integer t) { |
| 676 |
if (c++ <= 0) { |
| 677 |
try { |
| 678 |
Thread.sleep(500); |
| 679 |
} catch (InterruptedException e) { |
| 680 |
} |
| 681 |
} |
| 682 |
return t; |
| 683 |
} |
| 684 |
|
| 685 |
}).subscribe(ts); |
| 686 |
|
| 687 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 688 |
ts.assertNoErrors(); |
| 689 |
assertEquals(Flowable.bufferSize() * 2, ts.values().size()); |
| 690 |
} |
| 691 |
|
| 692 |
@Test |
| 693 |
public void backpressureWithSelectorDelay() { |
| 694 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 695 |
Flowable.range(1, Flowable.bufferSize() * 2) |
| 696 |
.delay(new Function<Integer, Flowable<Long>>() { |
| 697 |
|
| 698 |
@Override |
| 699 |
public Flowable<Long> apply(Integer i) { |
| 700 |
return Flowable.timer(100, TimeUnit.MILLISECONDS); |
| 701 |
} |
| 702 |
|
| 703 |
}) |
| 704 |
.observeOn(Schedulers.computation()) |
| 705 |
.map(new Function<Integer, Integer>() { |
| 706 |
|
| 707 |
int c; |
| 708 |
|
| 709 |
@Override |
| 710 |
public Integer apply(Integer t) { |
| 711 |
if (c++ <= 0) { |
| 712 |
try { |
| 713 |
Thread.sleep(500); |
| 714 |
} catch (InterruptedException e) { |
| 715 |
} |
| 716 |
} |
| 717 |
return t; |
| 718 |
} |
| 719 |
|
| 720 |
}).subscribe(ts); |
| 721 |
|
| 722 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 723 |
ts.assertNoErrors(); |
| 724 |
assertEquals(Flowable.bufferSize() * 2, ts.values().size()); |
| 725 |
} |
| 726 |
|
| 727 |
@Test |
| 728 |
public void backpressureWithSelectorDelayAndSubscriptionDelay() { |
| 729 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 730 |
Flowable.range(1, Flowable.bufferSize() * 2) |
| 731 |
.delay(Flowable.defer(new Supplier<Flowable<Long>>() { |
| 732 |
|
| 733 |
@Override |
| 734 |
public Flowable<Long> get() { |
| 735 |
return Flowable.timer(500, TimeUnit.MILLISECONDS); |
| 736 |
} |
| 737 |
}), new Function<Integer, Flowable<Long>>() { |
| 738 |
|
| 739 |
@Override |
| 740 |
public Flowable<Long> apply(Integer i) { |
| 741 |
return Flowable.timer(100, TimeUnit.MILLISECONDS); |
| 742 |
} |
| 743 |
|
| 744 |
}) |
| 745 |
.observeOn(Schedulers.computation()) |
| 746 |
.map(new Function<Integer, Integer>() { |
| 747 |
|
| 748 |
int c; |
| 749 |
|
| 750 |
@Override |
| 751 |
public Integer apply(Integer t) { |
| 752 |
if (c++ <= 0) { |
| 753 |
try { |
| 754 |
Thread.sleep(500); |
| 755 |
} catch (InterruptedException e) { |
| 756 |
} |
| 757 |
} |
| 758 |
return t; |
| 759 |
} |
| 760 |
|
| 761 |
}).subscribe(ts); |
| 762 |
|
| 763 |
ts.awaitDone(5, TimeUnit.SECONDS); |
| 764 |
ts.assertNoErrors(); |
| 765 |
assertEquals(Flowable.bufferSize() * 2, ts.values().size()); |
| 766 |
} |
| 767 |
|
| 768 |
@Test |
| 769 |
public void errorRunsBeforeOnNext() { |
| 770 |
TestScheduler test = new TestScheduler(); |
| 771 |
|
| 772 |
PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 773 |
|
| 774 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 775 |
|
| 776 |
pp.delay(1, TimeUnit.SECONDS, test).subscribe(ts); |
| 777 |
|
| 778 |
pp.onNext(1); |
| 779 |
|
| 780 |
test.advanceTimeBy(500, TimeUnit.MILLISECONDS); |
| 781 |
|
| 782 |
pp.onError(new TestException()); |
| 783 |
|
| 784 |
test.advanceTimeBy(1, TimeUnit.SECONDS); |
| 785 |
|
| 786 |
ts.assertNoValues(); |
| 787 |
ts.assertError(TestException.class); |
| 788 |
ts.assertNotComplete(); |
| 789 |
} |
| 790 |
|
| 791 |
@Test |
| 792 |
public void delaySupplierSimple() { |
| 793 |
final PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 794 |
|
| 795 |
Flowable<Integer> source = Flowable.range(1, 5); |
| 796 |
|
| 797 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 798 |
|
| 799 |
source.delaySubscription(Flowable.defer(new Supplier<Publisher<Integer>>() { |
| 800 |
@Override |
| 801 |
public Publisher<Integer> get() { |
| 802 |
return pp; |
| 803 |
} |
| 804 |
})).subscribe(ts); |
| 805 |
|
| 806 |
ts.assertNoValues(); |
| 807 |
ts.assertNoErrors(); |
| 808 |
ts.assertNotComplete(); |
| 809 |
|
| 810 |
pp.onNext(1); |
| 811 |
|
| 812 |
ts.assertValues(1, 2, 3, 4, 5); |
| 813 |
ts.assertComplete(); |
| 814 |
ts.assertNoErrors(); |
| 815 |
} |
| 816 |
|
| 817 |
@Test |
| 818 |
public void delaySupplierCompletes() { |
| 819 |
final PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 820 |
|
| 821 |
Flowable<Integer> source = Flowable.range(1, 5); |
| 822 |
|
| 823 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 824 |
|
| 825 |
source.delaySubscription(Flowable.defer(new Supplier<Publisher<Integer>>() { |
| 826 |
@Override |
| 827 |
public Publisher<Integer> get() { |
| 828 |
return pp; |
| 829 |
} |
| 830 |
})).subscribe(ts); |
| 831 |
|
| 832 |
ts.assertNoValues(); |
| 833 |
ts.assertNoErrors(); |
| 834 |
ts.assertNotComplete(); |
| 835 |
|
| 836 |
// FIXME should this complete the source instead of consuming it? |
| 837 |
pp.onComplete(); |
| 838 |
|
| 839 |
ts.assertValues(1, 2, 3, 4, 5); |
| 840 |
ts.assertComplete(); |
| 841 |
ts.assertNoErrors(); |
| 842 |
} |
| 843 |
|
| 844 |
@Test |
| 845 |
public void delaySupplierErrors() { |
| 846 |
final PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 847 |
|
| 848 |
Flowable<Integer> source = Flowable.range(1, 5); |
| 849 |
|
| 850 |
TestSubscriber<Integer> ts = new TestSubscriber<>(); |
| 851 |
|
| 852 |
source.delaySubscription(Flowable.defer(new Supplier<Publisher<Integer>>() { |
| 853 |
@Override |
| 854 |
public Publisher<Integer> get() { |
| 855 |
return pp; |
| 856 |
} |
| 857 |
})).subscribe(ts); |
| 858 |
|
| 859 |
ts.assertNoValues(); |
| 860 |
ts.assertNoErrors(); |
| 861 |
ts.assertNotComplete(); |
| 862 |
|
| 863 |
pp.onError(new TestException()); |
| 864 |
|
| 865 |
ts.assertNoValues(); |
| 866 |
ts.assertNotComplete(); |
| 867 |
ts.assertError(TestException.class); |
| 868 |
} |
| 869 |
|
| 870 |
@Test |
| 871 |
public void delayAndTakeUntilNeverSubscribeToSource() { |
| 872 |
PublishProcessor<Integer> delayUntil = PublishProcessor.create(); |
| 873 |
PublishProcessor<Integer> interrupt = PublishProcessor.create(); |
| 874 |
final AtomicBoolean subscribed = new AtomicBoolean(false); |
| 875 |
|
| 876 |
Flowable.just(1) |
| 877 |
.doOnSubscribe(new Consumer<Object>() { |
| 878 |
@Override |
| 879 |
public void accept(Object o) { |
| 880 |
subscribed.set(true); |
| 881 |
} |
| 882 |
}) |
| 883 |
.delaySubscription(delayUntil) |
| 884 |
.takeUntil(interrupt) |
| 885 |
.subscribe(); |
| 886 |
|
| 887 |
interrupt.onNext(9000); |
| 888 |
delayUntil.onNext(1); |
| 889 |
|
| 890 |
Assert.assertFalse(subscribed.get()); |
| 891 |
} |
| 892 |
|
| 893 |
@Test |
| 894 |
public void delayWithTimeDelayError() throws Exception { |
| 895 |
Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())) |
| 896 |
.delay(100, TimeUnit.MILLISECONDS, true) |
| 897 |
.test() |
| 898 |
.awaitDone(5, TimeUnit.SECONDS) |
| 899 |
.assertFailure(TestException.class, 1); |
| 900 |
} |
| 901 |
|
| 902 |
@Test |
| 903 |
public void delaySubscriptionDisposeBeforeTime() { |
| 904 |
Flowable<Integer> result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); |
| 905 |
|
| 906 |
Subscriber<Object> subscriber = TestHelper.mockSubscriber(); |
| 907 |
TestSubscriber<Object> ts = new TestSubscriber<>(subscriber); |
| 908 |
|
| 909 |
result.subscribe(ts); |
| 910 |
ts.cancel(); |
| 911 |
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); |
| 912 |
|
| 913 |
verify(subscriber, never()).onNext(any()); |
| 914 |
verify(subscriber, never()).onComplete(); |
| 915 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 916 |
} |
| 917 |
|
| 918 |
@Test |
| 919 |
public void onErrorCalledOnScheduler() throws Exception { |
| 920 |
final CountDownLatch latch = new CountDownLatch(1); |
| 921 |
final AtomicReference<Thread> thread = new AtomicReference<>(); |
| 922 |
|
| 923 |
Flowable.<String>error(new Exception()) |
| 924 |
.delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread()) |
| 925 |
.doOnError(new Consumer<Throwable>() { |
| 926 |
@Override |
| 927 |
public void accept(Throwable throwable) throws Exception { |
| 928 |
thread.set(Thread.currentThread()); |
| 929 |
latch.countDown(); |
| 930 |
} |
| 931 |
}) |
| 932 |
.onErrorResumeWith(Flowable.<String>empty()) |
| 933 |
.subscribe(); |
| 934 |
|
| 935 |
latch.await(); |
| 936 |
|
| 937 |
assertNotEquals(Thread.currentThread(), thread.get()); |
| 938 |
} |
| 939 |
|
| 940 |
@Test |
| 941 |
public void dispose() { |
| 942 |
TestHelper.checkDisposed(PublishProcessor.create().delay(1, TimeUnit.SECONDS)); |
| 943 |
|
| 944 |
TestHelper.checkDisposed(PublishProcessor.create().delay(Functions.justFunction(Flowable.never()))); |
| 945 |
} |
| 946 |
|
| 947 |
@Test |
| 948 |
public void doubleOnSubscribe() { |
| 949 |
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() { |
| 950 |
@Override |
| 951 |
public Flowable<Object> apply(Flowable<Object> f) throws Exception { |
| 952 |
return f.delay(1, TimeUnit.SECONDS); |
| 953 |
} |
| 954 |
}); |
| 955 |
|
| 956 |
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() { |
| 957 |
@Override |
| 958 |
public Flowable<Object> apply(Flowable<Object> f) throws Exception { |
| 959 |
return f.delay(Functions.justFunction(Flowable.never())); |
| 960 |
} |
| 961 |
}); |
| 962 |
} |
| 963 |
|
| 964 |
@Test |
| 965 |
public void onCompleteFinal() { |
| 966 |
TestScheduler scheduler = new TestScheduler(); |
| 967 |
|
| 968 |
Flowable.empty() |
| 969 |
.delay(1, TimeUnit.MILLISECONDS, scheduler) |
| 970 |
.subscribe(new DisposableSubscriber<Object>() { |
| 971 |
@Override |
| 972 |
public void onNext(Object value) { |
| 973 |
} |
| 974 |
|
| 975 |
@Override |
| 976 |
public void onError(Throwable e) { |
| 977 |
} |
| 978 |
|
| 979 |
@Override |
| 980 |
public void onComplete() { |
| 981 |
throw new TestException(); |
| 982 |
} |
| 983 |
}); |
| 984 |
|
| 985 |
try { |
| 986 |
scheduler.advanceTimeBy(1, TimeUnit.SECONDS); |
| 987 |
fail("Should have thrown"); |
| 988 |
} catch (TestException ex) { |
| 989 |
// expected |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
@Test |
| 994 |
public void onErrorFinal() { |
| 995 |
TestScheduler scheduler = new TestScheduler(); |
| 996 |
|
| 997 |
Flowable.error(new TestException()) |
| 998 |
.delay(1, TimeUnit.MILLISECONDS, scheduler) |
| 999 |
.subscribe(new DisposableSubscriber<Object>() { |
| 1000 |
@Override |
| 1001 |
public void onNext(Object value) { |
| 1002 |
} |
| 1003 |
|
| 1004 |
@Override |
| 1005 |
public void onError(Throwable e) { |
| 1006 |
throw new TestException(); |
| 1007 |
} |
| 1008 |
|
| 1009 |
@Override |
| 1010 |
public void onComplete() { |
| 1011 |
} |
| 1012 |
}); |
| 1013 |
|
| 1014 |
try { |
| 1015 |
scheduler.advanceTimeBy(1, TimeUnit.SECONDS); |
| 1016 |
fail("Should have thrown"); |
| 1017 |
} catch (TestException ex) { |
| 1018 |
// expected |
| 1019 |
} |
| 1020 |
} |
| 1021 |
|
| 1022 |
@Test |
| 1023 |
public void itemDelayReturnsNull() { |
| 1024 |
Flowable.just(1).delay(new Function<Integer, Publisher<Object>>() { |
| 1025 |
@Override |
| 1026 |
public Publisher<Object> apply(Integer t) throws Exception { |
| 1027 |
return null; |
| 1028 |
} |
| 1029 |
}) |
| 1030 |
.to(TestHelper.<Integer>testConsumer()) |
| 1031 |
.assertFailureAndMessage(NullPointerException.class, "The itemDelay returned a null Publisher"); |
| 1032 |
} |
| 1033 |
} |