Fixing HttpClient tests to configure before start
This commit is contained in:
parent
fa38868406
commit
d0afc63cd5
|
@ -39,7 +39,6 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.util.SocketAddressResolver;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
|
@ -50,12 +49,11 @@ public class ValidatingConnectionPoolTest extends AbstractHttpClientServerTest
|
|||
public HttpClient newHttpClient(Scenario scenario, HttpClientTransport transport, Executor executor, Scheduler scheduler, SocketAddressResolver resolver)
|
||||
{
|
||||
if (transport==null)
|
||||
{
|
||||
long timeout = 1000;
|
||||
transport = new HttpClientTransportOverHTTP(1);
|
||||
transport.setConnectionPoolFactory(destination ->
|
||||
|
||||
long timeout = 1000;
|
||||
transport.setConnectionPoolFactory(destination ->
|
||||
new ValidatingConnectionPool(destination, destination.getHttpClient().getMaxConnectionsPerDestination(), destination, destination.getHttpClient().getScheduler(), timeout));
|
||||
}
|
||||
|
||||
return super.newHttpClient(scenario, transport, executor, scheduler, resolver);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,9 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
|
||||
class SslSelectionDump extends ContainerLifeCycle implements Dumpable
|
||||
class SslSelectionDump implements Dumpable
|
||||
{
|
||||
static class CaptionedList extends ArrayList<String> implements Dumpable
|
||||
{
|
||||
|
@ -66,9 +65,7 @@ class SslSelectionDump extends ContainerLifeCycle implements Dumpable
|
|||
String[] includedByConfig)
|
||||
{
|
||||
this.type = type;
|
||||
addBean(enabled);
|
||||
addBean(disabled);
|
||||
|
||||
|
||||
List<String> jvmEnabled = Arrays.asList(enabledByJVM);
|
||||
List<Pattern> excludedPatterns = Arrays.stream(excludedByConfig)
|
||||
.map((entry) -> Pattern.compile(entry))
|
||||
|
@ -165,7 +162,7 @@ class SslSelectionDump extends ContainerLifeCycle implements Dumpable
|
|||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
dumpObjects(out, indent);
|
||||
Dumpable.dumpObjects(out, indent, this, enabled, disabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.http.client;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -65,9 +68,6 @@ import org.hamcrest.Matchers;
|
|||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class HttpClientLoadTest extends AbstractTest<HttpClientLoadTest.LoadTransportScenario>
|
||||
{
|
||||
private final Logger logger = Log.getLogger(HttpClientLoadTest.class);
|
||||
|
@ -85,11 +85,12 @@ public class HttpClientLoadTest extends AbstractTest<HttpClientLoadTest.LoadTran
|
|||
public void testIterative(Transport transport) throws Exception
|
||||
{
|
||||
init(transport);
|
||||
scenario.start(new LoadHandler());
|
||||
|
||||
scenario.client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
|
||||
scenario.client.setMaxConnectionsPerDestination(32768);
|
||||
scenario.client.setMaxRequestsQueuedPerDestination(1024 * 1024);
|
||||
scenario.start(new LoadHandler(), client ->
|
||||
{
|
||||
client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
|
||||
client.setMaxConnectionsPerDestination(32768);
|
||||
client.setMaxRequestsQueuedPerDestination(1024 * 1024);
|
||||
});
|
||||
|
||||
// At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity)
|
||||
int runs = 1;
|
||||
|
@ -130,11 +131,13 @@ public class HttpClientLoadTest extends AbstractTest<HttpClientLoadTest.LoadTran
|
|||
public void testConcurrent(Transport transport) throws Exception
|
||||
{
|
||||
init(transport);
|
||||
scenario.start(new LoadHandler());
|
||||
scenario.start(new LoadHandler(), client ->
|
||||
{
|
||||
client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
|
||||
client.setMaxConnectionsPerDestination(32768);
|
||||
client.setMaxRequestsQueuedPerDestination(1024 * 1024);
|
||||
});
|
||||
|
||||
scenario.client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
|
||||
scenario.client.setMaxConnectionsPerDestination(32768);
|
||||
scenario.client.setMaxRequestsQueuedPerDestination(1024 * 1024);
|
||||
|
||||
int runs = 1;
|
||||
int iterations = 256;
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
|
@ -270,20 +271,29 @@ public class TransportScenario
|
|||
else
|
||||
setConnectionIdleTimeout(idleTimeout);
|
||||
}
|
||||
|
||||
public void start(Handler handler) throws Exception
|
||||
{
|
||||
start(handler,null);
|
||||
}
|
||||
|
||||
public void start(Handler handler, Consumer<HttpClient> config) throws Exception
|
||||
{
|
||||
startServer(handler);
|
||||
startClient();
|
||||
startClient(config);
|
||||
}
|
||||
|
||||
public void start(HttpServlet servlet) throws Exception
|
||||
{
|
||||
startServer(servlet);
|
||||
startClient();
|
||||
startClient(null);
|
||||
}
|
||||
|
||||
public void startClient() throws Exception
|
||||
{
|
||||
startClient(null);
|
||||
}
|
||||
|
||||
public void startClient(Consumer<HttpClient> config) throws Exception
|
||||
{
|
||||
QueuedThreadPool clientThreads = new QueuedThreadPool();
|
||||
clientThreads.setName("client");
|
||||
|
@ -291,6 +301,10 @@ public class TransportScenario
|
|||
client = newHttpClient(provideClientTransport(transport), sslContextFactory);
|
||||
client.setExecutor(clientThreads);
|
||||
client.setSocketAddressResolver(new SocketAddressResolver.Sync());
|
||||
|
||||
if (config!=null)
|
||||
config.accept(client);
|
||||
|
||||
client.start();
|
||||
if (server != null)
|
||||
server.addBean(client);
|
||||
|
|
Loading…
Reference in New Issue