Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8d2d14

Browse files
committed
Use RuntimeValues to store and retrieve the real runtime values of HTTP ports
1 parent1519b51 commitc8d2d14

File tree

15 files changed

+183
-115
lines changed

15 files changed

+183
-115
lines changed

‎extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
importio.quarkus.vertx.http.runtime.CurrentRequestProducer;
6969
importio.quarkus.vertx.http.runtime.CurrentVertxRequest;
7070
importio.quarkus.vertx.http.runtime.HttpCertificateUpdateEventListener;
71+
importio.quarkus.vertx.http.runtime.HttpServerProducer;
7172
importio.quarkus.vertx.http.runtime.VertxConfigBuilder;
7273
importio.quarkus.vertx.http.runtime.VertxHttpBuildTimeConfig;
7374
importio.quarkus.vertx.http.runtime.VertxHttpConfig.InsecureRequests;
@@ -161,6 +162,7 @@ FilterBuildItem cors(CORSRecorder recorder,
161162
AdditionalBeanBuildItemadditionalBeans() {
162163
returnAdditionalBeanBuildItem.builder()
163164
.setUnremovable()
165+
.addBeanClass(HttpServerProducer.class)
164166
.addBeanClass(CurrentVertxRequest.class)
165167
.addBeanClass(CurrentRequestProducer.class)
166168
.addBeanClass(HttpCertificateUpdateEventListener.class)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packageio.quarkus.vertx.http;
2+
3+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
4+
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
5+
6+
importjakarta.inject.Inject;
7+
8+
importorg.junit.jupiter.api.Test;
9+
importorg.junit.jupiter.api.extension.RegisterExtension;
10+
11+
importio.quarkus.test.QuarkusUnitTest;
12+
importio.quarkus.vertx.http.runtime.HttpServer;
13+
14+
publicclassHttpServerTest {
15+
@RegisterExtension
16+
staticfinalQuarkusUnitTestCONFIG =newQuarkusUnitTest();
17+
18+
@Inject
19+
HttpServerwebServer;
20+
21+
@Test
22+
voidports() {
23+
assertTrue(webServer.getPort() >0);
24+
assertEquals(-1,webServer.getSecurePort());
25+
assertEquals(-1,webServer.getManagementPort());
26+
}
27+
}

‎extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/RandomPortTest.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
importjava.net.URL;
66

77
importjakarta.enterprise.event.Observes;
8+
importjakarta.inject.Inject;
89

910
importorg.eclipse.microprofile.config.ConfigProvider;
10-
importorg.eclipse.microprofile.config.inject.ConfigProperty;
1111
importorg.hamcrest.Matchers;
1212
importorg.jboss.shrinkwrap.api.asset.StringAsset;
1313
importorg.junit.jupiter.api.Test;
1414
importorg.junit.jupiter.api.extension.RegisterExtension;
1515

1616
importio.quarkus.test.QuarkusUnitTest;
1717
importio.quarkus.test.common.http.TestHTTPResource;
18+
importio.quarkus.vertx.http.runtime.VertxHttpConfig;
1819
importio.restassured.RestAssured;
1920
importio.vertx.core.Handler;
2021
importio.vertx.ext.web.Router;
@@ -30,6 +31,8 @@ public class RandomPortTest {
3031

3132
@TestHTTPResource("test")
3233
URLurl;
34+
@Inject
35+
VertxHttpConfigvertxHttpConfig;
3336

3437
@Test
3538
publicvoidportShouldNotBeZero() {
@@ -42,16 +45,17 @@ public void testActualPortAccessibleToApp() {
4245
RestAssured.get("/app").then().body(Matchers.equalTo(Integer.toString(url.getPort())));
4346
}
4447

45-
publicstaticclassAppClass {
46-
47-
@ConfigProperty(name ="quarkus.http.port")
48-
Stringport;
48+
@Test
49+
voidmappingPortIsZero() {
50+
assertThat(vertxHttpConfig.testPort()).isZero();
51+
}
4952

53+
publicstaticclassAppClass {
5054
publicvoidroute(@ObservesRouterrouter) {
5155
router.route("/test").handler(newHandler<RoutingContext>() {
5256
@Override
5357
publicvoidhandle(RoutingContextevent) {
54-
event.response().end(System.getProperty("quarkus.http.test-port"));
58+
event.response().end(ConfigProvider.getConfig().getValue("quarkus.http.test-port",String.class));
5559
}
5660
});
5761
router.route("/app").handler(newHandler<RoutingContext>() {
@@ -62,5 +66,4 @@ public void handle(RoutingContext event) {
6266
});
6367
}
6468
}
65-
6669
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
packageio.quarkus.vertx.http.runtime;
2+
3+
importio.quarkus.runtime.RuntimeValues;
4+
importio.quarkus.runtime.RuntimeValues.RuntimeKey;
5+
6+
publicclassHttpServer {
7+
privatefinalstaticHttpServerINSTANCE =newHttpServer();
8+
9+
publicstaticfinalRuntimeKey<Integer>HTTP_PORT =RuntimeKey.intKey("quarkus.http.port");
10+
publicstaticfinalRuntimeKey<Integer>HTTP_TEST_PORT =RuntimeKey.intKey("quarkus.http.test-port");
11+
publicstaticfinalRuntimeKey<Integer>HTTPS_PORT =RuntimeKey.intKey("quarkus.http.ssl-port");
12+
publicstaticfinalRuntimeKey<Integer>HTTPS_TEST_PORT =RuntimeKey.intKey("quarkus.http.test-ssl-port");
13+
publicstaticfinalRuntimeKey<Integer>MANAGEMENT_PORT =RuntimeKey.intKey("quarkus.management.port");
14+
publicstaticfinalRuntimeKey<Integer>MANAGEMENT_TEST_PORT =RuntimeKey.intKey("quarkus.management.test-port");
15+
16+
privateHttpServer() {
17+
}
18+
19+
/**
20+
* Return the http port that Quarkus is listening on.
21+
*
22+
* @return the port or <code>-1</code> if Quarkus is not set to listen to the http port.
23+
*/
24+
publicintgetPort() {
25+
// TODO - What if this method gets called before being set? Should this be an event instead?
26+
returnRuntimeValues.get(HTTP_PORT, -1);
27+
}
28+
29+
staticvoidsetPort(intport) {
30+
RuntimeValues.register(HTTP_PORT,port);
31+
}
32+
33+
staticvoidsetTestPort(inttestPort) {
34+
RuntimeValues.register(HTTP_TEST_PORT,testPort);
35+
}
36+
37+
/**
38+
* Return the https port that Quarkus is listening on.
39+
*
40+
* @return the port or <code>-1</code> if Quarkus is not set to listen to the https port.
41+
*/
42+
publicintgetSecurePort() {
43+
returnRuntimeValues.get(HTTPS_PORT, -1);
44+
}
45+
46+
staticvoidsetSecurePort(intport) {
47+
RuntimeValues.register(HTTPS_PORT,port);
48+
}
49+
50+
staticvoidsetSecureTestPort(inttestPort) {
51+
RuntimeValues.register(HTTPS_TEST_PORT,testPort);
52+
}
53+
54+
/**
55+
* Return the management http port that Quarkus is listening on.
56+
*
57+
* @return the port or <code>-1</code> if Quarkus is not set to listen to the management http port.
58+
*/
59+
publicintgetManagementPort() {
60+
returnRuntimeValues.get(MANAGEMENT_PORT, -1);
61+
}
62+
63+
staticvoidsetManagementPort(intmanagementPort) {
64+
RuntimeValues.register(MANAGEMENT_PORT,managementPort);
65+
}
66+
67+
staticvoidsetManagementTestPort(inttestPort) {
68+
RuntimeValues.register(MANAGEMENT_TEST_PORT,testPort);
69+
}
70+
71+
publicstaticHttpServerinstance() {
72+
returnINSTANCE;
73+
}
74+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packageio.quarkus.vertx.http.runtime;
2+
3+
importjakarta.enterprise.inject.Produces;
4+
importjakarta.inject.Singleton;
5+
6+
@Singleton
7+
publicclassHttpServerProducer {
8+
@Produces
9+
@Singleton
10+
publicHttpServerproducer() {
11+
returnHttpServer.instance();
12+
}
13+
}

‎extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java‎

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
importio.smallrye.config.SmallRyeConfigBuilderCustomizer;
101101
importio.vertx.core.AbstractVerticle;
102102
importio.vertx.core.AsyncResult;
103-
importio.vertx.core.Closeable;
104103
importio.vertx.core.Context;
105104
importio.vertx.core.DeploymentOptions;
106105
importio.vertx.core.Handler;
@@ -769,15 +768,10 @@ private static CompletableFuture<HttpServer> initializeManagementInterface(Vertx
769768

770769
actualManagementPort =ar.result().actualPort();
771770
if (actualManagementPort !=httpManagementServerOptions.getPort()) {
772-
varmanagementPortSystemProperties =newPortSystemProperties();
773-
managementPortSystemProperties.set("management",actualManagementPort,launchMode);
774-
((VertxInternal)vertx).addCloseHook(newCloseable() {
775-
@Override
776-
publicvoidclose(Promise<Void>completion) {
777-
managementPortSystemProperties.restore();
778-
completion.complete();
779-
}
780-
});
771+
io.quarkus.vertx.http.runtime.HttpServer.setManagementPort(actualManagementPort);
772+
if (launchMode.isDevOrTest()) {
773+
io.quarkus.vertx.http.runtime.HttpServer.setManagementTestPort(actualManagementPort);
774+
}
781775
}
782776
managementInterfaceFuture.complete(ar.result());
783777
}
@@ -1180,9 +1174,6 @@ private static class WebDeploymentVerticle extends AbstractVerticle implements R
11801174
privatefinalHttpServerOptionshttpsOptions;
11811175
privatefinalHttpServerOptionsdomainSocketOptions;
11821176
privatefinalLaunchModelaunchMode;
1183-
privatevolatilebooleanclearHttpProperty =false;
1184-
privatevolatilebooleanclearHttpsProperty =false;
1185-
privatevolatilePortSystemPropertiesportSystemProperties;
11861177
privatefinalInsecureRequestsinsecureRequests;
11871178
privatefinalVertxHttpConfigquarkusConfig;
11881179
privatefinalAtomicIntegerconnectionCount;
@@ -1364,23 +1355,17 @@ public void handle(AsyncResult<HttpServer> event) {
13641355
if (https) {
13651356
actualHttpsPort =actualPort;
13661357
validateHttpPorts(actualHttpPort,actualHttpsPort);
1358+
io.quarkus.vertx.http.runtime.HttpServer.setSecurePort(actualPort);
1359+
if (launchMode.isDevOrTest()) {
1360+
io.quarkus.vertx.http.runtime.HttpServer.setSecureTestPort(actualPort);
1361+
}
13671362
}else {
13681363
actualHttpPort =actualPort;
13691364
validateHttpPorts(actualHttpPort,actualHttpsPort);
1370-
}
1371-
if (actualPort !=options.getPort()) {
1372-
// Override quarkus.http(s)?.(test-)?port
1373-
Stringschema;
1374-
if (https) {
1375-
clearHttpsProperty =true;
1376-
schema ="https";
1377-
}else {
1378-
clearHttpProperty =true;
1379-
actualHttpPort =actualPort;
1380-
schema ="http";
1365+
io.quarkus.vertx.http.runtime.HttpServer.setPort(actualPort);
1366+
if (launchMode.isDevOrTest()) {
1367+
io.quarkus.vertx.http.runtime.HttpServer.setTestPort(actualPort);
13811368
}
1382-
portSystemProperties =newPortSystemProperties();
1383-
portSystemProperties.set(schema,actualPort,launchMode);
13841369
}
13851370

13861371
if (https && (quarkusConfig.ssl().certificate().reloadPeriod().isPresent())) {
@@ -1451,28 +1436,6 @@ public void stop(Promise<Void> stopFuture) {
14511436

14521437
Handler<AsyncResult<Void>>handleClose =event -> {
14531438
if (remainingCount.decrementAndGet() ==0) {
1454-
1455-
if (clearHttpProperty) {
1456-
StringportPropertyName =launchMode ==LaunchMode.TEST ?"quarkus.http.test-port"
1457-
:"quarkus.http.port";
1458-
System.clearProperty(portPropertyName);
1459-
if (launchMode.isDevOrTest()) {
1460-
System.clearProperty(propertyWithProfilePrefix(portPropertyName));
1461-
}
1462-
1463-
}
1464-
if (clearHttpsProperty) {
1465-
StringportPropertyName =launchMode ==LaunchMode.TEST ?"quarkus.http.test-ssl-port"
1466-
:"quarkus.http.ssl-port";
1467-
System.clearProperty(portPropertyName);
1468-
if (launchMode.isDevOrTest()) {
1469-
System.clearProperty(propertyWithProfilePrefix(portPropertyName));
1470-
}
1471-
}
1472-
if (portSystemProperties !=null) {
1473-
portSystemProperties.restore();
1474-
}
1475-
14761439
stopFuture.complete();
14771440
}
14781441
};
@@ -1488,10 +1451,6 @@ public void stop(Promise<Void> stopFuture) {
14881451
}
14891452
}
14901453

1491-
privateStringpropertyWithProfilePrefix(StringportPropertyName) {
1492-
return"%" +launchMode.getDefaultProfile() +"." +portPropertyName;
1493-
}
1494-
14951454
@Override
14961455
publicvoidbeforeCheckpoint(org.crac.Context<?extendsResource>context)throwsException {
14971456
Promise<Void>p =Promise.promise();

‎integration-tests/google-cloud-functions/src/test/java/io/quarkus/gcp/function/test/HttpFunctionRandomPortTestCase.java‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
importstaticio.restassured.RestAssured.when;
44
importstaticorg.hamcrest.Matchers.is;
55

6-
importorg.junit.jupiter.api.BeforeAll;
6+
importjava.util.Map;
7+
78
importorg.junit.jupiter.api.Test;
89

10+
importio.quarkus.gcp.function.test.HttpFunctionRandomPortTestCase.RandomPort;
911
importio.quarkus.google.cloud.functions.test.FunctionType;
1012
importio.quarkus.google.cloud.functions.test.WithFunction;
1113
importio.quarkus.test.junit.QuarkusTest;
14+
importio.quarkus.test.junit.QuarkusTestProfile;
15+
importio.quarkus.test.junit.TestProfile;
1216

1317
@QuarkusTest
18+
@TestProfile(RandomPort.class)
1419
@WithFunction(FunctionType.HTTP)
1520
classHttpFunctionRandomPortTestCase {
16-
17-
@BeforeAll
18-
publicstaticvoidsetup() {
19-
System.setProperty("quarkus.http.test-port","0");
20-
}
21-
2221
@Test
2322
publicvoidtest() {
2423
// test the function using RestAssured
@@ -28,4 +27,11 @@ public void test() {
2827
.statusCode(200)
2928
.body(is("Hello World!"));
3029
}
30+
31+
publicstaticclassRandomPortimplementsQuarkusTestProfile {
32+
@Override
33+
publicMap<String,String>getConfigOverrides() {
34+
returnMap.of("quarkus.http.test-port","0");
35+
}
36+
}
3137
}

‎integration-tests/grpc-test-random-port/src/test/java/io/quarkus/grpc/examples/hello/RandomPortVertxServerTlsTestBase.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public Map<String, String> getConfigOverrides() {
2121

2222
@Override
2323
protectedStringserverPortProperty() {
24-
return"quarkus.https.test-port";
24+
return"quarkus.http.test-ssl-port";
2525
}
2626
}

‎integration-tests/vertx-http/src/test/java/io/quarkus/it/vertx/RandomTestPortTestCase.java‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
importjava.net.URL;
77
importjava.util.Map;
8-
importjava.util.Optional;
98

10-
importorg.eclipse.microprofile.config.Config;
11-
importorg.eclipse.microprofile.config.ConfigProvider;
129
importorg.eclipse.microprofile.config.inject.ConfigProperty;
1310
importorg.junit.jupiter.api.Test;
1411

@@ -59,23 +56,6 @@ public void testHttpsTestPort() {
5956
assertEquals(httpsTestPort,httpsTestUrl.getPort());
6057
}
6158

62-
@Test
63-
publicvoidtestLegacyProperties() {
64-
Configconfig =ConfigProvider.getConfig();
65-
66-
testLegacyProperty(config,"quarkus.http.ssl-port","quarkus.https.port",httpsPort);
67-
testLegacyProperty(config,"quarkus.http.test-ssl-port","quarkus.https.test-port",httpsTestPort);
68-
testLegacyProperty(config,"%test.quarkus.http.ssl-port","%test.quarkus.https.port",httpsTestPort);
69-
}
70-
71-
privatevoidtestLegacyProperty(Configconfig,StringcorrectName,StringlegacyName,intexpectedValue) {
72-
Optional<Integer>portWithCorrectProperty =config.getOptionalValue(correctName,Integer.class);
73-
Optional<Integer>portWithLegacyProperty =config.getOptionalValue(legacyName,Integer.class);
74-
75-
assertEquals(Optional.of(expectedValue),portWithCorrectProperty);
76-
assertEquals(portWithCorrectProperty,portWithLegacyProperty);
77-
}
78-
7959
publicstaticclassTestPortProfileimplementsQuarkusTestProfile {
8060

8161
@Override

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp