From 1902ce4af4ebc7025b2efb30d9de2ac79fd5321e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 00:37:47 +0800 Subject: [PATCH 1/8] Refactor : refactor the agent proxy test data --- test/e2e/agent/engine/pom.xml | 1 + .../engine/env/AgentE2ETestEnvironment.java | 6 ----- .../test/resources/docker/proxy/Dockerfile | 7 ++++- .../docker/proxy/entrypoint/entrypoint.sh | 26 +++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh diff --git a/test/e2e/agent/engine/pom.xml b/test/e2e/agent/engine/pom.xml index 79dc7baf23d41..ea3b0638cdac1 100644 --- a/test/e2e/agent/engine/pom.xml +++ b/test/e2e/agent/engine/pom.xml @@ -107,6 +107,7 @@ ${project.basedir}/src/test/resources/docker/proxy/ Dockerfile + entrypoint/entrypoint.sh diff --git a/test/e2e/agent/engine/src/test/java/org/apache/shardingsphere/test/e2e/agent/engine/env/AgentE2ETestEnvironment.java b/test/e2e/agent/engine/src/test/java/org/apache/shardingsphere/test/e2e/agent/engine/env/AgentE2ETestEnvironment.java index 0ea49b1fa0628..83cf389f0e3ed 100644 --- a/test/e2e/agent/engine/src/test/java/org/apache/shardingsphere/test/e2e/agent/engine/env/AgentE2ETestEnvironment.java +++ b/test/e2e/agent/engine/src/test/java/org/apache/shardingsphere/test/e2e/agent/engine/env/AgentE2ETestEnvironment.java @@ -38,7 +38,6 @@ import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.shaded.org.awaitility.Awaitility; -import java.sql.SQLException; import java.time.Duration; import java.util.Collection; import java.util.LinkedList; @@ -115,11 +114,6 @@ private void createProxyEnvironment(final Optional agentPlugi containers.registerContainer(governanceContainer); containers.registerContainer(proxyContainer); containers.start(); - try { - proxyRequestExecutor = new ProxyRequestExecutor(proxyContainer.getConnection()); - proxyRequestExecutor.start(); - } catch (final SQLException ignored) { - } } @SuppressWarnings("OptionalUsedAsFieldOrParameterType") diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile index 70ac09b1d08f0..0c0f821b2396a 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile @@ -21,6 +21,11 @@ ARG APP_NAME ENV IS_DOCKER true ENV LOCAL_PATH /opt/shardingsphere-proxy +ADD entrypoint/entrypoint.sh /opt/entrypoint.sh ADD ${APP_NAME}.tar.gz /opt +RUN chmod +x /opt/entrypoint.sh RUN mv /opt/${APP_NAME} ${LOCAL_PATH} && mkdir -p ${LOCAL_PATH}/ext-lib && wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.49/mysql-connector-java-5.1.49.jar -P ${LOCAL_PATH}/ext-lib -ENTRYPOINT ${LOCAL_PATH}/bin/start.sh -g +RUN apt update +RUN apt install default-mysql-client -y + +ENTRYPOINT /opt/entrypoint.sh diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh new file mode 100644 index 0000000000000..eea75d2c25afe --- /dev/null +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -0,0 +1,26 @@ +# +# 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. +# + +bash /opt/shardingsphere-proxy/bin/start.sh -g && sleep 30 + +for ((i=1; i<=10; i++)) +do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" +done +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit=false;INSERT INTO t_order (order_id, user_id, status) VALUES (1000, 1000, \"ROLL_BACK\");" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit = fasle;UPDATE t_order SET status = 1000 WHERE order_id =1000;commit;" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM t_order;" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM non_existent_table;" From 4317485187a856c4a4fb28debbb8b18443ca93cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 00:58:27 +0800 Subject: [PATCH 2/8] Refactor : refactor the agent proxy test data script --- .../e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile | 1 + .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile index 0c0f821b2396a..759073314bbb6 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile @@ -27,5 +27,6 @@ RUN chmod +x /opt/entrypoint.sh RUN mv /opt/${APP_NAME} ${LOCAL_PATH} && mkdir -p ${LOCAL_PATH}/ext-lib && wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.49/mysql-connector-java-5.1.49.jar -P ${LOCAL_PATH}/ext-lib RUN apt update RUN apt install default-mysql-client -y +RUN "${LOCAL_PATH}/bin/start.sh -g" ENTRYPOINT /opt/entrypoint.sh diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index eea75d2c25afe..a6ffceba23bba 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -15,7 +15,7 @@ # limitations under the License. # -bash /opt/shardingsphere-proxy/bin/start.sh -g && sleep 30 +sleep 20 for ((i=1; i<=10; i++)) do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" From af399a254e4a837dd3290d2d049691c90423c513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 01:10:33 +0800 Subject: [PATCH 3/8] Refactor : refactor the agent proxy test data script --- .../e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile | 1 - .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile index 759073314bbb6..0c0f821b2396a 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/Dockerfile @@ -27,6 +27,5 @@ RUN chmod +x /opt/entrypoint.sh RUN mv /opt/${APP_NAME} ${LOCAL_PATH} && mkdir -p ${LOCAL_PATH}/ext-lib && wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.49/mysql-connector-java-5.1.49.jar -P ${LOCAL_PATH}/ext-lib RUN apt update RUN apt install default-mysql-client -y -RUN "${LOCAL_PATH}/bin/start.sh -g" ENTRYPOINT /opt/entrypoint.sh diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index a6ffceba23bba..790a5344f055e 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -15,7 +15,7 @@ # limitations under the License. # -sleep 20 +./opt/shardingsphere-proxy/bin/start.sh -g && sleep 20 for ((i=1; i<=10; i++)) do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" From 30734e4040488ac42c64a0f98a3ce85a8fb58a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 01:22:33 +0800 Subject: [PATCH 4/8] Refactor : refactor the agent proxy test data script --- .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index 790a5344f055e..9ff9386fba2fb 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -15,7 +15,7 @@ # limitations under the License. # -./opt/shardingsphere-proxy/bin/start.sh -g && sleep 20 +bash /opt/shardingsphere-proxy/bin/start.sh -g && sleep 20 for ((i=1; i<=10; i++)) do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" From 2e5af0230ee218684ce0c7716942c097d40a013f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 01:41:19 +0800 Subject: [PATCH 5/8] Refactor : refactor the agent proxy test data script --- .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index 9ff9386fba2fb..6a480c409f46a 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -15,7 +15,8 @@ # limitations under the License. # -bash /opt/shardingsphere-proxy/bin/start.sh -g && sleep 20 +nohup /opt/shardingsphere-proxy/bin/start.sh -g > /dev/null 2>&1 & +sleep 20 for ((i=1; i<=10; i++)) do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" From 3b8f430362e17d6469f0fda4cc8f55ad6f2353b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 11:58:01 +0800 Subject: [PATCH 6/8] Refactor : refactor the agent proxy test data script --- .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index 6a480c409f46a..4750b2f75487b 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -1,3 +1,4 @@ +#!/bin/bash # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,7 @@ # limitations under the License. # -nohup /opt/shardingsphere-proxy/bin/start.sh -g > /dev/null 2>&1 & +nohup bash -c "/opt/shardingsphere-proxy/bin/start.sh -g" /dev/null & sleep 20 for ((i=1; i<=10; i++)) From e2929bc2342df95e822f861ffc6da83d8c0decc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 12:34:08 +0800 Subject: [PATCH 7/8] Refactor : refactor the agent proxy test data script --- .../src/test/resources/docker/proxy/entrypoint/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index 4750b2f75487b..6146652344b38 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -23,6 +23,6 @@ for ((i=1; i<=10; i++)) do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" done mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit=false;INSERT INTO t_order (order_id, user_id, status) VALUES (1000, 1000, \"ROLL_BACK\");" -mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit = fasle;UPDATE t_order SET status = 1000 WHERE order_id =1000;commit;" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit = false;UPDATE t_order SET status = 1000 WHERE order_id =1000;commit;" mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM t_order;" mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM non_existent_table;" From f45bd8512befd9893395a040e224cd06c30f5925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Wed, 24 Jul 2024 15:58:39 +0800 Subject: [PATCH 8/8] Refactor : refactor the agent proxy test data script --- .../resources/docker/proxy/entrypoint/entrypoint.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh index 6146652344b38..c0c9f348a55cb 100644 --- a/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh +++ b/test/e2e/agent/engine/src/test/resources/docker/proxy/entrypoint/entrypoint.sh @@ -20,9 +20,14 @@ nohup bash -c "/opt/shardingsphere-proxy/bin/start.sh -g" /dev/null sleep 20 for ((i=1; i<=10; i++)) -do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;insert into t_order values (${i}, ${i}, \"INSERT_TEST\");" +do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;INSERT INTO t_order (order_id, user_id, status) VALUES (${i}, ${i}, \"INSERT_TEST\");" done -mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit=false;INSERT INTO t_order (order_id, user_id, status) VALUES (1000, 1000, \"ROLL_BACK\");" -mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit = false;UPDATE t_order SET status = 1000 WHERE order_id =1000;commit;" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit=0;INSERT INTO t_order (order_id, user_id, status) VALUES (1000, 1000, \"ROLL_BACK\");rollback" +mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;set autocommit=0;UPDATE t_order SET status = 1000 WHERE order_id =1000;commit;" mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM t_order;" +for ((i=1; i<=10; i++)) +do mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;DELETE FROM t_order WHERE order_id=${i};" +done +set +e mysql -uroot -h127.0.0.1 -proot -P3307 -e "USE sharding_db;SELECT * FROM non_existent_table;" +set -e