Skip to content

Commit

Permalink
Renamed AbstractTest.Transport to TransportType (#12637)
Browse files Browse the repository at this point in the history
* This to avoid confusion with oej.io.Transport, and facilitate refactoring (as "transport" appears in package names, documentation, etc.).

Renamed TransportType.H3 to H3_QUICHE.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet authored Dec 12, 2024
1 parent b799fd4 commit b96f49f
Show file tree
Hide file tree
Showing 59 changed files with 1,394 additions and 1,394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,33 @@ public class AbstractTest
protected ArrayByteBufferPool.Tracking serverBufferPool;
protected ArrayByteBufferPool.Tracking clientBufferPool;

public static Collection<Transport> transports()
public static Collection<TransportType> transports()
{
EnumSet<Transport> transports = EnumSet.allOf(Transport.class);
EnumSet<TransportType> transportTypes = EnumSet.allOf(TransportType.class);
if ("ci".equals(System.getProperty("env")))
transports.remove(Transport.H3);
return transports;
transportTypes.remove(TransportType.H3_QUICHE);
return transportTypes;
}

public static Collection<Transport> transportsNoFCGI()
public static Collection<TransportType> transportsNoFCGI()
{
Collection<Transport> transports = transports();
transports.remove(Transport.FCGI);
return transports;
Collection<TransportType> transportTypes = transports();
transportTypes.remove(TransportType.FCGI);
return transportTypes;
}

public static Collection<Transport> transportsTCP()
public static Collection<TransportType> transportsTCP()
{
Collection<Transport> transports = transports();
transports.remove(Transport.H3);
return transports;
Collection<TransportType> transportTypes = transports();
transportTypes.remove(TransportType.H3_QUICHE);
return transportTypes;
}

public static Collection<Transport> transportsTLS()
public static Collection<TransportType> transportsTLS()
{
Collection<Transport> transports = transports();
transports.retainAll(EnumSet.of(Transport.HTTPS, Transport.H2));
return transports;
Collection<TransportType> transportTypes = transports();
transportTypes.retainAll(EnumSet.of(TransportType.HTTPS, TransportType.H2));
return transportTypes;
}

@AfterEach
Expand Down Expand Up @@ -255,25 +255,25 @@ private static void dumpHeap(String testMethodName) throws Exception
mxBeanClass.getMethod("dumpHeap", String.class, boolean.class).invoke(mxBean, dumpName, true);
}

protected void start(Transport transport, Handler handler) throws Exception
protected void start(TransportType transportType, Handler handler) throws Exception
{
startServer(transport, handler);
startClient(transport);
startServer(transportType, handler);
startClient(transportType);
}

protected void startServer(Transport transport, Handler handler) throws Exception
protected void startServer(TransportType transportType, Handler handler) throws Exception
{
prepareServer(transport, handler);
prepareServer(transportType, handler);
server.start();
}

protected void prepareServer(Transport transport, Handler handler) throws Exception
protected void prepareServer(TransportType transportType, Handler handler) throws Exception
{
sslContextFactoryServer = newSslContextFactoryServer();
serverQuicConfig = new ServerQuicConfiguration(sslContextFactoryServer, workDir.getEmptyPathDir());
if (server == null)
server = newServer();
connector = newConnector(transport, server);
connector = newConnector(transportType, server);
server.addConnector(connector);
server.setHandler(handler);
}
Expand All @@ -296,41 +296,41 @@ protected SslContextFactory.Server newSslContextFactoryServer()
return ssl;
}

protected void startClient(Transport transport) throws Exception
protected void startClient(TransportType transportType) throws Exception
{
prepareClient(transport);
prepareClient(transportType);
client.start();
}

protected void prepareClient(Transport transport) throws Exception
protected void prepareClient(TransportType transportType) throws Exception
{
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
client = new HttpClient(newHttpClientTransport(transport));
client = new HttpClient(newHttpClientTransport(transportType));
clientBufferPool = new ArrayByteBufferPool.Tracking();
client.setByteBufferPool(clientBufferPool);
client.setExecutor(clientThreads);
client.setSocketAddressResolver(new SocketAddressResolver.Sync());
}

public AbstractConnector newConnector(Transport transport, Server server)
public AbstractConnector newConnector(TransportType transportType, Server server)
{
return switch (transport)
return switch (transportType)
{
case HTTP:
case HTTPS:
case H2C:
case H2:
case FCGI:
yield new ServerConnector(server, 1, 1, newServerConnectionFactory(transport));
case H3:
yield new QuicServerConnector(server, serverQuicConfig, newServerConnectionFactory(transport));
yield new ServerConnector(server, 1, 1, newServerConnectionFactory(transportType));
case H3_QUICHE:
yield new QuicServerConnector(server, serverQuicConfig, newServerConnectionFactory(transportType));
};
}

