|
16 | 16 | package org.eclipse.jetty.reactive.client;
|
17 | 17 |
|
18 | 18 | import java.io.IOException;
|
| 19 | +import java.io.InterruptedIOException; |
| 20 | +import java.net.URI; |
| 21 | +import java.time.Duration; |
19 | 22 | import java.util.Random;
|
20 | 23 |
|
21 | 24 | import javax.servlet.http.HttpServletRequest;
|
|
27 | 30 | import org.testng.Assert;
|
28 | 31 | import org.testng.annotations.Factory;
|
29 | 32 | import org.testng.annotations.Test;
|
| 33 | +import reactor.core.publisher.Mono; |
30 | 34 |
|
31 | 35 | public class ReactorTest extends AbstractTest {
|
32 | 36 | @Factory(dataProvider = "protocols", dataProviderClass = AbstractTest.class)
|
@@ -54,4 +58,34 @@ protected void service(String target, Request jettyRequest, HttpServletRequest r
|
54 | 58 | Assert.assertNotNull(responseContent);
|
55 | 59 | Assert.assertEquals(data, responseContent);
|
56 | 60 | }
|
| 61 | + |
| 62 | + @Test |
| 63 | + public void testTotalTimeout() throws Exception { |
| 64 | + long timeout = 1000; |
| 65 | + String result = "HELLO"; |
| 66 | + prepare(new EmptyHandler() { |
| 67 | + @Override |
| 68 | + protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { |
| 69 | + try { |
| 70 | + Thread.sleep(2 * timeout); |
| 71 | + response.getWriter().write(result); |
| 72 | + } catch (InterruptedException x) { |
| 73 | + throw new InterruptedIOException(); |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + String timeoutResult = "TIMEOUT"; |
| 79 | + String responseContent = WebClient.builder() |
| 80 | + .clientConnector(new JettyClientHttpConnector(httpClient())) |
| 81 | + .build() |
| 82 | + .get() |
| 83 | + .uri(new URI(uri())) |
| 84 | + .retrieve() |
| 85 | + .bodyToMono(String.class) |
| 86 | + .timeout(Duration.ofMillis(timeout), Mono.just(timeoutResult)) |
| 87 | + .block(); |
| 88 | + |
| 89 | + Assert.assertEquals(timeoutResult, responseContent); |
| 90 | + } |
57 | 91 | }
|
0 commit comments