Skip to content

Configurable server port for the vertx test using HttpTestBase.DEFAULT_HTTP_PORT #4991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Runs the tests
> mvn test
```

Tests can be run with specified HTTP port and/or HTTPS port.

```
> mvn test -Dvertx.httpPort=8888 -Dvertx.httpsPort=4044
```

Vert.x supports native transport on BSD and Linux, to run the tests with native transport

```
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/io/vertx/core/VertxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ public void testFinalizeHttpClient() throws Exception {
closed1.set(true);
});
})
.listen(8080, "localhost")
.listen(HttpTestBase.DEFAULT_HTTP_PORT, "localhost")
.onComplete(onSuccess(server -> latch.countDown()));
awaitLatch(latch);
HttpClient client = vertx.createHttpClient();
// client.connect(1234, "localhost");
client.request(HttpMethod.GET, 8080, "localhost", "/").onSuccess(req -> {
client.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "localhost", "/").onSuccess(req -> {
req.send();
});
(((CleanableHttpClient)client).delegate).netClient().closeFuture().onComplete(ar -> {
Expand Down Expand Up @@ -210,11 +210,11 @@ public void testFinalizeHttpClientWithRequestNotYetSent() throws Exception {
"\r\n");
});
})
.listen(8080, "localhost")
.listen(HttpTestBase.DEFAULT_HTTP_PORT, "localhost")
.onComplete(onSuccess(server -> latch.countDown()));
awaitLatch(latch);
HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1));
Future<HttpClientRequest> fut = client.request(HttpMethod.GET, 8080, "localhost", "/");
Future<HttpClientRequest> fut = client.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "localhost", "/");
assertWaitUntil(fut::succeeded);
WeakReference<HttpClient> ref = new WeakReference<>(client);
client = null;
Expand Down Expand Up @@ -245,10 +245,10 @@ public void testCascadeCloseHttpClient() throws Exception {
req.connection().closeHandler(v -> {
connected.set(false);
});
}).listen(8080, "localhost"));
}).listen(HttpTestBase.DEFAULT_HTTP_PORT, "localhost"));
VertxInternal vertx2 = (VertxInternal) Vertx.vertx();
HttpClient client = vertx2.createHttpClient();
client.request(HttpMethod.GET, 8080, "localhost", "/").onComplete(onSuccess(req -> {
client.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "localhost", "/").onComplete(onSuccess(req -> {
req.send();
}));
waitUntil(connected::get);
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/io/vertx/core/VirtualThreadDeploymentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
package io.vertx.core;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.*;
import io.vertx.core.impl.VertxInternal;
import io.vertx.test.core.VertxTestBase;
import junit.framework.AssertionFailedError;
Expand Down Expand Up @@ -108,7 +105,7 @@ public void start() {
inflight.decrementAndGet();
processing.set(false);
});
server.listen(8080, "localhost").await();
server.listen(HttpTestBase.DEFAULT_HTTP_PORT, "localhost").await();
}
}, new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD))
.toCompletionStage()
Expand All @@ -118,7 +115,7 @@ public void start() {
int numReq = 10;
waitFor(numReq);
for (int i = 0;i < numReq;i++) {
Future<Buffer> resp = client.request(HttpMethod.GET, 8080, "localhost", "/")
Future<Buffer> resp = client.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "localhost", "/")
.compose(req -> req.send()
.compose(HttpClientResponse::body));
resp.onComplete(onSuccess(v -> complete()));
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/io/vertx/core/dns/HostnameResolutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpTestBase;
import io.vertx.core.impl.HostnameResolver;
import io.vertx.core.impl.Utils;
import io.vertx.core.impl.VertxImpl;
Expand Down Expand Up @@ -153,11 +154,11 @@ public void testHttp() throws Exception {
});
try {
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(8080, "vertx.io").onComplete(onSuccess(s -> {
server.listen(HttpTestBase.DEFAULT_HTTP_PORT, "vertx.io").onComplete(onSuccess(s -> {
listenLatch.countDown();
}));
awaitLatch(listenLatch);
client.request(HttpMethod.GET, 8080, "vertx.io", "/somepath").onComplete(onSuccess(req -> {
client.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "vertx.io", "/somepath").onComplete(onSuccess(req -> {
req.send().onComplete(onSuccess(resp -> {
Buffer buffer = Buffer.buffer();
resp.handler(buffer::appendBuffer);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/vertx/core/file/FileResolverTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public void testFileSystemReadDirectory() {
@Test
public void testSendFileFromClasspath() {
waitFor(2);
vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(res -> {
vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT)).requestHandler(res -> {
res.response()
.sendFile("webroot/somefile.html")
.onComplete(onSuccess(v -> complete()));
}).listen().onComplete(onSuccess(res -> {
vertx.createHttpClient(new HttpClientOptions())
.request(HttpMethod.GET, 8080, "localhost", "/")
.request(HttpMethod.GET, HttpTestBase.DEFAULT_HTTP_PORT, "localhost", "/")
.compose(req -> req
.send()
.andThen(onSuccess(resp -> assertEquals(200, resp.statusCode())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testResetStreamRequestSent() throws Exception {
stream.reset(cause);
});
stream.writeHead(new HttpRequestHead(
HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, false, new StreamPriority(), false);
HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), DEFAULT_HTTP_HOST_AND_PORT, "", null), false, Unpooled.EMPTY_BUFFER, false, new StreamPriority(), false);
}));
}));
await();
Expand All @@ -97,7 +97,7 @@ public void testServerConnectionClose() throws Exception {
complete();
});
stream.writeHead(new HttpRequestHead(
HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), "localhost:8080", "", null), false, Unpooled.EMPTY_BUFFER, true, new StreamPriority(), false);
HttpMethod.GET, "/", MultiMap.caseInsensitiveMultiMap(), DEFAULT_HTTP_HOST_AND_PORT, "", null), false, Unpooled.EMPTY_BUFFER, true, new StreamPriority(), false);
}));
}));
await();
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/io/vertx/core/http/Http1xProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void testFilter(boolean accept) throws Exception {
if (accept) {
assertProxiedRequest(DEFAULT_HTTP_HOST);
}
assertEquals(Collections.singleton(SocketAddress.inetSocketAddress(8080, "localhost")), filtered);
assertEquals(Collections.singleton(SocketAddress.inetSocketAddress(DEFAULT_HTTP_PORT, "localhost")), filtered);
testComplete();
}));
await();
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testHttpProxyRequestOverrideClientSsl() throws Exception {
client = vertx.createHttpClient(new HttpClientOptions()
.setSsl(true).setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.port())));
testHttpProxyRequest(() -> client
.request(new RequestOptions().setSsl(false).setHost("localhost").setPort(8080))
.request(new RequestOptions().setSsl(false).setHost("localhost").setPort(DEFAULT_HTTP_PORT))
.compose(HttpClientRequest::send)).onComplete(onSuccess(v -> {
assertProxiedRequest(DEFAULT_HTTP_HOST);
testComplete();
Expand All @@ -166,7 +166,7 @@ public void testHttpProxyRequestOverrideClientSsl() throws Exception {

private void assertProxiedRequest(String host) {
assertNotNull("request did not go through proxy", proxy.getLastUri());
assertEquals("Host header doesn't contain target host", host + ":8080", proxy.getLastRequestHeaders().get("Host"));
assertEquals("Host header doesn't contain target host", host + ":" + DEFAULT_HTTP_PORT, proxy.getLastRequestHeaders().get("Host"));
}

private Future<Void> testHttpProxyRequest(Supplier<Future<HttpClientResponse>> reqFact) throws Exception {
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testHttpProxyRequestAuth() throws Exception {
req.send().onComplete(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertNotNull("request did not go through proxy", proxy.getLastUri());
assertEquals("Host header doesn't contain target host", "localhost:8080", proxy.getLastRequestHeaders().get("Host"));
assertEquals("Host header doesn't contain target host", DEFAULT_HTTP_HOST_AND_PORT, proxy.getLastRequestHeaders().get("Host"));
testComplete();
}));
}));
Expand All @@ -221,9 +221,9 @@ public void testHttpProxyFtpRequest() throws Exception {
startProxy(null, ProxyType.HTTP);
client.close();
client = vertx.createHttpClient(new HttpClientOptions()
.setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.port())));
.setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost(DEFAULT_HTTP_HOST).setPort(proxy.port())));
final String url = "ftp://ftp.gnu.org/gnu/";
proxy.setForceUri("http://localhost:8080/");
proxy.setForceUri("http://" + DEFAULT_HTTP_HOST_AND_PORT+ "/");
server.requestHandler(req -> {
req.response().end();
});
Expand Down Expand Up @@ -547,7 +547,7 @@ private void testWebSocket(HttpServerOptions serverOptions, WebSocketClientOptio
if (proxied) {
assertNotNull("request did not go through proxy", proxy.getLastUri());
if (clientOptions.getProxyOptions().getType() == ProxyType.HTTP) {
assertEquals("Host header doesn't contain target host", "localhost:4043", proxy.getLastRequestHeaders().get("Host"));
assertEquals("Host header doesn't contain target host", DEFAULT_HTTPS_HOST_AND_PORT, proxy.getLastRequestHeaders().get("Host"));
}
} else {
assertNull("request did go through proxy", proxy.getLastUri());
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/io/vertx/core/http/Http1xTLSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ public void testAlpn() throws Exception {
@Test
// Client trusts all server certs
public void testClearClientRequestOptionsSetSSL() throws Exception {
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(4043).setURI(DEFAULT_TEST_URI).setSsl(true);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setPort(DEFAULT_HTTPS_PORT).setURI(DEFAULT_TEST_URI).setSsl(true);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).requestOptions(options).pass();
}

@Test
// Client trusts all server certs
public void testSSLClientRequestOptionsSetSSL() throws Exception {
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(4043).setURI(DEFAULT_TEST_URI).setSsl(true);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setPort(DEFAULT_HTTPS_PORT).setURI(DEFAULT_TEST_URI).setSsl(true);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestOptions(options).pass();
}

@Test
// Client trusts all server certs
public void testClearClientRequestOptionsSetClear() throws Exception {
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setURI(DEFAULT_TEST_URI).setPort(DEFAULT_HTTPS_PORT).setSsl(false);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestOptions(options).pass();
}

@Test
// Client trusts all server certs
public void testSSLClientRequestOptionsSetClear() throws Exception {
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setURI(DEFAULT_TEST_URI).setPort(DEFAULT_HTTPS_PORT).setSsl(false);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).serverSSL(false).requestOptions(options).pass();
}

Expand All @@ -92,28 +92,28 @@ public void testSSLClientRequestOptionsSetClear() throws Exception {
@Test
// Client trusts all server certs
public void testClearClientRequestAbsSetSSL() throws Exception {
String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI;
String absoluteURI = "https://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI;
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).requestProvider(c -> c.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI(absoluteURI))).pass();
}