protected ConnectionFactory[] newServerConnectionFactory(Transport transport)
protected ConnectionFactory[] newServerConnectionFactory(TransportType transportType)
{
List<ConnectionFactory> list = switch (transport)
List<ConnectionFactory> list = switch (transportType)
{
case HTTP -> List.of(new HttpConnectionFactory(httpConfig));
case HTTPS ->
Expand All @@ -354,7 +354,7 @@ protected ConnectionFactory[] newServerConnectionFactory(Transport transport)
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactoryServer, alpn.getProtocol());
yield List.of(ssl, alpn, h2);
}
case H3 ->
case H3_QUICHE ->
{
httpConfig.addCustomizer(new SecureRequestCustomizer());
httpConfig.addCustomizer(new HostHeaderCustomizer());
Expand All @@ -370,11 +370,11 @@ protected SslContextFactory.Client newSslContextFactoryClient()
return new SslContextFactory.Client(true);
}

protected HttpClientTransport newHttpClientTransport(Transport transport) throws Exception
protected HttpClientTransport newHttpClientTransport(TransportType transportType) throws Exception
{
clientConnector = new ClientConnector();
clientConnector.setSelectors(1);
return switch (transport)
return switch (transportType)
{
case HTTP, HTTPS ->
{
Expand All @@ -387,7 +387,7 @@ protected HttpClientTransport newHttpClientTransport(Transport transport) throws
HTTP2Client http2Client = new HTTP2Client(clientConnector);
yield new HttpClientTransportOverHTTP2(http2Client);
}
case H3 ->
case H3_QUICHE ->
{
SslContextFactory.Client sslClient = newSslContextFactoryClient();
HTTP3Client http3Client = new HTTP3Client(new ClientQuicConfiguration(sslClient, null), clientConnector);
Expand All @@ -397,9 +397,9 @@ protected HttpClientTransport newHttpClientTransport(Transport transport) throws
};
}

protected URI newURI(Transport transport)
protected URI newURI(TransportType transportType)
{
String scheme = transport.isSecure() ? "https" : "http";
String scheme = transportType.isSecure() ? "https" : "http";
String uri = scheme + "://localhost";
if (connector instanceof NetworkConnector networkConnector)
uri += ":" + networkConnector.getLocalPort();
Expand Down Expand Up @@ -447,16 +447,16 @@ public static int freePort() throws IOException
}
}

public enum Transport
public enum TransportType
{
HTTP, HTTPS, H2C, H2, H3, FCGI;
HTTP, HTTPS, H2C, H2, H3_QUICHE, FCGI;

public boolean isSecure()
{
return switch (this)
{
case HTTP, H2C, FCGI -> false;
case HTTPS, H2, H3 -> true;
case HTTPS, H2, H3_QUICHE -> true;
};
}

Expand All @@ -465,7 +465,7 @@ public boolean isMultiplexed()
return switch (this)
{
case HTTP, HTTPS, FCGI -> false;
case H2C, H2, H3 -> true;
case H2C, H2, H3_QUICHE -> true;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public class AsyncRequestContentTest extends AbstractTest
{
@ParameterizedTest
@MethodSource("transports")
public void testEmptyAsyncContent(Transport transport) throws Exception
public void testEmptyAsyncContent(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

AsyncRequestContent content = new AsyncRequestContent();
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -61,13 +61,13 @@ public void testEmptyAsyncContent(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testAsyncContent(Transport transport) throws Exception
public void testAsyncContent(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

AsyncRequestContent content = new AsyncRequestContent();
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -83,14 +83,14 @@ public void testAsyncContent(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testEmptyInputStream(Transport transport) throws Exception
public void testEmptyInputStream(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

InputStreamRequestContent content =
new InputStreamRequestContent(new ByteArrayInputStream(new byte[0]));
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -104,14 +104,14 @@ public void testEmptyInputStream(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testInputStream(Transport transport) throws Exception
public void testInputStream(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

InputStreamRequestContent content =
new InputStreamRequestContent(new ByteArrayInputStream(new byte[1]));
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -125,13 +125,13 @@ public void testInputStream(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testEmptyOutputStream(Transport transport) throws Exception
public void testEmptyOutputStream(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

OutputStreamRequestContent content = new OutputStreamRequestContent();
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -146,13 +146,13 @@ public void testEmptyOutputStream(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testOutputStream(Transport transport) throws Exception
public void testOutputStream(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

OutputStreamRequestContent content = new OutputStreamRequestContent();
CountDownLatch latch = new CountDownLatch(1);
client.POST(newURI(transport))
client.POST(newURI(transportType))
.body(content)
.send(result ->
{
Expand All @@ -170,15 +170,15 @@ public void testOutputStream(Transport transport) throws Exception

@ParameterizedTest
@MethodSource("transports")
public void testBufferReuseAfterCallbackCompleted(Transport transport) throws Exception
public void testBufferReuseAfterCallbackCompleted(TransportType transportType) throws Exception
{
start(transport, new ConsumeInputHandler());
start(transportType, new ConsumeInputHandler());

AsyncRequestContent content = new AsyncRequestContent();

CountDownLatch latch = new CountDownLatch(1);
List<Byte> requestContent = new ArrayList<>();
client.POST(newURI(transport))
client.POST(newURI(transportType))
.onRequestContent(((request, buffer) -> requestContent.add(buffer.get())))
.body(content)
.send(result ->
Expand Down
Loading

0 comments on commit b96f49f

Please sign in to comment.