From cd0ed6ea0111fb7d8723788559d27032e6c4fd79 Mon Sep 17 00:00:00 2001 From: zero88 Date: Mon, 5 Aug 2024 11:46:58 +0700 Subject: [PATCH] refactor(:core:test): fix test --- .../java/cloud/playio/qwe/QWEBootConfig.java | 8 +++++--- .../java/cloud/playio/qwe/QWEConfigTest.java | 20 ++++++++++--------- .../playio/qwe/utils/NetworkUtilsTest.java | 6 ++++-- core/src/test/resources/def-system-cfg.json | 7 +++---- core/src/test/resources/full-system-cfg.json | 7 +++---- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/cloud/playio/qwe/QWEBootConfig.java b/core/src/main/java/cloud/playio/qwe/QWEBootConfig.java index 913aa8af..ac2e6b61 100644 --- a/core/src/main/java/cloud/playio/qwe/QWEBootConfig.java +++ b/core/src/main/java/cloud/playio/qwe/QWEBootConfig.java @@ -16,6 +16,7 @@ import io.vertx.core.metrics.MetricsOptions; import io.vertx.core.spi.cluster.ClusterManager; import io.vertx.core.tracing.TracingOptions; + import cloud.playio.qwe.cluster.ClusterType; import cloud.playio.qwe.launcher.BootCommand; import cloud.playio.qwe.utils.NetworkUtils; @@ -58,7 +59,7 @@ public final class QWEBootConfig extends VertxOptions implements IConfig { @Accessors(chain = true) private JsonObject keyStoreConfig; - public QWEBootConfig() {this.delegate = defVertxOpts();} + public QWEBootConfig() { this.delegate = defVertxOpts(); } @JsonCreator public QWEBootConfig(Map map) { @@ -93,14 +94,15 @@ public QWEBootConfig setClusterConfigFile(String clusterConfigFile) { private VertxOptions defVertxOpts() { return new VertxOptions().setHAGroup(DEFAULT_HA_GROUP) .setEventBusOptions(defEventBusOpts()) + .setEventLoopPoolSize(8) .setFileSystemOptions(defFileSysOpts()); } @Override - public String configKey() {return QWEConfig.BOOT_CONF_KEY;} + public String configKey() { return QWEConfig.BOOT_CONF_KEY; } @Override - public Class parent() {return QWEConfig.class;} + public Class parent() { return QWEConfig.class; } @Override public JsonObject toJson() { diff --git a/core/src/test/java/cloud/playio/qwe/QWEConfigTest.java b/core/src/test/java/cloud/playio/qwe/QWEConfigTest.java index cdea4c15..a2f817d6 100644 --- a/core/src/test/java/cloud/playio/qwe/QWEConfigTest.java +++ b/core/src/test/java/cloud/playio/qwe/QWEConfigTest.java @@ -6,9 +6,11 @@ import org.junit.jupiter.api.Test; import io.vertx.core.DeploymentOptions; +import io.vertx.core.ThreadingModel; import io.vertx.core.eventbus.DeliveryOptions; import io.vertx.core.json.DecodeException; import io.vertx.core.json.JsonObject; + import cloud.playio.qwe.QWEConfig.QWEDeployConfig; import cloud.playio.qwe.exceptions.ConfigException; @@ -71,7 +73,7 @@ public void test_deserialize_child_from_root() { Assertions.assertEquals(10, cfg.getInstances()); Assertions.assertEquals(60000000000L, cfg.getMaxWorkerExecuteTime()); Assertions.assertEquals(TimeUnit.NANOSECONDS, cfg.getMaxWorkerExecuteTimeUnit()); - Assertions.assertFalse(cfg.isWorker()); + Assertions.assertEquals(ThreadingModel.EVENT_LOOP, cfg.getThreadingModel()); } @Test @@ -94,10 +96,10 @@ public void test_blank() { Assertions.assertNotNull(cfg.getAppConfig().dataDir()); Assertions.assertTrue(cfg.getAppConfig().other().isEmpty()); Assertions.assertNotNull(cfg.getDeployConfig()); - JsonHelper.assertJson(new JsonObject("{\"worker\":false,\"workerPoolSize\":20," + - "\"maxWorkerExecuteTime\":60000000000,\"ha\":false,\"instances\":1," + - "\"maxWorkerExecuteTimeUnit\":\"NANOSECONDS\"}"), - cfg.getDeployConfig().toJson()); + JsonHelper.assertJson(new JsonObject( + "{\"worker\":false,\"workerPoolSize\":20,\"threadingModel\":\"EVENT_LOOP\"," + + "\"maxWorkerExecuteTime\":60000000000,\"ha\":false,\"instances\":1," + + "\"maxWorkerExecuteTimeUnit\":\"NANOSECONDS\"}"), cfg.getDeployConfig().toJson()); Assertions.assertNull(cfg.getBootConfig()); } @@ -110,10 +112,10 @@ public void test_blank_with_app_cfg() { Assertions.assertEquals(1, config.getAppConfig().other().size()); Assertions.assertEquals(1, config.getAppConfig().lookup("hello")); Assertions.assertNotNull(config.getDeployConfig()); - JsonHelper.assertJson(new JsonObject("{\"worker\":false,\"workerPoolSize\":20," + - "\"maxWorkerExecuteTime\":60000000000,\"ha\":false,\"instances\":1," + - "\"maxWorkerExecuteTimeUnit\":\"NANOSECONDS\"}"), - config.getDeployConfig().toJson()); + JsonHelper.assertJson(new JsonObject( + "{\"worker\":false,\"workerPoolSize\":20,\"threadingModel\":\"EVENT_LOOP\"," + + "\"maxWorkerExecuteTime\":60000000000,\"ha\":false,\"instances\":1," + + "\"maxWorkerExecuteTimeUnit\":\"NANOSECONDS\"}"), config.getDeployConfig().toJson()); Assertions.assertNull(config.getBootConfig()); } diff --git a/core/src/test/java/cloud/playio/qwe/utils/NetworkUtilsTest.java b/core/src/test/java/cloud/playio/qwe/utils/NetworkUtilsTest.java index 22c688e7..2252db71 100644 --- a/core/src/test/java/cloud/playio/qwe/utils/NetworkUtilsTest.java +++ b/core/src/test/java/cloud/playio/qwe/utils/NetworkUtilsTest.java @@ -9,7 +9,9 @@ public class NetworkUtilsTest { @Test public void test_get_public_ipv4() { - Assertions.assertNotNull(NetworkUtils.getPublicIpv4()); + final String address = NetworkUtils.getPublicIpv4(); + System.out.println(address); + Assertions.assertNotNull(address); } @Test @@ -18,8 +20,8 @@ public void test_get_socket_ipv4_address() { Assertions.assertNotNull(address); Assertions.assertEquals("127.0.0.1", address.getHostName()); Assertions.assertEquals("127.0.0.1", address.getHostString()); - Assertions.assertEquals("127.0.0.1:9090", address.toString()); Assertions.assertEquals(9090, address.getPort()); + Assertions.assertEquals("127.0.0.1/:9090", address.toString()); } } diff --git a/core/src/test/resources/def-system-cfg.json b/core/src/test/resources/def-system-cfg.json index 9103bdff..7aa5c0d3 100644 --- a/core/src/test/resources/def-system-cfg.json +++ b/core/src/test/resources/def-system-cfg.json @@ -24,9 +24,8 @@ "crlValues": [], "enabledCipherSuites": [], "enabledSecureTransportProtocols": [ - "TLSv1", - "TLSv1.1", - "TLSv1.2" + "TLSv1.2", + "TLSv1.3" ], "idleTimeout": 0, "idleTimeoutUnit": "SECONDS", @@ -51,7 +50,7 @@ "trustAll": true, "useAlpn": false }, - "eventLoopPoolSize": 32, + "eventLoopPoolSize": 8, "fileSystemOptions": { "classPathResolvingEnabled": true, "fileCacheDir": "/tmp/qwe-cache", diff --git a/core/src/test/resources/full-system-cfg.json b/core/src/test/resources/full-system-cfg.json index 0d2ba70c..b9eb3844 100644 --- a/core/src/test/resources/full-system-cfg.json +++ b/core/src/test/resources/full-system-cfg.json @@ -1,6 +1,6 @@ { "__system__": { - "eventLoopPoolSize": 32, + "eventLoopPoolSize": 8, "workerPoolSize": 20, "internalBlockingPoolSize": 20, "blockedThreadCheckInterval": 1000, @@ -36,9 +36,8 @@ "crlValues": [], "useAlpn": false, "enabledSecureTransportProtocols": [ - "TLSv1", - "TLSv1.1", - "TLSv1.2" + "TLSv1.2", + "TLSv1.3" ], "tcpFastOpen": false, "tcpCork": false,