@Test
// Client trusts all server certs
public void testSSLClientRequestAbsSetSSL() throws Exception {
String absoluteURI = "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI;
String absoluteURI = "https://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI;
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).requestProvider(c -> c.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI(absoluteURI))).pass();
}

@Test
// Client trusts all server certs
public void testClearClientRequestAbsSetClear() throws Exception {
String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI;
String absoluteURI = "http://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI;
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(false).serverSSL(false).requestProvider(c -> c.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI(absoluteURI))).pass();
}

@Test
// Client trusts all server certs
public void testSSLClientRequestAbsSetClear() throws Exception {
String absoluteURI = "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI;
String absoluteURI = "http://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI;
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).clientSSL(true).serverSSL(false).requestProvider(c -> c.request(new RequestOptions().setMethod(HttpMethod.POST).setAbsoluteURI(absoluteURI))).pass();
}

Expand All @@ -125,7 +125,7 @@ public void testRedirectToSSL() throws Exception {
.setHost(DEFAULT_HTTP_HOST)
.setPort(DEFAULT_HTTP_PORT)
).requestHandler(req -> {
req.response().setStatusCode(303).putHeader("location", "https://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end();
req.response().setStatusCode(303).putHeader("location", "https://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI).end();
});
startServer(redirectServer);
try {
Expand All @@ -149,11 +149,11 @@ public void testRedirectFromSSL() throws Exception {
.setHost(DEFAULT_HTTP_HOST)
.setPort(DEFAULT_HTTP_PORT)
).requestHandler(req -> {
req.response().setStatusCode(303).putHeader("location", "http://" + DEFAULT_HTTP_HOST + ":4043/" + DEFAULT_TEST_URI).end();
req.response().setStatusCode(303).putHeader("location", "http://" + DEFAULT_HTTPS_HOST_AND_PORT + "/" + DEFAULT_TEST_URI).end();
});
startServer(redirectServer);
try {
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTP_HOST).setURI(DEFAULT_TEST_URI).setPort(4043).setSsl(false);
RequestOptions options = new RequestOptions().setHost(DEFAULT_HTTPS_HOST).setURI(DEFAULT_TEST_URI).setPort(DEFAULT_HTTPS_PORT).setSsl(false);
testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.NONE, Trust.NONE)
.clientSSL(true)
.serverSSL(false)
Expand Down
Loading