This is an automated email from the ASF dual-hosted git repository. miaoliyao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new 4f492a54ed0 Refactor structure of agent e2e fixture package (#32197) 4f492a54ed0 is described below commit 4f492a54ed05c2321ccec02331064eb35e7571e0 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sat Jul 20 16:11:34 2024 +0800 Refactor structure of agent e2e fixture package (#32197) --- .../e2e/agent/common/env/E2ETestEnvironment.java | 2 +- .../dao/JDBCAgentTestDAO.java} | 8 ++-- .../common/{ => fixture}/entity/OrderEntity.java | 2 +- .../request/ProxyRequestExecutor.java | 22 +++++------ .../util/{OkHttpUtils.java => HttpUtils.java} | 44 +++++++--------------- .../test/e2e/agent/metrics/MetricsPluginE2EIT.java | 7 ++-- .../test/e2e/agent/jaeger/asserts/SpanAssert.java | 4 +- .../test/e2e/agent/zipkin/asserts/SpanAssert.java | 4 +- 8 files changed, 38 insertions(+), 55 deletions(-) diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java index 6c1840bf064..a754694939c 100644 --- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java +++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.test.e2e.agent.common.container.ShardingSphereP import org.apache.shardingsphere.test.e2e.agent.common.container.ZipkinContainer; import org.apache.shardingsphere.test.e2e.agent.common.enums.AdapterType; import org.apache.shardingsphere.test.e2e.agent.common.enums.PluginType; -import org.apache.shardingsphere.test.e2e.agent.common.request.ProxyRequestExecutor; +import org.apache.shardingsphere.test.e2e.agent.common.fixture.request.ProxyRequestExecutor; import org.apache.shardingsphere.test.e2e.env.container.atomic.DockerITContainer; import org.apache.shardingsphere.test.e2e.env.container.atomic.governance.GovernanceContainer; import org.apache.shardingsphere.test.e2e.env.container.atomic.governance.GovernanceContainerFactory; diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/JDBCAgentTestUtils.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/dao/JDBCAgentTestDAO.java similarity index 96% rename from test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/JDBCAgentTestUtils.java rename to test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/dao/JDBCAgentTestDAO.java index f67b1a7344e..3ebcf58b860 100644 --- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/JDBCAgentTestUtils.java +++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/dao/JDBCAgentTestDAO.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.shardingsphere.test.e2e.agent.common.util; +package org.apache.shardingsphere.test.e2e.agent.common.fixture.dao; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.test.e2e.agent.common.entity.OrderEntity; +import org.apache.shardingsphere.test.e2e.agent.common.fixture.entity.OrderEntity; import java.sql.Connection; import java.sql.PreparedStatement; @@ -30,10 +30,10 @@ import java.util.Collection; import java.util.LinkedList; /** - * JDBC agent test utils. + * JDBC agent test DAO. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class JDBCAgentTestUtils { +public final class JDBCAgentTestDAO { /** * Insert order. diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/entity/OrderEntity.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/entity/OrderEntity.java similarity index 93% rename from test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/entity/OrderEntity.java rename to test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/entity/OrderEntity.java index 74a5ec2d4c9..d4109db38db 100644 --- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/entity/OrderEntity.java +++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/entity/OrderEntity.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.test.e2e.agent.common.entity; +package org.apache.shardingsphere.test.e2e.agent.common.fixture.entity; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/request/ProxyRequestExecutor.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/request/ProxyRequestExecutor.java similarity index 76% rename from test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/request/ProxyRequestExecutor.java rename to test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/request/ProxyRequestExecutor.java index 47141a81f95..f192013e99a 100644 --- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/request/ProxyRequestExecutor.java +++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/fixture/request/ProxyRequestExecutor.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.test.e2e.agent.common.request; +package org.apache.shardingsphere.test.e2e.agent.common.fixture.request; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.test.e2e.agent.common.entity.OrderEntity; -import org.apache.shardingsphere.test.e2e.agent.common.util.JDBCAgentTestUtils; +import org.apache.shardingsphere.test.e2e.agent.common.fixture.entity.OrderEntity; +import org.apache.shardingsphere.test.e2e.agent.common.fixture.dao.JDBCAgentTestDAO; import org.testcontainers.shaded.org.awaitility.Awaitility; import java.sql.Connection; import java.time.Duration; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -66,19 +66,19 @@ public final class ProxyRequestExecutor implements Runnable { } private void request() { - Collection<Long> results = new ArrayList<>(10); + Collection<Long> results = new LinkedList<>(); for (int i = 1; i <= 10; i++) { OrderEntity orderEntity = new OrderEntity(i, i, "INSERT_TEST"); - JDBCAgentTestUtils.insertOrder(orderEntity, connection); + JDBCAgentTestDAO.insertOrder(orderEntity, connection); results.add(orderEntity.getOrderId()); } OrderEntity orderEntity = new OrderEntity(1000L, 1000, "ROLL_BACK"); - JDBCAgentTestUtils.insertOrderRollback(orderEntity, connection); - JDBCAgentTestUtils.updateOrderStatus(orderEntity, connection); - JDBCAgentTestUtils.selectAllOrders(connection); + JDBCAgentTestDAO.insertOrderRollback(orderEntity, connection); + JDBCAgentTestDAO.updateOrderStatus(orderEntity, connection); + JDBCAgentTestDAO.selectAllOrders(connection); for (Long each : results) { - JDBCAgentTestUtils.deleteOrderByOrderId(each, connection); + JDBCAgentTestDAO.deleteOrderByOrderId(each, connection); } - JDBCAgentTestUtils.createExecuteError(connection); + JDBCAgentTestDAO.createExecuteError(connection); } } diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/OkHttpUtils.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/HttpUtils.java similarity index 54% rename from test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/OkHttpUtils.java rename to test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/HttpUtils.java index 293110fb5c6..ae99f6f785b 100644 --- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/OkHttpUtils.java +++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/util/HttpUtils.java @@ -20,8 +20,6 @@ package org.apache.shardingsphere.test.e2e.agent.common.util; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.apache.shardingsphere.infra.util.json.JsonConfiguration; -import org.apache.shardingsphere.infra.util.json.JsonUtils; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -29,20 +27,16 @@ import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertNotNull; /** - * Ok http utils. + * HTTP utils. */ -public final class OkHttpUtils { +public final class HttpUtils { - private static final OkHttpUtils OK_HTTP_UTILS = new OkHttpUtils(); + private static final HttpUtils OK_HTTP_UTILS = new HttpUtils(); private final OkHttpClient client; - private OkHttpUtils() { - OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.connectTimeout(10L, TimeUnit.SECONDS); - builder.readTimeout(10L, TimeUnit.SECONDS); - builder.writeTimeout(10L, TimeUnit.SECONDS); - client = builder.build(); + private HttpUtils() { + client = new OkHttpClient.Builder().connectTimeout(10L, TimeUnit.SECONDS).readTimeout(10L, TimeUnit.SECONDS).writeTimeout(10L, TimeUnit.SECONDS).build(); } /** @@ -50,34 +44,22 @@ public final class OkHttpUtils { * * @return instance */ - public static OkHttpUtils getInstance() { + public static HttpUtils getInstance() { return OK_HTTP_UTILS; } /** - * Get response json and transform to class bean. + * Get response. * - * @param <T> type parameter - * @param url url - * @param clazz clazz - * @return type parameter class bean - * @throws IOException IO exception - */ - public <T extends JsonConfiguration> T get(final String url, final Class<T> clazz) throws IOException { - return JsonUtils.fromJsonString(get(url), clazz); - } - - /** - * Get response json. - * - * @param url url - * @return response json + * @param url URL + * @return response * @throws IOException IO exception */ public String get(final String url) throws IOException { Request request = new Request.Builder().url(url).build(); - Response response = client.newCall(request).execute(); - assertNotNull(response.body()); - return response.body().string(); + try (Response response = client.newCall(request).execute()) { + assertNotNull(response.body()); + return response.body().string(); + } } } diff --git a/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java b/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java index 573aac498a7..30fa26f38f2 100644 --- a/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java +++ b/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java @@ -18,10 +18,11 @@ package org.apache.shardingsphere.test.e2e.agent.metrics; import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.infra.util.json.JsonUtils; import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension; import org.apache.shardingsphere.test.e2e.agent.common.cases.AgentE2ETestCasesLoader; import org.apache.shardingsphere.test.e2e.agent.common.env.E2ETestEnvironment; -import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils; +import org.apache.shardingsphere.test.e2e.agent.common.util.HttpUtils; import org.apache.shardingsphere.test.e2e.agent.metrics.asserts.MetricMetadataAssert; import org.apache.shardingsphere.test.e2e.agent.metrics.asserts.MetricQueryAssert; import org.apache.shardingsphere.test.e2e.agent.metrics.cases.MetricE2ETestCases; @@ -61,7 +62,7 @@ class MetricsPluginE2EIT { : metricCase.getMetricName(); try { String metaDataURLWithParam = String.join("", metaDataURL, "?metric=", URLEncoder.encode(metricName, "UTF-8")); - MetricMetadataAssert.assertIs(OkHttpUtils.getInstance().get(metaDataURLWithParam, MetricsMetaDataResult.class), metricCase); + MetricMetadataAssert.assertIs(JsonUtils.fromJsonString(HttpUtils.getInstance().get(metaDataURLWithParam), MetricsMetaDataResult.class), metricCase); } catch (final IOException ex) { log.info("Access prometheus HTTP RESTFul API error: ", ex); } @@ -71,7 +72,7 @@ class MetricsPluginE2EIT { for (MetricQueryAssertion each : metricCase.getQueryAssertions()) { try { String queryURLWithParam = String.join("", queryURL, "?query=", URLEncoder.encode(each.getQuery(), "UTF-8")); - MetricQueryAssert.assertIs(OkHttpUtils.getInstance().get(queryURLWithParam, MetricsQueryResult.class), each); + MetricQueryAssert.assertIs(JsonUtils.fromJsonString(HttpUtils.getInstance().get(queryURLWithParam), MetricsQueryResult.class), each); } catch (final IOException ex) { log.info("Access prometheus HTTP RESTFul API error: ", ex); } diff --git a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java index 71bbf7488f1..b8b6a39e563 100644 --- a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java +++ b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java @@ -20,7 +20,7 @@ package org.apache.shardingsphere.test.e2e.agent.jaeger.asserts; import com.google.common.collect.ImmutableMap; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.util.json.JsonUtils; -import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils; +import org.apache.shardingsphere.test.e2e.agent.common.util.HttpUtils; import org.apache.shardingsphere.test.e2e.agent.jaeger.cases.SpanTestCase; import org.apache.shardingsphere.test.e2e.agent.jaeger.cases.TagAssertion; import org.apache.shardingsphere.test.e2e.agent.jaeger.result.SpanResult; @@ -82,7 +82,7 @@ public final class SpanAssert { @SneakyThrows(IOException.class) private static Collection<TraceResult> getTraceResults(final String url) { - TraceResults result = JsonUtils.fromJsonString(OkHttpUtils.getInstance().get(url), TraceResults.class); + TraceResults result = JsonUtils.fromJsonString(HttpUtils.getInstance().get(url), TraceResults.class); assertNotNull(result); return result.getData(); } diff --git a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java index cdade204e63..cfd75eddc69 100644 --- a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java +++ b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java @@ -20,7 +20,7 @@ package org.apache.shardingsphere.test.e2e.agent.zipkin.asserts; import com.fasterxml.jackson.core.type.TypeReference; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.util.json.JsonUtils; -import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils; +import org.apache.shardingsphere.test.e2e.agent.common.util.HttpUtils; import org.apache.shardingsphere.test.e2e.agent.zipkin.cases.SpanTestCase; import org.apache.shardingsphere.test.e2e.agent.zipkin.cases.TagAssertion; import org.apache.shardingsphere.test.e2e.agent.zipkin.result.SpanResult; @@ -77,7 +77,7 @@ public final class SpanAssert { @SneakyThrows(IOException.class) private static Collection<SpanResult> getSpanResults(final SpanTestCase expected, final String url) { - List<List<SpanResult>> result = JsonUtils.fromJsonString(OkHttpUtils.getInstance().get(url), new TypeReference<List<List<SpanResult>>>() { + List<List<SpanResult>> result = JsonUtils.fromJsonString(HttpUtils.getInstance().get(url), new TypeReference<List<List<SpanResult>>>() { }); assertNotNull(result); return result.stream().findFirst().orElse(Collections.emptyList()).stream()