From 8fcfdd9d7f14ac5b7fa40114f5415fe8a29cb1c2 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 6 Mar 2018 09:59:59 +0100 Subject: [PATCH] Fixes #2273 - Test failure: RoundRobinConnectionPoolTest.testRoundRobin. Now making sure all connections are opened before testing the round robin behavior. Signed-off-by: Simone Bordet --- .../client/RoundRobinConnectionPoolTest.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/RoundRobinConnectionPoolTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/RoundRobinConnectionPoolTest.java index c7bd1586a7e..ac8a1ea9a25 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/RoundRobinConnectionPoolTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/RoundRobinConnectionPoolTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -45,23 +46,39 @@ public class RoundRobinConnectionPoolTest extends AbstractHttpClientServerTest @Test public void testRoundRobin() throws Exception { + AtomicBoolean record = new AtomicBoolean(); List remotePorts = new ArrayList<>(); start(new EmptyServerHandler() { @Override protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - remotePorts.add(request.getRemotePort()); + if (record.get()) + remotePorts.add(request.getRemotePort()); } }); int maxConnections = 3; client.getTransport().setConnectionPoolFactory(destination -> new RoundRobinConnectionPool(destination, maxConnections, destination)); + // Prime the connections, so that they are all opened + // before we actually test the round robin behavior. + String host = "localhost"; + int port = connector.getLocalPort(); + for (int i = 0; i < maxConnections; ++i) + { + ContentResponse response = client.newRequest(host, port) + .scheme(scheme) + .timeout(5, TimeUnit.SECONDS) + .send(); + Assert.assertEquals(HttpStatus.OK_200, response.getStatus()); + } + + record.set(true); int requests = 2 * maxConnections - 1; for (int i = 0; i < requests; ++i) { - ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + ContentResponse response = client.newRequest(host, port) .scheme(scheme) .timeout(5, TimeUnit.SECONDS) .send();