Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Dec 20, 2024
1 parent 7947030 commit dbc7da7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public Runnable produce()

int filled = fill(getEndPoint(), networkBuffer.getByteBuffer(), compact);
if (LOG.isDebugEnabled())
LOG.debug("Filled {} bytes compacted {} in {}", filled, compact, networkBuffer);
LOG.debug("Filled {} bytes compacted {} {} in {}", filled, compact, networkBuffer, HTTP2Connection.this);

if (filled > 0)
{
Expand Down Expand Up @@ -439,10 +439,11 @@ else if (filled == 0)
private RetainableByteBuffer.Mutable acquireBuffer()
{
RetainableByteBuffer.Mutable buffer = heldBuffer.getAndSet(null);
RetainableByteBuffer.Mutable held = buffer;
if (buffer == null)
buffer = bufferPool.acquire(bufferSize, isUseInputDirectByteBuffers()).asMutable();
if (LOG.isDebugEnabled())
LOG.debug("Acquired {}", buffer);
LOG.debug("Acquired {} {} in {}", held == null ? "new" : "held", buffer, HTTP2Connection.this);
return buffer;
}

Expand All @@ -451,7 +452,7 @@ private void holdBuffer(RetainableByteBuffer.Mutable buffer)
if (heldBuffer.compareAndSet(null, buffer))
{
if (LOG.isDebugEnabled())
LOG.debug("Held {}", buffer);
LOG.debug("Held {} in {}", buffer, HTTP2Connection.this);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream;

import org.awaitility.Awaitility;
import org.eclipse.jetty.client.BytesRequestContent;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.client.Result;
Expand All @@ -40,14 +42,14 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.thread.Scheduler;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HttpClientLoadTest extends AbstractTest
Expand All @@ -68,24 +70,26 @@ public void testIterative(TransportType transportType) throws Exception
client.setMaxConnectionsPerDestination(32768);
client.setMaxRequestsQueuedPerDestination(1024 * 1024);
client.setIdleTimeout(120000);
client.start();

// At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity)
int runs = 1;
int iterations = 100;
for (int i = 0; i < runs; ++i)
try (HttpClient httpClient = client)
{
run(transportType, iterations);
}
httpClient.start();

// Re-run after warmup
iterations = 250;
for (int i = 0; i < runs; ++i)
{
run(transportType, iterations);
}
// At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity)
int runs = 1;
int iterations = 100;
for (int i = 0; i < runs; ++i)
{
run(transportType, iterations);
}

assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), Matchers.is(0));
// Re-run after warmup
iterations = 250;
for (int i = 0; i < runs; ++i)
{
run(transportType, iterations);
}
}
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), is(0)));
}

@ParameterizedTest
Expand All @@ -101,15 +105,17 @@ public void testConcurrent(TransportType transportType) throws Exception
client.setByteBufferPool(byteBufferPool);
client.setMaxConnectionsPerDestination(32768);
client.setMaxRequestsQueuedPerDestination(1024 * 1024);
client.start();
try (HttpClient httpClient = client)
{
httpClient.start();

int runs = 1;
int iterations = 128;
IntStream.range(0, 16).parallel().forEach(i ->
int runs = 1;
int iterations = 128;
IntStream.range(0, 16).parallel().forEach(i ->
IntStream.range(0, runs).forEach(j ->
run(transportType, iterations)));

assertThat("Connection Leaks: " + byteBufferPool.getLeaks(), byteBufferPool.getLeaks().size(), Matchers.is(0));
run(transportType, iterations)));
}
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), is(0)));
}

private void run(TransportType transportType, int iterations)
Expand Down

0 comments on commit dbc7da7

Please sign in to comment.