Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableIntervalRangeTest.java

raw
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
18 import java.util.concurrent.TimeUnit;
19
20 import org.junit.Test;
21
22 import io.reactivex.rxjava3.core.*;
23 import io.reactivex.rxjava3.exceptions.MissingBackpressureException;
24 import io.reactivex.rxjava3.schedulers.Schedulers;
25 import io.reactivex.rxjava3.testsupport.TestHelper;
26
27 public class FlowableIntervalRangeTest extends RxJavaTest {
28 @Test
29 public void simple() throws Exception {
30 Flowable.intervalRange(5, 5, 50, 50, TimeUnit.MILLISECONDS)
31 .test()
32 .awaitDone(5, TimeUnit.SECONDS)
33 .assertResult(5L, 6L, 7L, 8L, 9L);
34 }
35
36 @Test
37 public void customScheduler() {
38 Flowable.intervalRange(1, 5, 1, 1, TimeUnit.MILLISECONDS, Schedulers.single())
39 .test()
40 .awaitDone(5, TimeUnit.SECONDS)
41 .assertResult(1L, 2L, 3L, 4L, 5L);
42 }
43
44 @Test
45 public void countZero() {
46 Flowable.intervalRange(1, 0, 1, 1, TimeUnit.MILLISECONDS)
47 .test()
48 .awaitDone(5, TimeUnit.SECONDS)
49 .assertResult();
50 }
51
52 @Test
53 public void countNegative() {
54 try {
55 Flowable.intervalRange(1, -1, 1, 1, TimeUnit.MILLISECONDS);
56 fail("Should have thrown!");
57 } catch (IllegalArgumentException ex) {
58 assertEquals("count >= 0 required but it was -1", ex.getMessage());
59 }
60 }
61
62 @Test
63 public void longOverflow() {
64 Flowable.intervalRange(Long.MAX_VALUE - 1, 2, 1, 1, TimeUnit.MILLISECONDS);
65
66 Flowable.intervalRange(Long.MIN_VALUE, Long.MAX_VALUE, 1, 1, TimeUnit.MILLISECONDS);
67
68 try {
69 Flowable.intervalRange(Long.MAX_VALUE - 1, 3, 1, 1, TimeUnit.MILLISECONDS);
70 fail("Should have thrown!");
71 } catch (IllegalArgumentException ex) {
72 assertEquals("Overflow! start + count is bigger than Long.MAX_VALUE", ex.getMessage());
73 }
74 }
75
76 @Test
77 public void dispose() {
78 TestHelper.checkDisposed(Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS));
79 }
80
81 @Test
82 public void backpressureBounded() {
83 Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
84 .test(2L)
85 .awaitDone(5, TimeUnit.SECONDS)
86 .assertResult(1L, 2L);
87 }
88
89 @Test
90 public void backpressureOverflow() {
91 Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS)
92 .test(2L)
93 .awaitDone(5, TimeUnit.SECONDS)
94 .assertFailure(MissingBackpressureException.class, 1L, 2L);
95 }
96
97 @Test
98 public void badRequest() {
99 TestHelper.assertBadRequestReported(Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS));
100 }
101
102 @Test
103 public void take() {
104 Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
105 .take(1)
106 .test()
107 .awaitDone(5, TimeUnit.SECONDS)
108 .assertResult(1L);
109 }
110
111 @Test
112 public void cancel() {
113 Flowable.intervalRange(0, 20, 1, 1, TimeUnit.MILLISECONDS, Schedulers.trampoline())
114 .take(10)
115 .test()
116 .assertResult(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
117 }
118
119 @Test
120 public void takeSameAsRange() {
121 Flowable.intervalRange(0, 2, 1, 1, TimeUnit.MILLISECONDS, Schedulers.trampoline())
122 .take(2)
123 .test()
124 .assertResult(0L, 1L);
125 }
126 }