You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/03/22 06:30:07 UTC
[shardingsphere] branch master updated: add logging e2e test for JDBC that use agent (#24721)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 8ef98b32264 add logging e2e test for JDBC that use agent (#24721)
8ef98b32264 is described below
commit 8ef98b32264bdbc7befed1da09467fe62c488486
Author: jiangML <10...@qq.com>
AuthorDate: Wed Mar 22 14:29:58 2023 +0800
add logging e2e test for JDBC that use agent (#24721)
* add jdbc project for agent jdbc test
* add jdbc project for agent test
* update file plugin e2e test
* update agent file plugin e2e test
* update code
* update e2e-agent.yml
* optimize code
* update code
* optimize code
---
.github/workflows/e2e-agent.yml | 8 +-
test/e2e/agent/jdbc-project/pom.xml | 116 ++++++++++++++++
.../agent/jdbc/project/JdbcProjectApplication.java | 54 ++++++++
.../controller/AbstractRestController.java} | 27 ++--
.../jdbc/project/controller/OrderController.java | 118 ++++++++++++++++
.../agent/jdbc/project/entity/OrderEntity.java} | 33 ++---
.../agent/jdbc/project/enums/StatementType.java} | 23 +---
.../e2e/agent/jdbc/project/mapper/OrderMapper.java | 97 ++++++++++++++
.../agent/jdbc/project/service/OrderService.java | 71 ++++++++++
.../project/service/impl/OrderServiceImpl.java | 101 ++++++++++++++
.../e2e/agent/jdbc/project/vo/ResponseVo.java} | 29 ++--
.../jdbc/project/vo/response/HttpResult.java} | 36 +++--
.../jdbc/project/vo/response/ResultCode.java} | 29 ++--
.../resources/META-INF/mappers/OrderMapper.xml | 73 ++++++++++
.../src/main/resources/application.yml} | 18 ++-
.../jdbc-project/src/main/resources/config.yaml | 54 ++++++++
.../jdbc-project/src/main/resources/logback.xml | 31 +++++
.../e2e/agent/common/AgentTestActionExtension.java | 45 ++++++-
.../e2e/agent/common/env/E2ETestEnvironment.java | 52 ++++++-
.../test/e2e/agent/common/util/OkHttpUtils.java | 16 ++-
test/e2e/agent/plugins/logging/file/pom.xml | 149 ++++++++++++++++++++-
.../test/e2e/agent/file/FilePluginE2EIT.java | 26 +++-
.../test/e2e/agent/file/asserts/ContentAssert.java | 7 +-
.../test/e2e/agent/file/loader/LogLoader.java | 19 +--
.../test/resources/docker/jdbc}/Dockerfile | 13 +-
.../jdbc/conf/application.yml} | 13 +-
.../conf/config-db.yaml => jdbc/conf/config.yaml} | 18 +--
.../src/test/resources/docker/jdbc/conf/start.sh | 54 ++++++++
.../resources/docker/{ => jdbc}/docker-compose.yml | 22 ++-
.../test/resources/docker/proxy}/Dockerfile | 8 +-
.../resources/docker/proxy/conf/config-db.yaml | 4 +-
.../docker/{ => proxy}/docker-compose.yml | 12 +-
.../src/test/resources/env/engine-env.properties | 8 ++
test/e2e/agent/plugins/metrics/prometheus/pom.xml | 2 +-
test/e2e/agent/plugins/tracing/jaeger/pom.xml | 2 +-
test/e2e/agent/plugins/tracing/zipkin/pom.xml | 2 +-
test/e2e/agent/pom.xml | 4 +-
37 files changed, 1199 insertions(+), 195 deletions(-)
diff --git a/.github/workflows/e2e-agent.yml b/.github/workflows/e2e-agent.yml
index 04363dce838..6d10d0e237c 100644
--- a/.github/workflows/e2e-agent.yml
+++ b/.github/workflows/e2e-agent.yml
@@ -123,7 +123,9 @@ jobs:
name: Agent logging with MySQL
runs-on: ubuntu-latest
strategy:
+ max-parallel: 1
matrix:
+ adapter: [ proxy, jdbc ]
plugin: [ file ]
steps:
- uses: actions/checkout@v3
@@ -140,11 +142,11 @@ jobs:
- name: Build Project
run: |
./mvnw -B clean install -DskipITs -DskipTests -Prelease
- - name: Setup JDK 8 for Test
+ - name: Setup JDK 11 for Test
uses: actions/setup-java@v3
with:
distribution: 'temurin'
- java-version: 8
+ java-version: '11'
- name: Run E2E Test
run: |
- ./mvnw -B clean install -f test/e2e/agent/plugins/logging/${{ matrix.plugin }}/pom.xml -Dspotless.apply.skip=true -Dit.env.type=${{ matrix.plugin }} -Pit.env.${{ matrix.plugin }}
+ ./mvnw -B clean install -f test/e2e/agent/plugins/logging/${{ matrix.plugin }}/pom.xml -Dspotless.apply.skip=true -Dit.env.adapter=${{ matrix.adapter }} -Dit.env.type=${{ matrix.plugin }} -Pit.env.${{ matrix.adapter }}.${{ matrix.plugin }}
diff --git a/test/e2e/agent/jdbc-project/pom.xml b/test/e2e/agent/jdbc-project/pom.xml
new file mode 100644
index 00000000000..6f5cb37933c
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/pom.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-e2e-agent</artifactId>
+ <version>5.3.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-test-e2e-agent-jdbc-project</artifactId>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <spring-boot.version>2.7.9</spring-boot.version>
+ <mybatis-spring-boot-starter.version>2.3.0</mybatis-spring-boot-starter.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis.spring.boot</groupId>
+ <artifactId>mybatis-spring-boot-starter</artifactId>
+ <version>${mybatis-spring-boot-starter.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-core</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <finalName>${docker.jdbc.distribution.name}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <id>repackage</id>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/JdbcProjectApplication.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/JdbcProjectApplication.java
new file mode 100644
index 00000000000..e0eded93d49
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/JdbcProjectApplication.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.sql.DataSource;
+
+/**
+ * Jdbc project application.
+ */
+@SpringBootApplication
+@MapperScan("org.apache.shardingsphere.test.e2e.agent.jdbc.project.mapper")
+@EnableTransactionManagement
+public class JdbcProjectApplication {
+
+ /**
+ * Create platform transaction manager bean.
+ *
+ * @param dataSource data source
+ * @return platform transaction manager
+ */
+ @Bean
+ public PlatformTransactionManager txManager(final DataSource dataSource) {
+ return new DataSourceTransactionManager(dataSource);
+ }
+
+ // CHECKSTYLE:OFF
+ public static void main(final String[] args) {
+ SpringApplication.run(JdbcProjectApplication.class, args);
+ }
+ // CHECKSTYLE:ON
+}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/AbstractRestController.java
similarity index 51%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/AbstractRestController.java
index 208cdda8a68..988c0c1333f 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/AbstractRestController.java
@@ -15,22 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.controller;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo.response.HttpResult;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo.response.ResultCode;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
+/**
+ * Abstract rest controller.
+ */
+public abstract class AbstractRestController {
+
+ protected HttpResult<Void> success() {
+ return new HttpResult<Void>().toBuilder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).build();
+ }
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
+ protected <T> HttpResult<T> success(final T data) {
+ return new HttpResult<T>().toBuilder().code(ResultCode.SUCCESS.getCode()).message(ResultCode.SUCCESS.getMessage()).data(data).build();
}
}
diff --git a/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/OrderController.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/OrderController.java
new file mode 100644
index 00000000000..988251b1a40
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/controller/OrderController.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.controller;
+
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.enums.StatementType;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.service.OrderService;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo.response.HttpResult;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+
+/**
+ * Order controller.
+ */
+@RestController
+@RequestMapping("/order")
+public class OrderController extends AbstractRestController {
+
+ @Resource
+ private OrderService orderService;
+
+ /**
+ * Create table.
+ *
+ * @return http result
+ */
+ @GetMapping("/createTable")
+ public HttpResult<Void> createTable() {
+ orderService.createTable();
+ return success();
+ }
+
+ /**
+ * Drop table.
+ *
+ * @return http result
+ */
+ @GetMapping("/dropTable")
+ public HttpResult<Void> dropTable() {
+ orderService.dropTable();
+ return success();
+ }
+
+ /**
+ * Insert order.
+ *
+ * @return http result
+ */
+ @GetMapping("/insert")
+ public HttpResult<Void> insert() {
+ long index = 0;
+ while (index++ < 100) {
+ OrderEntity order = new OrderEntity(index, index, "OK");
+ orderService.insert(order, 0 == (index & 1) ? StatementType.STATEMENT : StatementType.PREPARED);
+ }
+ return success();
+ }
+
+ /**
+ * Update.
+ *
+ * @return http result
+ */
+ @GetMapping("/update")
+ public HttpResult<Void> update() {
+ Collection<OrderEntity> orders = orderService.selectAll(StatementType.STATEMENT);
+ int index = 0;
+ for (OrderEntity each : orders) {
+ each.setStatus("Fail");
+ orderService.update(each, 0 == (index++ & 1) ? StatementType.STATEMENT : StatementType.PREPARED);
+ }
+ return success();
+ }
+
+ /**
+ * Delete order.
+ *
+ * @return http result
+ */
+ @GetMapping("/delete")
+ public HttpResult<Void> delete() {
+ Collection<OrderEntity> orders = orderService.selectAll(StatementType.STATEMENT);
+ int index = 0;
+ for (OrderEntity each : orders) {
+ orderService.delete(each.getOrderId(), 0 == (index++ & 1) ? StatementType.STATEMENT : StatementType.PREPARED);
+ }
+ return success();
+ }
+
+ /**
+ * Select all order.
+ *
+ * @return http result
+ */
+ @GetMapping("selectAll")
+ public HttpResult<Collection<OrderEntity>> selectAll() {
+ return success(orderService.selectAll(StatementType.PREPARED));
+ }
+}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/entity/OrderEntity.java
similarity index 50%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/entity/OrderEntity.java
index 208cdda8a68..0b1ba681055 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/entity/OrderEntity.java
@@ -15,22 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
+/**
+ * Order entity.
+ */
+@AllArgsConstructor
+@Getter
+@Setter
+@ToString
+public class OrderEntity {
+
+ private final Long orderId;
+
+ private Long userId;
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
- }
+ private String status;
}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/enums/StatementType.java
similarity index 50%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/enums/StatementType.java
index 208cdda8a68..e09ad243378 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/enums/StatementType.java
@@ -15,22 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.enums;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
-
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
- }
+/**
+ * Statement type.
+ */
+public enum StatementType {
+ STATEMENT, PREPARED
}
diff --git a/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/mapper/OrderMapper.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/mapper/OrderMapper.java
new file mode 100644
index 00000000000..56d21562ef0
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/mapper/OrderMapper.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity;
+
+import java.util.Collection;
+
+/**
+ * Order mapper.
+ */
+@Mapper
+public interface OrderMapper {
+
+ /**
+ * Create table.
+ */
+ void createTable();
+
+ /**
+ * Drop table.
+ */
+ void dropTable();
+
+ /**
+ * Insert with statement.
+ *
+ * @param order order
+ */
+ void insertWithStatement(OrderEntity order);
+
+ /**
+ * Insert with prepared statement.
+ *
+ * @param order order
+ */
+ void insertWithPreparedStatement(OrderEntity order);
+
+ /**
+ * Delete with statement.
+ *
+ * @param orderId order id
+ */
+ void deleteWithStatement(@Param("orderId") Long orderId);
+
+ /**
+ * Delete with prepared statement.
+ *
+ * @param orderId order id
+ */
+ void deleteWithPreparedStatement(@Param("orderId") Long orderId);
+
+ /**
+ * Select all with statement.
+ *
+ * @return orders
+ */
+ Collection<OrderEntity> selectAllWithStatement();
+
+ /**
+ * Select all with prepared statement.
+ *
+ * @return orders
+ */
+ Collection<OrderEntity> selectAllWithPreparedStatement();
+
+ /**
+ * Update with statement.
+ *
+ * @param order order
+ */
+ void updateWithStatement(OrderEntity order);
+
+ /**
+ * Update with prepared statement.
+ *
+ * @param order order
+ */
+ void updateWithPreparedStatement(OrderEntity order);
+}
diff --git a/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/OrderService.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/OrderService.java
new file mode 100644
index 00000000000..ee9a4b7ab36
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/OrderService.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.service;
+
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.enums.StatementType;
+
+import java.util.Collection;
+
+/**
+ * Order service.
+ */
+public interface OrderService {
+
+ /**
+ * Create table.
+ */
+ void createTable();
+
+ /**
+ * Drop table.
+ */
+ void dropTable();
+
+ /**
+ * Insert order.
+ *
+ * @param order order
+ * @param statementType statement type
+ */
+ void insert(OrderEntity order, StatementType statementType);
+
+ /**
+ * Delete.
+ *
+ * @param orderId order id
+ * @param statementType statement type
+ */
+ void delete(Long orderId, StatementType statementType);
+
+ /**
+ * Update.
+ *
+ * @param order order
+ * @param statementType statement type
+ */
+ void update(OrderEntity order, StatementType statementType);
+
+ /**
+ * Select all.
+ *
+ * @param statementType statement type
+ * @return orders
+ */
+ Collection<OrderEntity> selectAll(StatementType statementType);
+}
diff --git a/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/impl/OrderServiceImpl.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/impl/OrderServiceImpl.java
new file mode 100644
index 00000000000..e6061cddbb0
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/service/impl/OrderServiceImpl.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.service.impl;
+
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.enums.StatementType;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.mapper.OrderMapper;
+import org.apache.shardingsphere.test.e2e.agent.jdbc.project.service.OrderService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Collection;
+
+/**
+ * Order service impl.
+ */
+@Service
+public class OrderServiceImpl implements OrderService {
+
+ @Resource
+ private OrderMapper orderMapper;
+
+ @Override
+ public void createTable() {
+ orderMapper.createTable();
+ }
+
+ @Override
+ public void dropTable() {
+ orderMapper.dropTable();
+ }
+
+ @Override
+ public void insert(final OrderEntity order, final StatementType statementType) {
+ switch (statementType) {
+ case STATEMENT:
+ orderMapper.insertWithStatement(order);
+ break;
+ case PREPARED:
+ orderMapper.insertWithPreparedStatement(order);
+ break;
+ default:
+ throw new UnsupportedOperationException("Unsupported operation");
+ }
+ }
+
+ @Override
+ public void delete(final Long id, final StatementType statementType) {
+ switch (statementType) {
+ case STATEMENT:
+ orderMapper.deleteWithStatement(id);
+ break;
+ case PREPARED:
+ orderMapper.deleteWithPreparedStatement(id);
+ break;
+ default:
+ throw new UnsupportedOperationException("Unsupported operation");
+ }
+ }
+
+ @Override
+ public void update(final OrderEntity order, final StatementType statementType) {
+ switch (statementType) {
+ case STATEMENT:
+ orderMapper.updateWithStatement(order);
+ break;
+ case PREPARED:
+ orderMapper.updateWithPreparedStatement(order);
+ break;
+ default:
+ throw new UnsupportedOperationException("Unsupported operation");
+ }
+ }
+
+ @Override
+ public Collection<OrderEntity> selectAll(final StatementType statementType) {
+ switch (statementType) {
+ case STATEMENT:
+ return orderMapper.selectAllWithStatement();
+ case PREPARED:
+ return orderMapper.selectAllWithPreparedStatement();
+ default:
+ throw new UnsupportedOperationException("Unsupported operation");
+ }
+ }
+}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/ResponseVo.java
similarity index 50%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/ResponseVo.java
index 208cdda8a68..95a075050a3 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/ResponseVo.java
@@ -15,22 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import lombok.Getter;
+import lombok.Setter;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
+/**
+ * Response vo.
+ */
+@Getter
+@Setter
+public class ResponseVo<T> {
+
+ private String code;
+
+ private String message;
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
- }
+ private T data;
}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/HttpResult.java
similarity index 51%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/HttpResult.java
index 208cdda8a68..7bbb0557f8c 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/HttpResult.java
@@ -15,22 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo.response;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.Serializable;
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
+/**
+ * Http result.
+ */
+@NoArgsConstructor
+@Getter
+public class HttpResult<T> implements Serializable {
+
+ private int code;
+
+ private String message;
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
+ private T data;
+
+ @Builder(toBuilder = true)
+ public HttpResult(final int code, final String message, final T data) {
+ this.code = code;
+ this.message = message;
+ this.data = data;
}
+
}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/ResultCode.java
similarity index 51%
copy from test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
copy to test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/ResultCode.java
index 208cdda8a68..e1ea191b2ae 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/jdbc-project/src/main/java/org/apache/shardingsphere/test/e2e/agent/jdbc/project/vo/response/ResultCode.java
@@ -15,22 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.file;
+package org.apache.shardingsphere.test.e2e.agent.jdbc.project.vo.response;
-import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import lombok.Getter;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@ExtendWith(AgentTestActionExtension.class)
-public final class FilePluginE2EIT {
+/**
+ * Result code.
+ */
+@Getter
+public enum ResultCode {
+
+ SUCCESS(200, "SUCCESS"), FAIL(400, "FAIL");
+ private final int code;
+
+ private final String message;
- @Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
+ ResultCode(final int code, final String message) {
+ this.code = code;
+ this.message = message;
}
}
diff --git a/test/e2e/agent/jdbc-project/src/main/resources/META-INF/mappers/OrderMapper.xml b/test/e2e/agent/jdbc-project/src/main/resources/META-INF/mappers/OrderMapper.xml
new file mode 100644
index 00000000000..74d200ace3a
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/resources/META-INF/mappers/OrderMapper.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.shardingsphere.test.e2e.agent.jdbc.project.mapper.OrderMapper">
+
+ <resultMap id="BaseResultMap" type="org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity">
+ <id column="order_id" jdbcType="BIGINT" property="orderId" />
+ <result column="user_id" jdbcType="BIGINT" property="userId" />
+ <result column="status" property="status" />
+ </resultMap>
+
+ <update id="createTable">
+ CREATE TABLE IF NOT EXISTS t_order (
+ order_id BIGINT NOT NULL,
+ user_id BIGINT DEFAULT NULL,
+ status VARCHAR(32) DEFAULT NULL,
+ PRIMARY KEY (order_id)
+ );
+ </update>
+
+ <update id="dropTable">
+ DROP TABLE IF EXISTS t_order;
+ </update>
+
+ <insert id="insertWithStatement" parameterType="org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity" statementType="STATEMENT">
+ insert into t_order(order_id, user_id, status) value (${orderId}, ${userId}, '${status}')
+ </insert>
+
+ <insert id="insertWithPreparedStatement" parameterType="org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity" statementType="PREPARED">
+ insert into t_order(order_id, user_id, status) value (#{orderId}, #{userId}, #{status})
+ </insert>
+
+ <delete id="deleteWithStatement" parameterType="java.lang.Long" statementType="STATEMENT">
+ delete from t_order where order_id=${orderId}
+ </delete>
+
+ <delete id="deleteWithPreparedStatement" parameterType="java.lang.Long" statementType="PREPARED">
+ delete from t_order where order_id=#{orderId}
+ </delete>
+
+ <select id="selectAllWithStatement" resultMap="BaseResultMap" statementType="STATEMENT">
+ select * from t_order
+ </select>
+
+ <select id="selectAllWithPreparedStatement" resultMap="BaseResultMap" statementType="PREPARED">
+ select * from t_order
+ </select>
+
+ <update id="updateWithStatement" parameterType="org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity" statementType="STATEMENT">
+ update t_order set status='${status}' where order_id=${orderId}
+ </update>
+
+ <update id="updateWithPreparedStatement" parameterType="org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity.OrderEntity" statementType="PREPARED">
+ update t_order set status=#{status} where order_id=#{orderId}
+ </update>
+
+</mapper>
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties b/test/e2e/agent/jdbc-project/src/main/resources/application.yml
similarity index 68%
copy from test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
copy to test/e2e/agent/jdbc-project/src/main/resources/application.yml
index 10fcecc9529..00c04692381 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
+++ b/test/e2e/agent/jdbc-project/src/main/resources/application.yml
@@ -15,11 +15,17 @@
# limitations under the License.
#
-it.env.type=${it.env}
-it.env.value=file
+server:
+ port: 80
-proxy.url=jdbc:mysql://127.0.0.1:43072/agent-file-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
-proxy.username=root
-proxy.password=root
+mybatis:
+ mapper-locations: classpath*:META-INF/mappers/*Mapper.xml
+ type-aliases-package: org.apache.shardingsphere.test.e2e.agent.jdbc.project.entity
-collect.data.wait.milliseconds=2000
+logging:
+ config: classpath:logback.xml
+
+spring:
+ datasource:
+ driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
+ url: jdbc:shardingsphere:classpath:config.yaml
diff --git a/test/e2e/agent/jdbc-project/src/main/resources/config.yaml b/test/e2e/agent/jdbc-project/src/main/resources/config.yaml
new file mode 100644
index 00000000000..d4827feb1ca
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/resources/config.yaml
@@ -0,0 +1,54 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+databaseName: sharding_db
+
+dataSources:
+ ds_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/jdbc_test_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ username: root
+ password: 123456
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/jdbc_test_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ username: root
+ password: 123456
+
+rules:
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order
+ databaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database-inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ shardingAlgorithms:
+ database-inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_$->{user_id % 2}
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
diff --git a/test/e2e/agent/jdbc-project/src/main/resources/logback.xml b/test/e2e/agent/jdbc-project/src/main/resources/logback.xml
new file mode 100644
index 00000000000..a5b428b38dc
--- /dev/null
+++ b/test/e2e/agent/jdbc-project/src/main/resources/logback.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder charset="UTF-8">
+ <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root>
+ <level value="info" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/AgentTestActionExtension.java b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/AgentTestActionExtension.java
index b89f6f34ee4..4bd822708a5 100644
--- a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/AgentTestActionExtension.java
+++ b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/AgentTestActionExtension.java
@@ -22,12 +22,15 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.test.e2e.agent.common.entity.OrderEntity;
import org.apache.shardingsphere.test.e2e.agent.common.env.E2ETestEnvironment;
import org.apache.shardingsphere.test.e2e.agent.common.util.JDBCAgentTestUtils;
+import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import javax.sql.DataSource;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@@ -44,6 +47,24 @@ public final class AgentTestActionExtension implements BeforeEachCallback {
@Override
public void beforeEach(final ExtensionContext context) {
checkEnvironment();
+ if (E2ETestEnvironment.getInstance().isAdaptedProxy()) {
+ requestProxy();
+ } else {
+ requestJdbcProject();
+ }
+ sleep();
+ }
+
+ private void checkEnvironment() {
+ assumeTrue(E2ETestEnvironment.getInstance().isEnvironmentPrepared());
+ assumeFalse(E2ETestEnvironment.getInstance().isInitializationFailed());
+ E2ETestEnvironment.getInstance().prepareEnvironment();
+ if (E2ETestEnvironment.getInstance().isAdaptedProxy()) {
+ assertNotNull(E2ETestEnvironment.getInstance().getDataSource());
+ }
+ }
+
+ private void requestProxy() {
DataSource dataSource = E2ETestEnvironment.getInstance().getDataSource();
List<Long> results = new ArrayList<>(10);
for (int i = 1; i <= 10; i++) {
@@ -59,22 +80,32 @@ public final class AgentTestActionExtension implements BeforeEachCallback {
JDBCAgentTestUtils.deleteOrderByOrderId(each, dataSource);
}
JDBCAgentTestUtils.createExecuteError(dataSource);
- sleep();
}
- private void checkEnvironment() {
- assumeTrue(E2ETestEnvironment.getInstance().isEnvironmentPrepared());
- assumeFalse(E2ETestEnvironment.getInstance().isInitializationFailed());
- E2ETestEnvironment.getInstance().createDataSource();
- assertNotNull(E2ETestEnvironment.getInstance().getDataSource());
+ @SneakyThrows(IOException.class)
+ private void requestJdbcProject() {
+ String baseUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.base.url");
+ String createTableUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.create.table");
+ String dropTableUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.drop.table");
+ String insertUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.insert");
+ String updateUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.update");
+ String selectAllUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.select.all");
+ String deleteUrl = E2ETestEnvironment.getInstance().getProps().getProperty("jdbc.path.delete");
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, dropTableUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, createTableUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, insertUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, updateUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, selectAllUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, deleteUrl));
+ OkHttpUtils.getInstance().get(String.join("", baseUrl, dropTableUrl));
}
@SneakyThrows(InterruptedException.class)
private void sleep() {
if (!hasSleep) {
log.info("Waiting to collect data ...");
- Thread.sleep(getSleepMilliseconds());
hasSleep = true;
+ TimeUnit.MILLISECONDS.sleep(getSleepMilliseconds());
}
}
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 6579dc44eb2..33d0c75859f 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
@@ -21,10 +21,13 @@ import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import okhttp3.Response;
+import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;
import javax.sql.DataSource;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -46,9 +49,12 @@ public final class E2ETestEnvironment {
private boolean initializationFailed;
+ private boolean isAdaptedProxy;
+
private E2ETestEnvironment() {
props = EnvironmentProperties.loadProperties("env/engine-env.properties");
isEnvironmentPrepared = props.getProperty("it.env.value").equals(props.getProperty("it.env.type"));
+ isAdaptedProxy = "proxy".equalsIgnoreCase(props.getProperty("it.env.adapter", "proxy"));
}
/**
@@ -61,11 +67,21 @@ public final class E2ETestEnvironment {
}
/**
- * Create data source.
+ * Prepare environment.
*/
- public void createDataSource() {
+ public void prepareEnvironment() {
+ if (isAdaptedProxy()) {
+ createDataSource();
+ return;
+ }
+ if (isEnvironmentPrepared && !initializationFailed) {
+ initializationFailed = !waitForJdbcEnvironmentReady();
+ }
+ }
+
+ private void createDataSource() {
if (isEnvironmentPrepared && null == dataSource) {
- if (waitForEnvironmentReady(props)) {
+ if (waitForProxyEnvironmentReady(props)) {
dataSource = createHikariCP(props);
} else {
initializationFailed = true;
@@ -73,7 +89,7 @@ public final class E2ETestEnvironment {
}
}
- private boolean waitForEnvironmentReady(final Properties props) {
+ private boolean waitForProxyEnvironmentReady(final Properties props) {
log.info("Proxy with agent environment initializing ...");
try {
Awaitility.await().atMost(2, TimeUnit.MINUTES).pollInterval(5, TimeUnit.SECONDS).until(() -> isProxyReady(props));
@@ -81,6 +97,7 @@ public final class E2ETestEnvironment {
log.info("Proxy with agent environment initialization failed ...");
return false;
}
+ log.info("Proxy with agent environment initialized successfully ...");
return true;
}
@@ -93,10 +110,9 @@ public final class E2ETestEnvironment {
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement()) {
statement.execute("SELECT 1");
- } catch (final SQLException ignore) {
+ } catch (final SQLException ignored) {
return false;
}
- log.info("Proxy with agent environment initialized successfully ...");
return true;
}
@@ -110,4 +126,28 @@ public final class E2ETestEnvironment {
result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
return new HikariDataSource(result);
}
+
+ private boolean waitForJdbcEnvironmentReady() {
+ log.info("Jdbc project with agent environment initializing ...");
+ try {
+ Awaitility.await().atMost(2, TimeUnit.MINUTES).pollInterval(5, TimeUnit.SECONDS).until(() -> isJdbcReady(props));
+ } catch (final ConditionTimeoutException ignored) {
+ log.info("Jdbc project with agent environment initialization failed ...");
+ return false;
+ }
+ log.info("Jdbc project with agent environment initialized successfully ...");
+ return true;
+ }
+
+ private boolean isJdbcReady(final Properties props) {
+ log.info("Try to connect jdbc project ...");
+ String baseUrl = props.getProperty("jdbc.base.url");
+ String selectAllUrl = props.getProperty("jdbc.path.select.all");
+ try {
+ Response response = OkHttpUtils.getInstance().getResponse(String.join("", baseUrl, selectAllUrl));
+ return response.isSuccessful();
+ } catch (final IOException ignored) {
+ }
+ return false;
+ }
}
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/OkHttpUtils.java
index 55dd9bf297f..bd0886f1e97 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/OkHttpUtils.java
@@ -62,7 +62,7 @@ public final class OkHttpUtils {
* @param url url
* @param clazz clazz
* @return type parameter class bean
- * @throws IOException the IOException
+ * @throws IOException IO exception
*/
public <T> T get(final String url, final Class<T> clazz) throws IOException {
return GSON.fromJson(get(url), clazz);
@@ -73,7 +73,7 @@ public final class OkHttpUtils {
*
* @param url url
* @return response json
- * @throws IOException the IOException
+ * @throws IOException IO exception
*/
public String get(final String url) throws IOException {
Request request = new Request.Builder().url(url).build();
@@ -81,4 +81,16 @@ public final class OkHttpUtils {
assertNotNull(response.body());
return response.body().string();
}
+
+ /**
+ * Get response.
+ *
+ * @param url url
+ * @return response
+ * @throws IOException IO exception
+ */
+ public Response getResponse(final String url) throws IOException {
+ Request request = new Request.Builder().url(url).build();
+ return client.newCall(request).execute();
+ }
}
diff --git a/test/e2e/agent/plugins/logging/file/pom.xml b/test/e2e/agent/plugins/logging/file/pom.xml
index 19b40b5bd3c..2d0cdf9aa25 100644
--- a/test/e2e/agent/plugins/logging/file/pom.xml
+++ b/test/e2e/agent/plugins/logging/file/pom.xml
@@ -30,6 +30,11 @@
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<mysql-connector-java.version>8.0.31</mysql-connector-java.version>
+
+ <docker.proxy.context.directory>target/proxy</docker.proxy.context.directory>
+ <docker.proxy.compose.file>${project.basedir}/src/test/resources/docker/proxy/docker-compose.yml</docker.proxy.compose.file>
+ <docker.jdbc.context.directory>target/jdbc</docker.jdbc.context.directory>
+ <docker.jdbc.compose.file>${project.basedir}/src/test/resources/docker/jdbc/docker-compose.yml</docker.jdbc.compose.file>
</properties>
<dependencies>
@@ -71,7 +76,7 @@
<profiles>
<profile>
- <id>it.env.file</id>
+ <id>it.env.proxy.file</id>
<properties>
<it.env>file</it.env>
</properties>
@@ -80,6 +85,24 @@
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
+ <execution>
+ <id>copy-dockerfile</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${docker.proxy.context.directory}</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/test/resources/docker/proxy/</directory>
+ <includes>
+ <include>Dockerfile</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
<execution>
<id>copy-resources</id>
<goals>
@@ -87,10 +110,13 @@
</goals>
<phase>validate</phase>
<configuration>
- <outputDirectory>target/</outputDirectory>
+ <outputDirectory>${docker.proxy.context.directory}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../../../../../../distribution/proxy/target/</directory>
+ <includes>
+ <include>${docker.proxy.distribution.name}.tar.gz</include>
+ </includes>
</resource>
</resources>
</configuration>
@@ -105,8 +131,10 @@
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
- <APP_NAME>${docker.distribution.name}</APP_NAME>
+ <APP_NAME>${docker.proxy.distribution.name}</APP_NAME>
</buildArgs>
+ <contextDirectory>${docker.proxy.context.directory}</contextDirectory>
+ <dockerfile>${docker.proxy.context.directory}/Dockerfile</dockerfile>
</configuration>
<executions>
<execution>
@@ -122,24 +150,131 @@
<artifactId>docker-compose-maven-plugin</artifactId>
<executions>
<execution>
- <id>agent-metrics-up</id>
+ <id>agent-logging-up</id>
+ <goals>
+ <goal>up</goal>
+ </goals>
+ <phase>pre-integration-test</phase>
+ <configuration>
+ <composeFile>${docker.proxy.compose.file}</composeFile>
+ <detachedMode>true</detachedMode>
+ </configuration>
+ </execution>
+ <execution>
+ <id>agent-logging-down</id>
+ <goals>
+ <goal>down</goal>
+ </goals>
+ <phase>post-integration-test</phase>
+ <configuration>
+ <composeFile>${docker.proxy.compose.file}</composeFile>
+ <removeVolumes>true</removeVolumes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>it.env.jdbc.file</id>
+ <properties>
+ <it.env>file</it.env>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dockerfile</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${docker.jdbc.context.directory}</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/test/resources/docker/jdbc</directory>
+ <includes>
+ <include>Dockerfile</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-resources</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${docker.jdbc.context.directory}/shardingsphere-jdbc-app</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/../../../jdbc-project/target/</directory>
+ <includes>
+ <include>${docker.jdbc.distribution.name}.jar</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/test/resources/docker/jdbc/conf</directory>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/../../../../../../distribution/agent/target/apache-shardingsphere-${project.version}-shardingsphere-agent-bin/</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>dockerfile-maven-plugin</artifactId>
+ <configuration>
+ <repository>apache/shardingsphere-jdbc-agent-logging-file-test</repository>
+ <tag>latest</tag>
+ <buildArgs>
+ <APP_NAME>${docker.jdbc.distribution.name}</APP_NAME>
+ </buildArgs>
+ <contextDirectory>${docker.jdbc.context.directory}</contextDirectory>
+ <dockerfile>${docker.jdbc.context.directory}/Dockerfile</dockerfile>
+ </configuration>
+ <executions>
+ <execution>
+ <id>shardingsphere-jdbc-bin</id>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.dkanejs.maven.plugins</groupId>
+ <artifactId>docker-compose-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>agent-logging-up</id>
<goals>
<goal>up</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
- <composeFile>${project.basedir}/src/test/resources/docker/docker-compose.yml</composeFile>
+ <composeFile>${docker.jdbc.compose.file}</composeFile>
<detachedMode>true</detachedMode>
</configuration>
</execution>
<execution>
- <id>agent-metrics-down</id>
+ <id>agent-logging-down</id>
<goals>
<goal>down</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
- <composeFile>${project.basedir}/src/test/resources/docker/docker-compose.yml</composeFile>
+ <composeFile>${docker.jdbc.compose.file}</composeFile>
<removeVolumes>true</removeVolumes>
</configuration>
</execution>
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
index 208cdda8a68..f3c7b061511 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
@@ -18,19 +18,39 @@
package org.apache.shardingsphere.test.e2e.agent.file;
import org.apache.shardingsphere.test.e2e.agent.common.AgentTestActionExtension;
+import org.apache.shardingsphere.test.e2e.agent.common.env.E2ETestEnvironment;
import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import java.io.File;
+import java.util.Collection;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(AgentTestActionExtension.class)
public final class FilePluginE2EIT {
@Test
- public void assertProxyWithAgent() {
- assertTrue(LogLoader.getLogFile().exists(), String.format("The file `%s` does not exist", LogLoader.getLogFilePath()));
- ContentAssert.assertIs("Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
+ public void assertWithAgent() {
+ assertTrue(new File(LogLoader.getLogFilePath(E2ETestEnvironment.getInstance().isAdaptedProxy())).exists(),
+ String.format("The file `%s` does not exist", LogLoader.getLogFilePath(E2ETestEnvironment.getInstance().isAdaptedProxy())));
+ Collection<String> actualLogLines = LogLoader.getLogLines(E2ETestEnvironment.getInstance().isAdaptedProxy());
+ assertFalse(actualLogLines.isEmpty(), "Actual log is empty");
+ if (E2ETestEnvironment.getInstance().isAdaptedProxy()) {
+ assertProxyWithAgent(actualLogLines);
+ } else {
+ assertJdbcWithAgent(actualLogLines);
+ }
+ }
+
+ private void assertProxyWithAgent(final Collection<String> actualLogLines) {
+ ContentAssert.assertIs(actualLogLines, "Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
+ }
+
+ private void assertJdbcWithAgent(final Collection<String> actualLogLines) {
+ ContentAssert.assertIs(actualLogLines, "Build meta data contexts finished, cost\\s(?=[1-9]+\\d*)");
}
}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
index 35a075424e2..10a02bffbc7 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
+++ b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.test.e2e.agent.file.asserts;
-import org.apache.shardingsphere.test.e2e.agent.file.loader.LogLoader;
-
import java.util.Collection;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -34,11 +32,10 @@ public final class ContentAssert {
/**
* Assertion specifies regular log content.
*
+ * @param actualLogLines actual logs
* @param expectedLogRegex expected log regex
*/
- public static void assertIs(final String expectedLogRegex) {
- Collection<String> actualLogLines = LogLoader.getLogLines();
- assertThat("Actual log is empty", actualLogLines.size(), greaterThan(0));
+ public static void assertIs(final Collection<String> actualLogLines, final String expectedLogRegex) {
Pattern pattern = Pattern.compile(expectedLogRegex);
Collection<String> expectedLogs = actualLogLines.stream().filter(each -> pattern.matcher(each).find()).collect(Collectors.toList());
assertThat(String.format("The log for the specified regular `%s` does not exist", expectedLogRegex), expectedLogs.size(), greaterThan(0));
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/loader/LogLoader.java b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/loader/LogLoader.java
index 40a971d340d..fa8082cf05a 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/loader/LogLoader.java
+++ b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/loader/LogLoader.java
@@ -36,12 +36,13 @@ public final class LogLoader {
/**
* Get log lines.
*
+ * @param isAdaptedProxy is adapted proxy
* @return log lines
*/
@SneakyThrows(IOException.class)
- public static Collection<String> getLogLines() {
+ public static Collection<String> getLogLines(final boolean isAdaptedProxy) {
Collection<String> result = new LinkedList<>();
- Collection<String> lines = Files.readAllLines(Paths.get(getLogFilePath()));
+ Collection<String> lines = Files.readAllLines(Paths.get(getLogFilePath(isAdaptedProxy)));
Pattern pattern = Pattern.compile("^\\[");
StringBuilder builder = new StringBuilder();
boolean hasFind = false;
@@ -69,18 +70,10 @@ public final class LogLoader {
/**
* Get log file path.
*
+ * @param isAdaptedProxy is adapted proxy
* @return log file path
*/
- public static String getLogFilePath() {
- return String.join(File.separator, Paths.get("").toAbsolutePath().toString(), "target", "logs", "stdout.log");
- }
-
- /**
- * Get log file.
- *
- * @return log file
- */
- public static File getLogFile() {
- return new File(getLogFilePath());
+ public static String getLogFilePath(final boolean isAdaptedProxy) {
+ return String.join(File.separator, Paths.get("").toAbsolutePath().toString(), String.join(File.separator, "target", isAdaptedProxy ? "proxy" : "jdbc", "logs", "stdout.log"));
}
}
diff --git a/test/e2e/agent/plugins/logging/file/Dockerfile b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/Dockerfile
similarity index 68%
copy from test/e2e/agent/plugins/logging/file/Dockerfile
copy to test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/Dockerfile
index 8019795ff49..d917f2ffd9e 100644
--- a/test/e2e/agent/plugins/logging/file/Dockerfile
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/Dockerfile
@@ -15,14 +15,13 @@
# limitations under the License.
#
-FROM eclipse-temurin:8-jdk
+FROM eclipse-temurin:11-jdk
ARG APP_NAME
-ENV WAIT_VERSION 2.7.2
+ENV WAIT_VERSION=2.7.2 JAR_FILE_NAME=${APP_NAME}.jar
-ADD target/${APP_NAME}.tar.gz /opt
+COPY shardingsphere-jdbc-app /opt/shardingsphere-jdbc-app
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
-RUN chmod +x /wait
-RUN mv /opt/${APP_NAME} /opt/shardingsphere-proxy
-RUN wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar -P /opt/shardingsphere-proxy/lib
-ENTRYPOINT /wait && /opt/shardingsphere-proxy/bin/start.sh -g && tail -f /opt/shardingsphere-proxy/logs/stdout.log
+RUN chmod +x /wait && chmod +x /opt/shardingsphere-jdbc-app/start.sh
+WORKDIR /opt/shardingsphere-jdbc-app
+ENTRYPOINT ./start.sh $JAR_FILE_NAME --agent && tail -f ./logs/stdout.log
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/application.yml
similarity index 75%
copy from test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
copy to test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/application.yml
index 10fcecc9529..389a37be2ac 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/application.yml
@@ -15,11 +15,10 @@
# limitations under the License.
#
-it.env.type=${it.env}
-it.env.value=file
+server:
+ port: 80
-proxy.url=jdbc:mysql://127.0.0.1:43072/agent-file-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
-proxy.username=root
-proxy.password=root
-
-collect.data.wait.milliseconds=2000
+spring:
+ datasource:
+ driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
+ url: jdbc:shardingsphere:absolutepath:/opt/shardingsphere-jdbc-app/config.yaml
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/config.yaml
similarity index 75%
copy from test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml
copy to test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/config.yaml
index b601248abc0..ab564d043c0 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/config.yaml
@@ -19,23 +19,17 @@ databaseName: agent-file-db
dataSources:
ds_0:
- url: jdbc:mysql://mysql.agent.logging.host:3306/agent_file_db_0?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://mysql.agent.jdbc.logging.host:3306/agent_file_db_0?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
username: root
password:
- connectionTimeoutMilliseconds: 30000
- idleTimeoutMilliseconds: 60000
- maxLifetimeMilliseconds: 1800000
- maxPoolSize: 10
- minPoolSize: 2
ds_1:
- url: jdbc:mysql://mysql.agent.logging.host:3306/agent_file_db_1?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://mysql.agent.jdbc.logging.host:3306/agent_file_db_1?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
username: root
password:
- connectionTimeoutMilliseconds: 30000
- idleTimeoutMilliseconds: 60000
- maxLifetimeMilliseconds: 1800000
- maxPoolSize: 10
- minPoolSize: 2
rules:
- !SHARDING
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/start.sh b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/start.sh
new file mode 100644
index 00000000000..46bdf181936
--- /dev/null
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/conf/start.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+DEPLOY_DIR="$(pwd)"
+LOGS_DIR=${DEPLOY_DIR}/logs
+if [ ! -d "${LOGS_DIR}" ]; then
+ mkdir "${LOGS_DIR}"
+fi
+STDOUT_FILE=${LOGS_DIR}/stdout.log
+JAR_FILE=$1
+
+AGENT_FILE=${DEPLOY_DIR}/agent/shardingsphere-agent.jar
+function set_agent_name() {
+ if [ -d "${DEPLOY_DIR}/agent" ]; then
+ AGENT_NAME=$(ls "${DEPLOY_DIR}/agent/shardingsphere-agent"*)
+ if [ -n "${AGENT_NAME}" ]; then
+ AGENT_FILE=${AGENT_NAME}
+ fi
+ fi
+}
+
+AGENT_PARAM="";
+function set_agent_parameter() {
+ if [ -f "$AGENT_FILE" ]; then
+ AGENT_PARAM=" -javaagent:${AGENT_FILE} "
+ fi
+}
+
+for arg in $*
+do
+ if [ "$arg" == "--agent" ] ; then
+ set_agent_name
+ set_agent_parameter
+ break
+ fi
+ let PARAMETER_INDEX+=1
+done
+
+nohup java ${AGENT_PARAM} -jar ${DEPLOY_DIR}/${JAR_FILE} >> ${STDOUT_FILE} 2>&1 &
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/docker-compose.yml
similarity index 69%
copy from test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml
copy to test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/docker-compose.yml
index 9fe1eaa4065..0bf59f4c537 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/jdbc/docker-compose.yml
@@ -20,27 +20,25 @@ version: "2.1"
services:
mysql:
image: "mysql/mysql-server:5.7"
- container_name: agent-logging-mysql
+ container_name: agent-jdbc-logging-mysql
command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
volumes:
- - ../env/mysql:/docker-entrypoint-initdb.d/
+ - ../../env/mysql:/docker-entrypoint-initdb.d/
ports:
- - "43060:3306"
+ - "43061:3306"
environment:
- LANG=C.UTF-8
- shardingsphere-proxy-agent-logging:
- image: apache/shardingsphere-proxy-agent-logging-file-test
- container_name: shardingsphere-proxy-agent-logging-file
+ shardingsphere-jdbc-agent-logging:
+ image: apache/shardingsphere-jdbc-agent-logging-file-test
+ container_name: shardingsphere-jdbc-agent-logging-file
ports:
- - "43072:3307"
- - "43080:3308"
+ - "18080:80"
links:
- - "mysql:mysql.agent.logging.host"
+ - "mysql:mysql.agent.jdbc.logging.host"
volumes:
- - ./proxy/conf:/opt/shardingsphere-proxy/conf
- - ./agent/conf:/opt/shardingsphere-proxy/agent/conf
- - ../../../../target/logs:/opt/shardingsphere-proxy/logs
+ - ../agent/conf:/opt/shardingsphere-jdbc-app/agent/conf
+ - ../../../../../target/jdbc/logs:/opt/shardingsphere-jdbc-app/logs
depends_on:
- mysql
environment:
diff --git a/test/e2e/agent/plugins/logging/file/Dockerfile b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/Dockerfile
similarity index 79%
rename from test/e2e/agent/plugins/logging/file/Dockerfile
rename to test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/Dockerfile
index 8019795ff49..0e34682b6e9 100644
--- a/test/e2e/agent/plugins/logging/file/Dockerfile
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/Dockerfile
@@ -15,14 +15,12 @@
# limitations under the License.
#
-FROM eclipse-temurin:8-jdk
+FROM eclipse-temurin:11-jdk
ARG APP_NAME
ENV WAIT_VERSION 2.7.2
-ADD target/${APP_NAME}.tar.gz /opt
+ADD ${APP_NAME}.tar.gz /opt
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
-RUN chmod +x /wait
-RUN mv /opt/${APP_NAME} /opt/shardingsphere-proxy
-RUN wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar -P /opt/shardingsphere-proxy/lib
+RUN chmod +x /wait && mv /opt/${APP_NAME} /opt/shardingsphere-proxy && wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar -P /opt/shardingsphere-proxy/lib
ENTRYPOINT /wait && /opt/shardingsphere-proxy/bin/start.sh -g && tail -f /opt/shardingsphere-proxy/logs/stdout.log
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml
index b601248abc0..fbcd7a5bcf2 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/conf/config-db.yaml
@@ -19,7 +19,7 @@ databaseName: agent-file-db
dataSources:
ds_0:
- url: jdbc:mysql://mysql.agent.logging.host:3306/agent_file_db_0?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
+ url: jdbc:mysql://mysql.agent.proxy.logging.host:3306/agent_file_db_0?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
username: root
password:
connectionTimeoutMilliseconds: 30000
@@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 10
minPoolSize: 2
ds_1:
- url: jdbc:mysql://mysql.agent.logging.host:3306/agent_file_db_1?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
+ url: jdbc:mysql://mysql.agent.proxy.logging.host:3306/agent_file_db_1?serverTimezone=UTC&useSSL=false&characterEncoding=utf-8
username: root
password:
connectionTimeoutMilliseconds: 30000
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/docker-compose.yml
similarity index 81%
rename from test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml
rename to test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/docker-compose.yml
index 9fe1eaa4065..2f556b36196 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/docker/docker-compose.yml
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/docker/proxy/docker-compose.yml
@@ -20,10 +20,10 @@ version: "2.1"
services:
mysql:
image: "mysql/mysql-server:5.7"
- container_name: agent-logging-mysql
+ container_name: agent-proxy-logging-mysql
command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
volumes:
- - ../env/mysql:/docker-entrypoint-initdb.d/
+ - ../../env/mysql:/docker-entrypoint-initdb.d/
ports:
- "43060:3306"
environment:
@@ -36,11 +36,11 @@ services:
- "43072:3307"
- "43080:3308"
links:
- - "mysql:mysql.agent.logging.host"
+ - "mysql:mysql.agent.proxy.logging.host"
volumes:
- - ./proxy/conf:/opt/shardingsphere-proxy/conf
- - ./agent/conf:/opt/shardingsphere-proxy/agent/conf
- - ../../../../target/logs:/opt/shardingsphere-proxy/logs
+ - ./conf:/opt/shardingsphere-proxy/conf
+ - ../agent/conf:/opt/shardingsphere-proxy/agent/conf
+ - ../../../../../target/proxy/logs:/opt/shardingsphere-proxy/logs
depends_on:
- mysql
environment:
diff --git a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties b/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
index 10fcecc9529..486fe927238 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
+++ b/test/e2e/agent/plugins/logging/file/src/test/resources/env/engine-env.properties
@@ -22,4 +22,12 @@ proxy.url=jdbc:mysql://127.0.0.1:43072/agent-file-db?serverTimezone=UTC&useSSL=f
proxy.username=root
proxy.password=root
+jdbc.base.url=http://127.0.0.1:18080
+jdbc.path.create.table=/order/createTable
+jdbc.path.drop.table=/order/dropTable
+jdbc.path.insert=/order/insert
+jdbc.path.update=/order/update
+jdbc.path.select.all=/order/selectAll
+jdbc.path.delete=/order/delete
+
collect.data.wait.milliseconds=2000
diff --git a/test/e2e/agent/plugins/metrics/prometheus/pom.xml b/test/e2e/agent/plugins/metrics/prometheus/pom.xml
index 16fe33451c4..ffba6fa01a3 100644
--- a/test/e2e/agent/plugins/metrics/prometheus/pom.xml
+++ b/test/e2e/agent/plugins/metrics/prometheus/pom.xml
@@ -106,7 +106,7 @@
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
- <APP_NAME>${docker.distribution.name}</APP_NAME>
+ <APP_NAME>${docker.proxy.distribution.name}</APP_NAME>
</buildArgs>
</configuration>
<executions>
diff --git a/test/e2e/agent/plugins/tracing/jaeger/pom.xml b/test/e2e/agent/plugins/tracing/jaeger/pom.xml
index de1b4c90836..77e662d5e65 100644
--- a/test/e2e/agent/plugins/tracing/jaeger/pom.xml
+++ b/test/e2e/agent/plugins/tracing/jaeger/pom.xml
@@ -105,7 +105,7 @@
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
- <APP_NAME>${docker.distribution.name}</APP_NAME>
+ <APP_NAME>${docker.proxy.distribution.name}</APP_NAME>
</buildArgs>
</configuration>
<executions>
diff --git a/test/e2e/agent/plugins/tracing/zipkin/pom.xml b/test/e2e/agent/plugins/tracing/zipkin/pom.xml
index cc3b6ebf625..d0e72275877 100644
--- a/test/e2e/agent/plugins/tracing/zipkin/pom.xml
+++ b/test/e2e/agent/plugins/tracing/zipkin/pom.xml
@@ -105,7 +105,7 @@
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
- <APP_NAME>${docker.distribution.name}</APP_NAME>
+ <APP_NAME>${docker.proxy.distribution.name}</APP_NAME>
</buildArgs>
</configuration>
<executions>
diff --git a/test/e2e/agent/pom.xml b/test/e2e/agent/pom.xml
index 2bee1753f4e..67bcfb7fe58 100644
--- a/test/e2e/agent/pom.xml
+++ b/test/e2e/agent/pom.xml
@@ -30,11 +30,13 @@
<modules>
<module>plugins</module>
+ <module>jdbc-project</module>
</modules>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
- <docker.distribution.name>apache-shardingsphere-${project.version}-shardingsphere-proxy-bin</docker.distribution.name>
+ <docker.proxy.distribution.name>apache-shardingsphere-${project.version}-shardingsphere-proxy-bin</docker.proxy.distribution.name>
+ <docker.jdbc.distribution.name>shardingsphere-jdbc-agent-test-${project.version}</docker.jdbc.distribution.name>
</properties>
<dependencies>