You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: items/test-work-scheduling-using-testscheduler.md
+22-11Lines changed: 22 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,29 +59,40 @@ final Observable<ByteStreamProgress> throttledObservable =
59
59
);
60
60
```
61
61
62
-
After we have created the throttled `Observable` instance, we first subscribe to it with a `TestObserver`. We then emit `ByteSteamProgress` instances on `progressSubject`. By observing the values emitted by the throttled `Observable` instance, we assert its correctness:
62
+
After we have created the throttled `Observable` instance, we first subscribe to it with a `TestObserver`. We then emit a sequence of `ByteSteamProgress` instances on `progressSubject`:
63
63
64
64
```java
65
-
finallong startTime =1;
66
65
// Emit incomplete progress with 10 and 20 bytes consumed in the first window.
We emit incomplete `ByteStreamProgress` instances with `10` and then `20` bytes in the first window. The `Observable` returned by `throttledObservable` should emit only the first instance in this pair. Similarly, we emit incomplete `ByteStreamProgress` instances with `30` and then `40` bytes in the second window. Again, `throttledObservable` should emit only the first instance in this pair.
77
83
84
+
Finally, we emit a complete `ByteStreamProgress` instance with `50` bytes in the second window. The `Observable` returned by `throttledObservable` should not throttling it, and consequently emit it.
85
+
86
+
To assert this behavior, we create the expected sequence of `ContentDownloadEvent` values and pass it to method `assertReceivedOnNext` of `TestObserver`:
Note that the test above takes less than a millisecond to run on my computer, even though it simulates over 500 milliseconds passing. Use a `TestScheduler` to keep your tests fast.
97
+
Note that the test above takes less than a millisecond to run on my computer, even though it simulates over 500 milliseconds passing. Use `TestScheduler` to keep your tests fast.
0 commit comments