|
15 | 15 |
|
16 | 16 | import static org.junit.jupiter.api.Assertions.*; |
17 | 17 |
|
18 | | -import java.util.concurrent.CancellationException; |
| 18 | +import java.util.concurrent.*; |
19 | 19 | import java.util.concurrent.atomic.AtomicInteger; |
20 | 20 |
|
21 | | -import org.junit.jupiter.api.*; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
22 | 23 | import io.reactivex.rxjava4.core.Streamable; |
23 | 24 | import io.reactivex.rxjava4.disposables.CompositeDisposable; |
24 | 25 | import io.reactivex.rxjava4.exceptions.*; |
| 26 | +import io.reactivex.rxjava4.processors.DispatchStreamProcessor; |
25 | 27 |
|
26 | 28 | public class StreamableForEachTest extends StreamableBaseTest { |
27 | 29 |
|
@@ -189,4 +191,60 @@ public void forEachBiInsideCancel() throws Throwable { |
189 | 191 | assertEquals(1, counter.get()); |
190 | 192 | }); |
191 | 193 | } |
| 194 | + |
| 195 | + @Test |
| 196 | + public void forEachInput() throws Throwable { |
| 197 | + var dsp = new DispatchStreamProcessor<>(); |
| 198 | + var ts = dsp.test(); |
| 199 | + |
| 200 | + ts.awaitOnSubscribe(1, TimeUnit.SECONDS); |
| 201 | + |
| 202 | + while (!dsp.hasStreamers()) { |
| 203 | + Thread.sleep(0, 1000); |
| 204 | + } |
| 205 | + |
| 206 | + Streamable.range(1, 5) |
| 207 | + .subscribe(dsp); |
| 208 | + |
| 209 | + ts.awaitDone(5, TimeUnit.SECONDS) |
| 210 | + .assertResult(1, 2, 3, 4, 5); |
| 211 | + } |
| 212 | + |
| 213 | + @Test |
| 214 | + public void forEachInputDebug() throws Throwable { |
| 215 | + withCachedExecutor(exec -> { |
| 216 | + var dsp = new DispatchStreamProcessor<>(); |
| 217 | + var ts = dsp.test(exec); |
| 218 | + |
| 219 | + ts.awaitOnSubscribe(1, TimeUnit.SECONDS); |
| 220 | + |
| 221 | + while (!dsp.hasStreamers()) { |
| 222 | + Thread.sleep(0, 1000); |
| 223 | + } |
| 224 | + |
| 225 | + Streamable.range(1, 5) |
| 226 | + .subscribe(dsp); |
| 227 | + |
| 228 | + ts.awaitDone(5, TimeUnit.SECONDS) |
| 229 | + .assertResult(1, 2, 3, 4, 5); |
| 230 | + }); |
| 231 | + } |
| 232 | + |
| 233 | + @Test |
| 234 | + public void forEachInputError() throws Throwable { |
| 235 | + var dsp = new DispatchStreamProcessor<>(); |
| 236 | + var ts = dsp.test(); |
| 237 | + |
| 238 | + ts.awaitOnSubscribe(1, TimeUnit.SECONDS); |
| 239 | + |
| 240 | + while (!dsp.hasStreamers()) { |
| 241 | + Thread.sleep(0, 1000); |
| 242 | + } |
| 243 | + |
| 244 | + Streamable.error(new TestException()) |
| 245 | + .subscribe(dsp); |
| 246 | + |
| 247 | + ts.awaitDone(5, TimeUnit.SECONDS) |
| 248 | + .assertFailure(TestException.class); |
| 249 | + } |
192 | 250 | } |
0 commit comments