Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ class SharedHttpClientConnectionGroup extends ManagedResource {
private static final BiFunction<PoolWaiter<HttpClientConnection>, List<PoolConnection<HttpClientConnection>>, PoolConnection<HttpClientConnection>> LIFO_SELECTOR = (waiter, connections) -> {
int size = connections.size();
PoolConnection<HttpClientConnection> selected = null;
long last = 0L;
for (int i = 0; i < size; i++) {
PoolConnection<HttpClientConnection> pooled = connections.get(i);
if (pooled.available() > 0) {
HttpClientConnection conn = pooled.get();
if (selected == null) {
// The timestamp is only read when two connections are compared, a lone connection may not support it
if (selected == null || pooled.get().lastResponseReceivedTimestamp() > selected.get().lastResponseReceivedTimestamp()) {
selected = pooled;
} else {
if (conn.lastResponseReceivedTimestamp() > last) {
selected = pooled;
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions vertx-core/src/test/java/io/vertx/tests/http/Http1xTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,16 @@ private void testHttpClientResponsePause(Checkpoint checkpoint, Handler<HttpClie

@Test
public void testPoolLIFOPolicy() throws Exception {
testPoolLIFOPolicy(0, 1);
}

@Test
public void testPoolLIFOPolicyWithResponsesInReverseOrder() throws Exception {
// The most recently used connection is the first one created
testPoolLIFOPolicy(1, 0);
}

private void testPoolLIFOPolicy(int firstResponse, int lastResponse) throws Exception {
List<HttpServerRequest> requests = Collections.synchronizedList(new ArrayList<>());
server.requestHandler(requests::add);
startServer(testAddress);
Expand All @@ -3993,7 +4003,7 @@ public void testPoolLIFOPolicy() throws Exception {
int val = i;
assertWaitUntil(() -> requests.size() == val + 1);
}
for (int i = 0;i < 2;i++) {
for (int i : new int[]{firstResponse, lastResponse}) {
requests.get(i).response().end();
connections.get(i).await();
// Make sure that connection lastResponseReceivedTimestamp are distinct
Expand All @@ -4008,7 +4018,7 @@ public void testPoolLIFOPolicy() throws Exception {
assertWaitUntil(() -> requests.size() == 3);
requests.get(2).response().end();
HttpConnection connection = future.await();
assertSame(connection, connections.get(1).result());
assertSame(connection, connections.get(lastResponse).result());
}

@Test
Expand Down