Skip to content
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

Refactor/some improvements #107

Merged
merged 6 commits into from
Aug 5, 2024
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
8 changes: 5 additions & 3 deletions core/src/main/java/cloud/playio/qwe/QWEBootConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> map) {
Expand Down Expand Up @@ -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<? extends IConfig> parent() {return QWEConfig.class;}
public Class<? extends IConfig> parent() { return QWEConfig.class; }

@Override
public JsonObject toJson() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cloud/playio/qwe/dto/PlainType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cloud.playio.qwe.dto;

/**
* Defines {@link EnumType} with depends only {@code type} property
* Defines {@link EnumType} with depends on only {@code type} property
*/
public interface PlainType extends EnumType {}
38 changes: 19 additions & 19 deletions core/src/main/java/cloud/playio/qwe/dto/jpa/Pagination.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
package cloud.playio.qwe.dto.jpa;

import cloud.playio.qwe.dto.JsonData;
import io.github.zero88.utils.Strings;
import io.zero88.jpa.Pageable;

import cloud.playio.qwe.dto.msg.RequestFilter;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import cloud.playio.qwe.dto.JsonData;
import cloud.playio.qwe.dto.msg.RequestFilter;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@JsonIgnoreProperties(value="perPage")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public final class Pagination implements Pageable, JsonData {

@JsonProperty(RequestFilter.PAGE)
private int page;
@JsonProperty(RequestFilter.PER_PAGE)
private int perPage;
@JsonProperty(RequestFilter.PAGE_SIZE)
private int pageSize;

@Override
public int getPageSize() {
return perPage;
}
public int getPage() { return page; }

@Override
public int getPageSize() { return pageSize; }

public static Pagination oneValue() {
return Pagination.builder().perPage(1).page(1).build();
return Pagination.builder().pageSize(1).page(1).build();
}

public static Builder builder() { return new Builder(); }

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class Builder {

private static final int DEFAULT_PER_PAGE = 20;
private static final int DEFAULT_PAGE_SIZE = 20;
private static final int DEFAULT_PAGE = 1;

private int page = DEFAULT_PAGE;
private int perPage = DEFAULT_PER_PAGE;
private int pageSize = DEFAULT_PAGE_SIZE;

public Builder page(int page) {
this.page = Math.max(DEFAULT_PAGE, page);
Expand All @@ -53,19 +53,19 @@ public Builder page(String page) {
return this;
}

public Builder perPage(int perPage) {
this.perPage = perPage > 0 ? Math.min(perPage, DEFAULT_PER_PAGE) : DEFAULT_PER_PAGE;
public Builder pageSize(int perPage) {
this.pageSize = perPage > 0 ? Math.min(perPage, DEFAULT_PAGE_SIZE) : DEFAULT_PAGE_SIZE;
return this;
}

public Builder perPage(String perPage) {
final int pp = Strings.convertToInt(perPage, DEFAULT_PER_PAGE);
this.perPage = pp > 0 ? Math.min(pp, DEFAULT_PER_PAGE) : DEFAULT_PER_PAGE;
public Builder pageSize(String perPage) {
final int pp = Strings.convertToInt(perPage, DEFAULT_PAGE_SIZE);
this.pageSize = pp > 0 ? Math.min(pp, DEFAULT_PAGE_SIZE) : DEFAULT_PAGE_SIZE;
return this;
}

public Pagination build() {
return new Pagination(page, perPage);
return new Pagination(page, pageSize);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class RequestFilter extends JsonObject implements JsonData {
*
* @since 1.0.0
*/
public static final String PER_PAGE = "_per_page";
public static final String PAGE_SIZE = "_page_size";
/**
* For {@code audit}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public interface TextFileOperator extends AsyncFileOperator {
* @param path File path
* @param option File option
* @return a buffer
* @apiNote This methods will auto verify a give path must be existed and be a file and a file size doesn't
* exceeds max size in configuration
* @apiNote This method will auto verify a give path must be existed and be a file and a file size doesn't
* exceed max size in configuration
* @see FileOption
* @see #verifyFile(Path)
*/
Expand Down
20 changes: 11 additions & 9 deletions core/src/test/java/cloud/playio/qwe/QWEConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down
28 changes: 18 additions & 10 deletions core/src/test/java/cloud/playio/qwe/dto/PaginationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,55 @@

public class PaginationTest {

@Test
public void test_build_one_value() {
Pagination pagination = Pagination.oneValue();
Assertions.assertEquals(1, pagination.getPage());
Assertions.assertEquals(1, pagination.getPageSize());
}


@Test
public void test_build_without_value() {
Pagination pagination = Pagination.builder().build();
Assertions.assertEquals(1, pagination.getPage());
Assertions.assertEquals(20, pagination.getPerPage());
Assertions.assertEquals(20, pagination.getPageSize());
}

@Test
public void test_build_with_value() {
Pagination pagination = Pagination.builder().page(5).perPage(15).build();
Pagination pagination = Pagination.builder().page(5).pageSize(15).build();
Assertions.assertEquals(5, pagination.getPage());
Assertions.assertEquals(15, pagination.getPerPage());
Assertions.assertEquals(15, pagination.getPageSize());
}

@Test
public void test_build_with_per_page_greater() {
Pagination pagination = Pagination.builder().perPage(50).build();
Pagination pagination = Pagination.builder().pageSize(50).build();
Assertions.assertEquals(1, pagination.getPage());
Assertions.assertEquals(20, pagination.getPerPage());
Assertions.assertEquals(20, pagination.getPageSize());
}

@Test
public void test_build_with_per_page_equals_zero() {
Pagination pagination = Pagination.builder().perPage(0).build();
Pagination pagination = Pagination.builder().pageSize(0).build();
Assertions.assertEquals(1, pagination.getPage());
Assertions.assertEquals(20, pagination.getPerPage());
Assertions.assertEquals(20, pagination.getPageSize());
}

@Test
public void test_build_with_page_equals_zero() {
Pagination pagination = Pagination.builder().page(0).build();
Assertions.assertEquals(1, pagination.getPage());
Assertions.assertEquals(20, pagination.getPerPage());
Assertions.assertEquals(20, pagination.getPageSize());
}

@Test
public void test_from_json() {
final JsonObject init = new JsonObject().put("_page", 5).put("_per_page", 10);
final JsonObject init = new JsonObject().put("_page", 5).put("_page_size", 10);
final Pagination pagination = init.mapTo(Pagination.class);
Assertions.assertEquals(5, pagination.getPage());
Assertions.assertEquals(10, pagination.getPerPage());
Assertions.assertEquals(10, pagination.getPageSize());
}

}
6 changes: 3 additions & 3 deletions core/src/test/java/cloud/playio/qwe/dto/RequestDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void test_to_json() {
Assertions.assertEquals(1, requestData.pagination().getPage());
Assertions.assertEquals(20, requestData.pagination().getPerPage());
Assertions.assertEquals("{\"headers\":{},\"body\":{\"name\":\"hello\"},\"filter\":{\"x\":\"test\"}," +
"\"pagination\":{\"_page\":1,\"_per_page\":20}}", requestData.toJson().encode());
"\"pagination\":{\"_page\":1,\"_page_size\":20}}", requestData.toJson().encode());
}

@Test
Expand All @@ -44,7 +44,7 @@ public void test_to_json_without_pagination() {

@Test
public void test_from_json_1() {
final JsonObject pagination = new JsonObject().put("_page", 5).put("_per_page", 10);
final JsonObject pagination = new JsonObject().put("_page", 5).put("_page_size", 10);
final JsonObject data = new JsonObject().put("pagination", pagination)
.put("body", new JsonObject())
.put("filter", new JsonObject());
Expand All @@ -58,7 +58,7 @@ public void test_from_json_1() {

@Test
public void test_from_json_2() {
final JsonObject pagination = new JsonObject().put("_page", 5).put("_per_page", 10);
final JsonObject pagination = new JsonObject().put("_page", 5).put("_page_size", 10);
final JsonObject data = new JsonObject().put("pagination", pagination)
.put("body", new JsonObject().put("name", "xyz"))
.put("filter", new JsonObject().put("key", "1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<unresolved>:9090", address.toString());
}

}
7 changes: 3 additions & 4 deletions core/src/test/resources/def-system-cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"crlValues": [],
"enabledCipherSuites": [],
"enabledSecureTransportProtocols": [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
"TLSv1.2",
"TLSv1.3"
],
"idleTimeout": 0,
"idleTimeoutUnit": "SECONDS",
Expand All @@ -51,7 +50,7 @@
"trustAll": true,
"useAlpn": false
},
"eventLoopPoolSize": 32,
"eventLoopPoolSize": 8,
"fileSystemOptions": {
"classPathResolvingEnabled": true,
"fileCacheDir": "/tmp/qwe-cache",
Expand Down
7 changes: 3 additions & 4 deletions core/src/test/resources/full-system-cfg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"__system__": {
"eventLoopPoolSize": 32,
"eventLoopPoolSize": 8,
"workerPoolSize": 20,
"internalBlockingPoolSize": 20,
"blockedThreadCheckInterval": 1000,
Expand Down Expand Up @@ -36,9 +36,8 @@
"crlValues": [],
"useAlpn": false,
"enabledSecureTransportProtocols": [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
"TLSv1.2",
"TLSv1.3"
],
"tcpFastOpen": false,
"tcpCork": false,
Expand Down
4 changes: 3 additions & 1 deletion http/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
dependencies {
api(projects.core)
api(projects.http.shared)

testImplementation(libs.junitVertx)
testImplementation(testFixtures(projects.core))
testImplementation(libs.junitVertx)
testImplementation(libs.log4j2Core)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public JsonObject toJson(@NonNull ObjectMapper mapper) {
return new JsonObject().put("userAgent", userAgent)
.put("http2Enabled", http2Enabled)
.put("options", options.toJson())
.put("httpHandlers", JsonData.tryParse(this.httpHandlers).toJson(mapper))
.put("webSocketHandlers", JsonData.tryParse(this.webSocketHandlers).toJson(mapper));
.put("httpHandlers", JsonData.tryParse(httpHandlers).toJson(mapper))
.put("webSocketHandlers", JsonData.tryParse(webSocketHandlers).toJson(mapper));
}

@JsonCreator
Expand All @@ -70,7 +70,7 @@ static HttpClientOptions defaultOptions() {
return new HttpClientOptions().setIdleTimeout(HTTP_IDLE_TIMEOUT_SECOND)
.setIdleTimeoutUnit(TimeUnit.SECONDS)
.setConnectTimeout(CONNECT_TIMEOUT_SECOND * 1000)
.setTryUseCompression(true)
.setDecompressionSupported(true)
.setWebSocketCompressionLevel(6)
.setWebSocketCompressionAllowClientNoContext(true)
.setWebSocketCompressionRequestServerNoContext(true)
Expand Down
Loading
Loading