Skip to content

Commit

Permalink
[type:refactor] refactor module
Browse files Browse the repository at this point in the history
  • Loading branch information
moremind committed Nov 8, 2023
1 parent fc83b43 commit 1ab0371
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ jobs:
strategy:
matrix:
include:
- case: shenyu-e2e-case-http
script: e2e-http-sync
- case: shenyu-e2e-case-spring-cloud
script: e2e-springcloud-sync
- case: shenyu-e2e-case-apache-dubbo
Expand Down
1 change: 1 addition & 0 deletions shenyu-e2e/shenyu-e2e-case/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<modules>
<module>shenyu-e2e-case-storage</module>
<module>shenyu-e2e-case-http</module>
<module>shenyu-e2e-case-spring-cloud</module>
<module>shenyu-e2e-case-alibaba-dubbo</module>
<module>shenyu-e2e-case-apache-dubbo</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/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.
#

docker save shenyu-examples-http:latest | sudo k3s ctr images import -

# init kubernetes for mysql
SHENYU_TESTCASE_DIR=$(dirname "$(dirname "$(dirname "$(dirname "$0")")")")
bash "${SHENYU_TESTCASE_DIR}"/k8s/script/storage/storage_init_mysql.sh

# init register center
CUR_PATH=$(readlink -f "$(dirname "$0")")
PRGDIR=$(dirname "$CUR_PATH")
kubectl apply -f "${SHENYU_TESTCASE_DIR}"/k8s/sync/shenyu-cm.yml

# init shenyu sync
SYNC_ARRAY=("websocket" "http" "zookeeper" "etcd")
#SYNC_ARRAY=("websocket" "nacos")
MIDDLEWARE_SYNC_ARRAY=("zookeeper" "etcd" "nacos")
for sync in ${SYNC_ARRAY[@]}; do
echo -e "------------------\n"
kubectl apply -f "$SHENYU_TESTCASE_DIR"/k8s/shenyu-mysql.yml
sleep 30s
echo "[Start ${sync} synchronous] create shenyu-admin-${sync}.yml shenyu-bootstrap-${sync}.yml shenyu-examples-springcloud.yml"
# shellcheck disable=SC2199
# shellcheck disable=SC2076
# shellcheck disable=SC2154
if [[ "${MIDDLEWARE_SYNC_ARRAY[@]}" =~ "${sync}" ]]; then
kubectl apply -f "${SHENYU_TESTCASE_DIR}"/k8s/shenyu-"${sync}".yml
sleep 10s
fi
kubectl apply -f "${SHENYU_TESTCASE_DIR}"/k8s/sync/shenyu-admin-"${sync}".yml
sh "$SHENYU_TESTCASE_DIR"/k8s/script/healthcheck.sh http://localhost:31095/actuator/health
kubectl apply -f "${SHENYU_TESTCASE_DIR}"/k8s/sync/shenyu-bootstrap-"${sync}".yml
sh "$SHENYU_TESTCASE_DIR"/k8s/script/healthcheck.sh http://localhost:31195/actuator/health
kubectl apply -f "${PRGDIR}"/shenyu-examples-http.yml
sh "$SHENYU_TESTCASE_DIR"/k8s/script/healthcheck.sh http://localhost:31189/grpc/actuator/health
sleep 10s
kubectl get pod -o wide

## run e2e-test
./mvnw -B -f ./shenyu-e2e/pom.xml -pl shenyu-e2e-case/shenyu-e2e-case-grpc -am test
# shellcheck disable=SC2181
if (($?)); then
echo "${sync}-sync-e2e-test failed"
echo "shenyu-admin log:"
echo "------------------"
kubectl logs "$(kubectl get pod -o wide | grep shenyu-admin | awk '{print $1}')"
echo "shenyu-bootstrap log:"
echo "------------------"
kubectl logs "$(kubectl get pod -o wide | grep shenyu-bootstrap | awk '{print $1}')"
exit 1
fi
kubectl delete -f "${SHENYU_TESTCASE_DIR}"/k8s/shenyu-mysql.yml
kubectl delete -f "${SHENYU_TESTCASE_DIR}"/k8s/sync/shenyu-admin-"${sync}".yml
kubectl delete -f "${SHENYU_TESTCASE_DIR}"/k8s/sync/shenyu-bootstrap-"${sync}".yml
kubectl delete -f "${PRGDIR}"/shenyu-examples-grpc.yml
# shellcheck disable=SC2199
# shellcheck disable=SC2076
if [[ "${MIDDLEWARE_SYNC_ARRAY[@]}" =~ "${sync}" ]]; then
kubectl delete -f "${SHENYU_TESTCASE_DIR}"/k8s/shenyu-"${sync}".yml
fi
echo "[Remove ${sync} synchronous] delete shenyu-admin-${sync}.yml shenyu-bootstrap-${sync}.yml shenyu-examples-springcloud.yml"
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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.

apiVersion: apps/v1
kind: Deployment
metadata:
name: shenyu-examples-http
labels:
app: shenyu-examples-http
spec:
replicas: 1
selector:
matchLabels:
app: shenyu-examples-http
strategy: {}
template:
metadata:
labels:
app: shenyu-examples-http
spec:
containers:
- image: shenyu-examples-http
name: shenyu-examples-http
livenessProbe:
exec:
command:
- wget -q -O - http://localhost:8189/actuator/health | grep UP || exit 1
initialDelaySeconds: 10
failureThreshold: 3
timeoutSeconds: 2
env:
- name: shenyu.register.serverLists
value: http://shenyu-admin:9095
ports:
- containerPort: 8189
imagePullPolicy: IfNotPresent
restartPolicy: Always
status: {}

