|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.nio.charset.Charset;
|
20 | 20 | import java.nio.charset.StandardCharsets;
|
| 21 | +import java.time.Duration; |
21 | 22 | import java.util.ArrayList;
|
22 | 23 | import java.util.Arrays;
|
23 | 24 | import java.util.Collections;
|
24 | 25 | import java.util.List;
|
25 | 26 |
|
26 | 27 | import org.junit.jupiter.api.Test;
|
| 28 | +import org.reactivestreams.Subscription; |
| 29 | +import reactor.core.publisher.BaseSubscriber; |
27 | 30 | import reactor.core.publisher.Flux;
|
28 | 31 | import reactor.test.StepVerifier;
|
29 | 32 |
|
@@ -75,14 +78,15 @@ public void decode() {
|
75 | 78 | String s = String.format("%s\n%s\n%s", u, e, o);
|
76 | 79 | Flux<DataBuffer> input = toDataBuffers(s, 1, UTF_8);
|
77 | 80 |
|
78 |
| - // TODO: temporarily replace testDecodeAll with explicit decode/cancel/empty |
79 |
| - // see https://github.com/reactor/reactor-core/issues/2041 |
| 81 | + testDecodeAll(input, TYPE, step -> step.expectNext(u, e, o).verifyComplete(), null, null); |
| 82 | + } |
80 | 83 |
|
81 |
| -// testDecode(input, TYPE, step -> step.expectNext(u, e, o).verifyComplete(), null, null); |
82 |
| -// testDecodeCancel(input, TYPE, null, null); |
83 |
| -// testDecodeEmpty(TYPE, null, null); |
| 84 | + @Test // gh-30299 |
| 85 | + public void decodeAndCancelWithPendingChunks() { |
| 86 | + Flux<DataBuffer> input = toDataBuffers("abc", 1, UTF_8).concatWith(Flux.never()); |
| 87 | + Flux<String> result = this.decoder.decode(input, TYPE, null, null); |
84 | 88 |
|
85 |
| - testDecodeAll(input, TYPE, step -> step.expectNext(u, e, o).verifyComplete(), null, null); |
| 89 | + StepVerifier.create(result).thenAwait(Duration.ofMillis(100)).thenCancel().verify(); |
86 | 90 | }
|
87 | 91 |
|
88 | 92 | @Test
|
@@ -264,4 +268,13 @@ private DataBuffer stringBuffer(String value) {
|
264 | 268 | return buffer;
|
265 | 269 | }
|
266 | 270 |
|
| 271 | + |
| 272 | + private static class SingleRequestSubscriber extends BaseSubscriber<String> { |
| 273 | + |
| 274 | + @Override |
| 275 | + protected void hookOnSubscribe(Subscription subscription) { |
| 276 | + subscription.request(1); |
| 277 | + } |
| 278 | + } |
| 279 | + |
267 | 280 | }
|
0 commit comments