|
15 | 15 | */ |
16 | 16 | package io.reactivesocket.internal; |
17 | 17 |
|
18 | | -import static io.reactivesocket.TestUtil.*; |
19 | | -import static org.junit.Assert.*; |
20 | | -import static io.reactivesocket.ConnectionSetupPayload.NO_FLAGS; |
21 | | -import static io.reactivex.Observable.*; |
22 | | - |
23 | | -import java.util.Arrays; |
24 | | -import java.util.List; |
25 | | -import java.util.concurrent.TimeUnit; |
26 | | -import java.util.function.Consumer; |
27 | | - |
28 | | -import org.junit.Test; |
29 | | - |
30 | 18 | import io.reactivesocket.ConnectionSetupPayload; |
31 | 19 | import io.reactivesocket.Frame; |
32 | 20 | import io.reactivesocket.FrameType; |
33 | 21 | import io.reactivesocket.LatchedCompletable; |
34 | 22 | import io.reactivesocket.Payload; |
35 | 23 | import io.reactivesocket.TestConnection; |
36 | | -import io.reactivex.subscribers.TestSubscriber; |
| 24 | +import io.reactivesocket.util.PayloadImpl; |
37 | 25 | import io.reactivex.Observable; |
38 | 26 | import io.reactivex.subjects.ReplaySubject; |
| 27 | +import io.reactivex.subscribers.TestSubscriber; |
| 28 | +import org.hamcrest.MatcherAssert; |
| 29 | +import org.junit.Test; |
39 | 30 | import org.reactivestreams.Publisher; |
40 | 31 | import org.reactivestreams.Subscription; |
41 | 32 |
|
| 33 | +import java.util.ArrayList; |
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.List; |
| 36 | +import java.util.concurrent.TimeUnit; |
| 37 | +import java.util.function.Consumer; |
| 38 | + |
| 39 | +import static io.reactivesocket.ConnectionSetupPayload.*; |
| 40 | +import static io.reactivesocket.TestUtil.*; |
| 41 | +import static io.reactivex.Observable.*; |
| 42 | +import static org.hamcrest.Matchers.*; |
| 43 | +import static org.junit.Assert.*; |
| 44 | + |
42 | 45 | public class RequesterTest |
43 | 46 | { |
44 | 47 | final static Consumer<Throwable> ERROR_HANDLER = Throwable::printStackTrace; |
@@ -79,6 +82,30 @@ public void testReqMetaPushCancelBeforeRequestN() throws InterruptedException { |
79 | 82 | testCancelBeforeRequestN(p.metadataPush(utf8EncodedPayload("hello", null))); |
80 | 83 | } |
81 | 84 |
|
| 85 | + @Test() |
| 86 | + public void testReqStreamRequestLongMax() throws InterruptedException { |
| 87 | + TestConnection testConnection = establishConnection(); |
| 88 | + Requester p = createClientRequester(testConnection); |
| 89 | + |
| 90 | + testRequestLongMaxValue(p.requestStream(new PayloadImpl("")), testConnection); |
| 91 | + } |
| 92 | + |
| 93 | + @Test() |
| 94 | + public void testReqSubscriptionRequestLongMax() throws InterruptedException { |
| 95 | + TestConnection testConnection = establishConnection(); |
| 96 | + Requester p = createClientRequester(testConnection); |
| 97 | + |
| 98 | + testRequestLongMaxValue(p.requestSubscription(new PayloadImpl("")), testConnection); |
| 99 | + } |
| 100 | + |
| 101 | + @Test() |
| 102 | + public void testReqChannelRequestLongMax() throws InterruptedException { |
| 103 | + TestConnection testConnection = establishConnection(); |
| 104 | + Requester p = createClientRequester(testConnection); |
| 105 | + |
| 106 | + testRequestLongMaxValue(p.requestChannel(Publishers.just(new PayloadImpl(""))), testConnection); |
| 107 | + } |
| 108 | + |
82 | 109 | @Test(timeout=2000) |
83 | 110 | public void testRequestResponseSuccess() throws InterruptedException { |
84 | 111 | TestConnection conn = establishConnection(); |
@@ -306,14 +333,35 @@ private static <T> void testCancelBeforeRequestN(Publisher<T> source) { |
306 | 333 | testSubscriber.assertNotComplete(); |
307 | 334 | } |
308 | 335 |
|
309 | | - private static Requester createClientRequester() throws InterruptedException { |
310 | | - TestConnection conn = establishConnection(); |
| 336 | + private static <T> void testRequestLongMaxValue(Publisher<T> source, TestConnection testConnection) { |
| 337 | + List<Integer> requestNs = new ArrayList<>(); |
| 338 | + testConnection.write.add(frame -> { |
| 339 | + if (frame.getType() == FrameType.REQUEST_N) { |
| 340 | + requestNs.add(Frame.RequestN.requestN(frame)); |
| 341 | + } |
| 342 | + }); |
| 343 | + |
| 344 | + TestSubscriber<T> testSubscriber = new TestSubscriber<T>(1L); |
| 345 | + source.subscribe(testSubscriber); |
| 346 | + |
| 347 | + testSubscriber.request(Long.MAX_VALUE); |
| 348 | + testSubscriber.assertNoErrors(); |
| 349 | + testSubscriber.assertNotComplete(); |
| 350 | + |
| 351 | + MatcherAssert.assertThat("Negative requestNs received.", requestNs, not(contains(-1))); |
| 352 | + } |
| 353 | + |
| 354 | + private static Requester createClientRequester(TestConnection connection) throws InterruptedException { |
311 | 355 | LatchedCompletable rc = new LatchedCompletable(1); |
312 | | - Requester p = Requester.createClientRequester(conn, ConnectionSetupPayload.create("UTF-8", "UTF-8", NO_FLAGS), ERROR_HANDLER, rc); |
| 356 | + Requester p = Requester.createClientRequester(connection, ConnectionSetupPayload.create("UTF-8", "UTF-8", NO_FLAGS), ERROR_HANDLER, rc); |
313 | 357 | rc.await(); |
314 | 358 | return p; |
315 | 359 | } |
316 | 360 |
|
| 361 | + private static Requester createClientRequester() throws InterruptedException { |
| 362 | + return createClientRequester(establishConnection()); |
| 363 | + } |
| 364 | + |
317 | 365 | private static TestConnection establishConnection() { |
318 | 366 | return new TestConnection(); |
319 | 367 | } |
|
0 commit comments