---
apiVersion: v1
kind: Service
metadata:
name: shenyu-examples-http
labels:
app: shenyu-examples-http
spec:
selector:
app: shenyu-examples-http
type: NodePort
ports:
- name: "8189"
port: 8189
targetPort: 8189
nodePort: 31189
status:
loadBalancer: {}
28 changes: 28 additions & 0 deletions shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-http/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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">
<parent>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-e2e-case</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-e2e-case-http</artifactId>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.shenyu.e2e.testcase.http;

import org.apache.shenyu.e2e.client.WaitDataSync;
import org.apache.shenyu.e2e.client.admin.AdminClient;
import org.apache.shenyu.e2e.client.gateway.GatewayClient;
import org.apache.shenyu.e2e.engine.annotation.ShenYuTest;
import org.apache.shenyu.e2e.enums.ServiceTypeEnum;
import org.junit.jupiter.api.Test;

/**
* Testing the correctness of etcd data synchronization method.
*/
@ShenYuTest(environments = {
@ShenYuTest.Environment(
serviceName = "shenyu-e2e-admin",
service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e",
baseUrl = "http://localhost:31095",
type = ServiceTypeEnum.SHENYU_ADMIN,
parameters = {
@ShenYuTest.Parameter(key = "username", value = "admin"),
@ShenYuTest.Parameter(key = "password", value = "123456")
}
)
),
@ShenYuTest.Environment(
serviceName = "shenyu-e2e-gateway",
service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e",
baseUrl = "http://localhost:31195",
type = ServiceTypeEnum.SHENYU_GATEWAY
)
)
})
public class DataSynTest {

@Test
void testDataSyn(final AdminClient adminClient, final GatewayClient gatewayClient) throws Exception {
adminClient.login();
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllSelectors, gatewayClient::getSelectorCache, adminClient);
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllMetaData, gatewayClient::getMetaDataCache, adminClient);
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllRules, gatewayClient::getRuleCache, adminClient);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.shenyu.e2e.testcase.http;

import com.google.common.collect.Lists;
import org.apache.shenyu.e2e.engine.scenario.ShenYuScenarioProvider;
import org.apache.shenyu.e2e.engine.scenario.specification.ScenarioSpec;
import org.apache.shenyu.e2e.engine.scenario.specification.ShenYuBeforeEachSpec;
import org.apache.shenyu.e2e.engine.scenario.specification.ShenYuCaseSpec;
import org.apache.shenyu.e2e.engine.scenario.specification.ShenYuScenarioSpec;

import java.util.List;
import static org.apache.shenyu.e2e.engine.scenario.function.HttpCheckers.exists;

public class DividePluginCases implements ShenYuScenarioProvider {
@Override
public List<ScenarioSpec> get() {
return Lists.newArrayList(
testDivideHello()
);
}

private ShenYuScenarioSpec testDivideHello() {
return ShenYuScenarioSpec.builder()
.name("single-divide uri =]")
.beforeEachSpec(ShenYuBeforeEachSpec.builder()
.checker(exists("/http/shenyu/client/hello"))
.build())
.caseSpec(ShenYuCaseSpec.builder()
.addExists("/http/shenyu/client/hello")
.addNotExists("/http/shenyu/client/hello/222/111")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.shenyu.e2e.testcase.http;

import org.apache.shenyu.e2e.client.WaitDataSync;
import org.apache.shenyu.e2e.client.admin.AdminClient;
import org.apache.shenyu.e2e.client.gateway.GatewayClient;
import org.apache.shenyu.e2e.engine.annotation.ShenYuScenario;
import org.apache.shenyu.e2e.engine.annotation.ShenYuTest;
import org.apache.shenyu.e2e.engine.scenario.specification.CaseSpec;
import org.apache.shenyu.e2e.enums.ServiceTypeEnum;
import org.junit.jupiter.api.BeforeAll;

@ShenYuTest(environments = {
@ShenYuTest.Environment(
serviceName = "shenyu-e2e-admin",
service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e",
baseUrl = "http://localhost:31095",
type = ServiceTypeEnum.SHENYU_ADMIN,
parameters = {
@ShenYuTest.Parameter(key = "username", value = "admin"),
@ShenYuTest.Parameter(key = "password", value = "123456")
}
)
),
@ShenYuTest.Environment(
serviceName = "shenyu-e2e-gateway",
service = @ShenYuTest.ServiceConfigure(moduleName = "shenyu-e2e",
baseUrl = "http://localhost:31195",
type = ServiceTypeEnum.SHENYU_GATEWAY
)
)
})
public class DividePluginTest {

@BeforeAll
void setup(final AdminClient adminClient, final GatewayClient gatewayClient) throws Exception {
adminClient.login();
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllSelectors, gatewayClient::getSelectorCache, adminClient);
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllMetaData, gatewayClient::getMetaDataCache, adminClient);
WaitDataSync.waitAdmin2GatewayDataSyncEquals(adminClient::listAllRules, gatewayClient::getRuleCache, adminClient);
}

@ShenYuScenario(provider = DividePluginCases.class)
void testDivide(final GatewayClient gateway, final CaseSpec spec) {
spec.getVerifiers().forEach(verifier -> verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
}

0 comments on commit 1ab0371

Please sign in to comment.