| # |
| # 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. |
| # |
| |
| name: Integration Test for Proxy Helm Charts |
| |
| on: push |
| |
| jobs: |
| run: |
| name: Integration Test for ShardingSphere Proxy Helm Charts |
| runs-on: ubuntu-latest |
| steps: |
| - name: "Checkout codes" |
| uses: actions/checkout@v3 |
| - name: "Setup kind" |
| uses: helm/kind-action@v1.2.0 |
| - name: "Setup helm" |
| uses: azure/setup-helm@v2.1 |
| - name: "Setup kubectl" |
| uses: azure/setup-kubectl@v2.0 |
| - name: "Test Helm Charts for ShardingSphere Proxy" |
| run: | |
| set -x |
| export TEST_NAMESPACE="shardingsphere-system" |
| kubectl create namespace ${TEST_NAMESPACE} |
| cd charts/shardingsphere-proxy/charts/governance |
| helm dependency build |
| cd ../.. |
| helm dependency build |
| cd .. |
| helm install shardingsphere-proxy shardingsphere-proxy -n ${TEST_NAMESPACE} --set compute.replicas=1 |
| kubectl wait --timeout=60s --for=condition=Ready --all pod -n ${TEST_NAMESPACE} |
| kubectl get pod,svc -n ${TEST_NAMESPACE} --show-labels |
| cd .. |
| kubectl apply -f hack/kubernetes/mysql.yml |
| sleep 180 |
| kubectl get pod,svc -n default --show-labels |
| kubectl wait --timeout=120s --for=condition=Ready --all pod -n ${TEST_NAMESPACE} |
| kubectl get pod,svc -n default --show-labels |
| kubectl port-forward svc/shardingsphere-proxy-apache-shardingsphere-proxy 3307:3307 -n ${TEST_NAMESPACE} & |
| kubectl port-forward svc/mysql-1 3316:3306 -n default & |
| kubectl port-forward svc/mysql-2 3326:3306 -n default & |
| sleep 3 |
| - name: "Prepare mysql" |
| uses: shogo82148/actions-setup-mysql@v1 |
| with: |
| mysql-version: '5.7' |
| - name: "Create schema from MySQL-1" |
| run: mysql -h127.0.0.1 -P3316 -uroot -proot -e 'CREATE DATABASE ds_1;' |
| - name: "Create schema from MySQL-2" |
| run: mysql -h127.0.0.1 -P3326 -uroot -proot -e 'CREATE DATABASE ds_2;' |
| - name: "Create sharding db" |
| run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'CREATE DATABASE sharding_db; USE sharding_db;ADD RESOURCE ds_0 (HOST="mysql-1.default",PORT=3306,DB="ds_1",USER="root",PASSWORD="root"),ds_1 (HOST="mysql-2.default",PORT=3306,DB="ds_2",USER="root",PASSWORD="root");CREATE SHARDING TABLE RULE t_order(RESOURCES(ds_0,ds_1),SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="2")),KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake")));CREATE TABLE `t_order` (`order_id` int NOT NULL,`user_id` int NOT NULL,`status` varchar(45) DEFAULT NULL,PRIMARY KEY (`order_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;INSERT INTO `t_order` VALUES(1, 1, "code1"),(2, 2, "code2");' |
| #- name: "Run DistSQL add resource" |
| #run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'ADD RESOURCE ds_0 (HOST="mysql-1.default",PORT=3306,DB="ds_1",USER="root",PASSWORD="root"),ds_1 (HOST="mysql-2.default",PORT=3306,DB="ds_2",USER="root",PASSWORD="root");' |
| #- name: "Run DistSQL add sharding rule" |
| #run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'CREATE SHARDING TABLE RULE t_order(RESOURCES(ds_0,ds_1),SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="2")),KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake")));' |
| #- name: "Run DistSQL add sharding table" |
| #run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'CREATE TABLE `t_order` (`order_id` int NOT NULL,`user_id` int NOT NULL,`status` varchar(45) DEFAULT NULL,PRIMARY KEY (`order_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;' |
| #- name: "Run insert data" |
| #run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'INSERT INTO `t_order` VALUES(1, 1, "code1"),(2, 2, "code2");' |
| - name: "Quert data" |
| run: mysql -h127.0.0.1 -P3307 -uroot -proot -e 'USE sharding_db;SELECT * FROM t_order;' |
| - name: "Query data from MySQL-1" |
| run: mysql -h127.0.0.1 -P3316 -uroot -proot -e 'USE ds_1;SELECT * FROM `t_order_0`;' |
| - name: "Query data from MySQL-2 " |
| run: mysql -h127.0.0.1 -P3326 -uroot -proot -e 'USE ds_2;SELECT * FROM `t_order_1`;' |