|
16 | 16 |
|
17 | 17 | package org.springframework.boot.web.embedded.jetty;
|
18 | 18 |
|
19 |
| -import java.io.IOException; |
20 | 19 | import java.net.InetAddress;
|
21 | 20 | import java.time.Duration;
|
| 21 | +import java.util.ArrayList; |
22 | 22 | import java.util.Arrays;
|
| 23 | +import java.util.List; |
23 | 24 | import java.util.concurrent.CountDownLatch;
|
24 | 25 | import java.util.concurrent.Future;
|
25 | 26 | import java.util.concurrent.TimeUnit;
|
26 |
| -import java.util.concurrent.atomic.AtomicReference; |
27 | 27 |
|
28 | 28 | import org.eclipse.jetty.server.Connector;
|
29 | 29 | import org.eclipse.jetty.server.Server;
|
30 | 30 | import org.eclipse.jetty.server.ServerConnector;
|
31 | 31 | import org.junit.jupiter.api.Test;
|
32 | 32 | import org.mockito.InOrder;
|
| 33 | +import reactor.core.publisher.Mono; |
33 | 34 |
|
34 | 35 | import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
|
35 | 36 | import org.springframework.boot.web.server.Shutdown;
|
| 37 | +import org.springframework.http.ResponseEntity; |
36 | 38 | import org.springframework.http.client.reactive.JettyResourceFactory;
|
37 | 39 | import org.springframework.http.server.reactive.HttpHandler;
|
38 | 40 |
|
39 | 41 | import static org.assertj.core.api.Assertions.assertThat;
|
40 | 42 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
41 |
| -import static org.awaitility.Awaitility.await; |
42 | 43 | import static org.mockito.ArgumentMatchers.any;
|
43 | 44 | import static org.mockito.Mockito.inOrder;
|
44 | 45 | import static org.mockito.Mockito.mock;
|
@@ -127,24 +128,32 @@ void whenServerIsShuttingDownGracefullyThenNewConnectionsCannotBeMade() throws E
|
127 | 128 | BlockingHandler blockingHandler = new BlockingHandler();
|
128 | 129 | this.webServer = factory.getWebServer(blockingHandler);
|
129 | 130 | this.webServer.start();
|
130 |
| - getWebClient().build().get().retrieve().toBodilessEntity().subscribe(); |
| 131 | + CountDownLatch responseLatch = new CountDownLatch(1); |
| 132 | + getWebClient().build().get().retrieve().toBodilessEntity().subscribe((response) -> responseLatch.countDown()); |
131 | 133 | blockingHandler.awaitQueue();
|
132 | 134 | Future<Boolean> shutdownResult = initiateGracefulShutdown();
|
133 | 135 | // We need to make two requests as Jetty accepts one additional request after a
|
134 | 136 | // connector has been told to stop accepting requests
|
135 |
| - CountDownLatch responseLatch = new CountDownLatch(1); |
136 |
| - AtomicReference<Throwable> errorReference = new AtomicReference<>(); |
137 |
| - getWebClient().build().get().retrieve().toBodilessEntity().doOnSuccess((response) -> responseLatch.countDown()) |
138 |
| - .doOnError(errorReference::set).subscribe(); |
139 |
| - getWebClient().build().get().retrieve().toBodilessEntity().doOnSuccess((response) -> responseLatch.countDown()) |
140 |
| - .doOnError(errorReference::set).subscribe(); |
| 137 | + Mono<ResponseEntity<Void>> unconnectableRequest1 = getWebClient().build().get().retrieve().toBodilessEntity(); |
| 138 | + Mono<ResponseEntity<Void>> unconnectableRequest2 = getWebClient().build().get().retrieve().toBodilessEntity(); |
141 | 139 | assertThat(shutdownResult.get()).isEqualTo(false);
|
142 | 140 | blockingHandler.completeOne();
|
143 |
| - blockingHandler.completeOne(); |
144 | 141 | responseLatch.await(5, TimeUnit.SECONDS);
|
145 | 142 | this.webServer.stop();
|
146 |
| - Throwable error = await().atMost(Duration.ofSeconds(30)).until(errorReference::get, (ex) -> ex != null); |
147 |
| - assertThat(error).isInstanceOf(IOException.class); |
| 143 | + List<Object> results = new ArrayList<>(); |
| 144 | + try { |
| 145 | + results.add(unconnectableRequest1.block()); |
| 146 | + } |
| 147 | + catch (Exception ex) { |
| 148 | + results.add(ex); |
| 149 | + } |
| 150 | + try { |
| 151 | + results.add(unconnectableRequest2.block()); |
| 152 | + } |
| 153 | + catch (Exception ex) { |
| 154 | + results.add(ex); |
| 155 | + } |
| 156 | + assertThat(results).anySatisfy((result) -> assertThat(result).isInstanceOf(Exception.class)); |
148 | 157 | }
|
149 | 158 |
|
150 | 159 | @Override
|
|
0 commit comments