Compare commits
229 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7d9f4b5234 | ||
|
b6b58ad584 | ||
|
528c33a9fb | ||
|
106a1d57dd | ||
|
bbed5a4eb7 | ||
|
7133411bc2 | ||
|
c56c4153eb | ||
|
bcbdb863ba | ||
|
5d8d81aae4 | ||
|
4e42fe6bad | ||
|
3967c91d1a | ||
|
cfa3312582 | ||
|
525f3bf43f | ||
|
48a0f8b0fb | ||
|
927fbfd110 | ||
|
3e28b586bb | ||
|
631babe1e2 | ||
|
c00d863242 | ||
|
0f023a270f | ||
|
6122a9afc4 | ||
|
6c6a22b4cc | ||
|
96a93189c3 | ||
|
fbfa39d06d | ||
|
f4a4ab2eb5 | ||
|
7e577811a7 | ||
|
197795a854 | ||
|
298f36f145 | ||
|
4e776256eb | ||
|
ad83ff0c75 | ||
|
ed7bd03d4c | ||
|
fc5e502243 | ||
|
1879c81edd | ||
|
4f827ca0d9 | ||
|
c717538bd7 | ||
|
8664a1aec6 | ||
|
a6047fae45 | ||
|
47d913de05 | ||
|
9d0a48d54f | ||
|
6c05ad5497 | ||
|
de5ade75c8 | ||
|
2233e6556c | ||
|
2aa9fc51bc | ||
|
8aba80d3c1 | ||
|
e8e8cd29c0 | ||
|
97162438f7 | ||
|
92a3d17681 | ||
|
b8d13e0557 | ||
|
8034da88e5 | ||
|
108f51083f | ||
|
8575e84ee4 | ||
|
29c28bd01e | ||
|
27da090b7c | ||
|
3b2f787d61 | ||
|
63dc87a30c | ||
|
5d871967ea | ||
|
e192e25d9d | ||
|
cd8e8583d8 | ||
|
21bfac76e7 | ||
|
ab6591ac83 | ||
|
833e6ca59a | ||
|
7590a4eb12 | ||
|
d68b904f93 | ||
|
8a03485fa8 | ||
|
07d92ffb3e | ||
|
7cdf224157 | ||
|
da78aeea0d | ||
|
d1bd44625f | ||
|
19c3adcbb6 | ||
|
d212a52bc9 | ||
|
0d8b04b470 | ||
|
96ee0f37e6 | ||
|
5f7801b341 | ||
|
04f9b86e45 | ||
|
79a5aa5eb6 | ||
|
67da6d1b5f | ||
|
25155e480a | ||
|
857e6113c4 | ||
|
47786e6c0b | ||
|
98edf22e8c | ||
|
0a797223c0 | ||
|
bc039bc125 | ||
|
6fa3069b7e | ||
|
992f10a1d6 | ||
|
6bee5c47a9 | ||
|
366c88e4d6 | ||
|
9363a088f0 | ||
|
35e3994bcb | ||
|
94bf8661ad | ||
|
26176ddb3c | ||
|
dc0e46e9f9 | ||
|
67b672251e | ||
|
5169f06654 | ||
|
6fe43637c0 | ||
|
9a6ec0ca3d | ||
|
15c9663d31 | ||
|
4e2bcb9277 | ||
|
47dd078545 | ||
|
b047a90fba | ||
|
7c461fdf67 | ||
|
ed64d1f055 | ||
|
99807358df | ||
|
8d6f87eda6 | ||
|
70ad2eb991 | ||
|
b2e506d7fe | ||
|
b016e79dfe | ||
|
da3e88b3d4 | ||
|
de10c07146 | ||
|
17dea53d20 | ||
|
4d30b042ee | ||
|
720519b1dc | ||
|
96814ff00d | ||
|
2bb7193d1b | ||
|
5c19ac12ad | ||
|
2005ca6f90 | ||
|
9b2cc662ec | ||
|
fb597084c5 | ||
|
5c141593d8 | ||
|
d179e47df4 | ||
|
d4126ba2bd | ||
|
8af8519c6d | ||
|
c09ee2da04 | ||
|
facf4c8270 | ||
|
19a857b701 | ||
|
25585d65dd | ||
|
5fcef225be | ||
|
2df335d57e | ||
|
6461aeb719 | ||
|
3a1f0c297e | ||
|
ec4f21540e | ||
|
08edb4fbd6 | ||
|
a7d9ef2fe8 | ||
|
082c5073bb | ||
|
6dc0a2109f | ||
|
9db51e58ed | ||
|
9fd6ff6a04 | ||
|
b79d585f97 | ||
|
038420c69f | ||
|
c86147b6ab | ||
|
0d7fcff261 | ||
|
d26ed3623e | ||
|
3b319502a1 | ||
|
5a5473bdbd | ||
|
15fbf92b15 | ||
|
2f2fc1b12b | ||
|
4397e8d275 | ||
|
c2aa515f1e | ||
|
b7c3905976 | ||
|
92dda945a0 | ||
|
64b9e8d3f7 | ||
|
8f1cb59370 | ||
|
961d56ccce | ||
|
fdbc99dd99 | ||
|
889a78a82b | ||
|
a275356c10 | ||
|
7f4c7f8297 | ||
|
4f279bf110 | ||
|
c2f8463e12 | ||
|
fde996d2a6 | ||
|
1710fa32a2 | ||
|
1d3f1bb492 | ||
|
7d085a8846 | ||
|
0ee724ee7f | ||
|
3c278edba9 | ||
|
e6eb636aed | ||
|
21f8065073 | ||
|
139f4f2377 | ||
|
3da1240f3a | ||
|
2bb93982df | ||
|
9fcc4c0dbe | ||
|
1b9a22c1a8 | ||
|
9d473ef60c | ||
|
8f2150892a | ||
|
817eb58597 | ||
|
bd5caa64a6 | ||
|
849393c4a1 | ||
|
9722ad8dd5 | ||
|
dd385294f5 | ||
|
5f9c848d7e | ||
|
30a5014e5d | ||
|
f5d72a3455 | ||
|
51fa941df7 | ||
|
07168099db | ||
|
bdbc356ce4 | ||
|
1943825e4d | ||
|
a7d1c35f85 | ||
|
207505735c | ||
|
b4a380f15b | ||
|
84900756d1 | ||
|
c98b8c4111 | ||
|
f3fb60ebf3 | ||
|
c70a86820d | ||
|
dbb1b65fcb | ||
|
ea94095f74 | ||
|
2296125d41 | ||
|
8a69c9e8ac | ||
|
97104b2445 | ||
|
6b0636dd5d | ||
|
d4e2ccda82 | ||
|
526227c77b | ||
|
6587029851 | ||
|
9e48e8cb3b | ||
|
41222ee99a | ||
|
4d76eb7c31 | ||
|
d40190ee24 | ||
|
ca9d55e264 | ||
|
790bb197cf | ||
|
ab2ddac06f | ||
|
d84a566235 | ||
|
06edd123f9 | ||
|
58803687c8 | ||
|
a3420b733b | ||
|
26d045ca49 | ||
|
327ebaf36e | ||
|
01a28ee3cd | ||
|
92f36b1d30 | ||
|
cd2d4149b5 | ||
|
3058f9f8ff | ||
|
319ec8c257 | ||
|
380c019fdd | ||
|
18a4672dd9 | ||
|
2fd002c8d1 | ||
|
de739e9b9c | ||
|
33cb6e26c7 | ||
|
f8b3d35e88 | ||
|
7fdbc63390 | ||
|
263e223d94 | ||
|
4ad98d837d | ||
|
cc34b6ca0d | ||
|
c026d2f3ac |
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@ -6,11 +6,10 @@ name: "Continuous Integration"
|
||||
on:
|
||||
push:
|
||||
branches: [ master, develop, v1.x-develop, v1.X ]
|
||||
pull_request:
|
||||
pull_request_target:
|
||||
branches: [ develop, v1.x-develop ]
|
||||
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
@ -21,16 +20,16 @@ jobs:
|
||||
java: [8]
|
||||
steps:
|
||||
- name: "Cache Maven Repos"
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: "Set up JDK ${{ matrix.java }}"
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'zulu'
|
||||
@ -44,6 +43,11 @@ jobs:
|
||||
- name: "Test With Maven"
|
||||
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||
- name: "Codecov"
|
||||
uses: codecov/codecov-action@v3.1.0
|
||||
uses: codecov/codecov-action@v4.2.0
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
with:
|
||||
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./persistence/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-auth-plugin/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/config/target/site/jacoco/jacoco.xml,./plugin/control/target/site/jacoco/jacoco.xml,./plugin/datasource/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./plugin/environment/target/site/jacoco/jacoco.xml,./plugin/trace/target/site/jacoco/jacoco.xml,./prometheus/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
|
||||
verbose: true
|
||||
fail_ci_if_error: true
|
||||
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./config/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./logger-adapter-impl/log4j2-adapter/target/site/jacoco/jacoco.xml,./logger-adapter-impl/logback-adapter-12/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./persistence/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-auth-plugin/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-control-plugin/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/config/target/site/jacoco/jacoco.xml,./plugin/control/target/site/jacoco/jacoco.xml,./plugin/datasource/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./plugin/environment/target/site/jacoco/jacoco.xml,./plugin/trace/target/site/jacoco/jacoco.xml,./prometheus/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
488
.github/workflows/pr-e2e-test.yml
vendored
488
.github/workflows/pr-e2e-test.yml
vendored
@ -6,10 +6,11 @@ on:
|
||||
workflows: ["PR-CI"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
@ -22,6 +23,8 @@ jobs:
|
||||
matrix:
|
||||
base-image: ["ubuntu"]
|
||||
java-version: ["8"]
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v3.1.0
|
||||
@ -33,7 +36,7 @@ jobs:
|
||||
run_id: ${{ github.event.workflow_run.id }},
|
||||
});
|
||||
var matchArtifactNacos = artifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "nacos"
|
||||
return artifact.name == "nacos"
|
||||
})[0];
|
||||
var download = await github.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
@ -47,19 +50,12 @@ jobs:
|
||||
unzip nacos.zip
|
||||
mkdir nacos
|
||||
cp -r nacos-* nacos/
|
||||
ls
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: nacos-group/nacos-e2e.git
|
||||
ref: main
|
||||
path: nacos-e2e
|
||||
- name: docker-login
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and save docker images
|
||||
- name: Generate image tag
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*.tar.gz nacos-e2e/cicd/build
|
||||
@ -68,43 +64,44 @@ jobs:
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
||||
echo $tag
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
||||
docker push ${DOCKER_REPO}:${tag}
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||
- name: docker-login-1
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
name: versionlist
|
||||
path: nacos-e2e/cicd/build/versionlist/*
|
||||
|
||||
|
||||
list-version:
|
||||
if: always()
|
||||
name: List version
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
name: Download versionlist
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: save docker_1 images
|
||||
run: |
|
||||
mkdir build_backup
|
||||
cp -rf nacos-e2e/cicd/build/* ./build_backup/
|
||||
cd nacos-e2e/cicd/build
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${{ env.TAG }} .
|
||||
docker push ${DOCKER_REPO}:${{ env.TAG }}
|
||||
- name: docker-login-2
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
name: versionlist
|
||||
path: versionlist
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER_B }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN_B }}
|
||||
- name: save docker_2 images
|
||||
run: |
|
||||
rm -rf nacos-e2e/cicd/build/*
|
||||
mv ./build_backup/* nacos-e2e/cicd/build/
|
||||
cd nacos-e2e/cicd/build
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO_B}:${{ env.TAG }} .
|
||||
docker push ${DOCKER_REPO_B}:${{ env.TAG }}
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls versionlist`)
|
||||
run: |
|
||||
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
|
||||
deploy:
|
||||
if: ${{ success() }}
|
||||
name: Deploy nacos
|
||||
needs: [list-version,docker]
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
@ -112,99 +109,392 @@ jobs:
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
echo "REPLICA_COUNT=1" >> $GITHUB_ENV
|
||||
echo "DATABASE=embedded" >> $GITHUB_ENV
|
||||
- name: allocate docker repo
|
||||
run: |
|
||||
if [[ $(expr $(expr ${{ github.run_id }} + ${{ strategy.job-index }} ) % 2 ) -eq 1 ]]; then
|
||||
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO }}" >> $GITHUB_ENV
|
||||
else
|
||||
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO_B }}" >> $GITHUB_ENV
|
||||
fi
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: Deploy nacos
|
||||
with:
|
||||
action: "deploy"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
chart-git: "https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git"
|
||||
chart-branch: "main"
|
||||
chart-path: "./cicd/helm"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
helm-values: |
|
||||
yamlString: |
|
||||
action: deploy
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-test:
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
waitTimes: 2000
|
||||
velaAppDescription: nacos-${{ env.GITHUB_WORKFLOW }}-${{ github.run_id }}@${{ matrix.version }}
|
||||
repoName: nacos
|
||||
helm:
|
||||
chart: ./cicd/helm
|
||||
git:
|
||||
branch: main
|
||||
repoType: git
|
||||
retries: 3
|
||||
url: https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git
|
||||
values:
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO_ACTUAL }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-java-test:
|
||||
if: ${{ success() }}
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
name: Java e2e Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: e2e test
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: java e2e test
|
||||
with:
|
||||
action: "test"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
||||
test-code-branch: "main"
|
||||
test-code-path: "java/nacos-2X"
|
||||
test-cmd: 'mvn clean test -B'
|
||||
job-id: ${{ strategy.job-index }}
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v3
|
||||
if: always() # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/test_report/TEST-*.xml'
|
||||
annotate_only: true
|
||||
include_passed: true
|
||||
detailed_summary: true
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: java/nacos-2X
|
||||
CMD: mvn clean test -B
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
name: testlog-${{ matrix.mode }}-java.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
||||
e2e-go-test:
|
||||
if: ${{ success() }}
|
||||
name: GO E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: go e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: golang
|
||||
CMD: |
|
||||
cd /root/code/golang && go mod init nacos_go_test && go mod tidy
|
||||
gotestsum --junitfile ./target/surefire-reports/TEST-report.xml ./nacosgotest
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-go.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-cpp-test:
|
||||
if: ${{ success() }}
|
||||
name: Cpp E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: cpp e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: cpp
|
||||
CMD: |
|
||||
cd /root/code/cpp && make install
|
||||
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc && source ~/.bashrc
|
||||
cd /root/code/cpp/nacoscpptest
|
||||
g++ nacos_test.cpp -o nacos_test -lgtest -lpthread -I/usr/local/include/nacos/ -L/usr/local/lib/ -lnacos-cli
|
||||
chmod 777 nacos_test && ./nacos_test --gtest_output="xml:../target/surefire-reports/TEST-gtestresults.xml"
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-cpp.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-csharp-test:
|
||||
if: ${{ success() }}
|
||||
name: Csharp E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: csharp e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: csharp
|
||||
CMD: |
|
||||
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
|
||||
yum -y install dotnet-sdk-3.1 && yum -y install aspnetcore-runtime-7.0
|
||||
cd /root/code/csharp/nacos-csharp-sdk-test && dotnet restore
|
||||
dotnet test --logger:"junit;LogFilePath=../target/surefire-reports/TEST-result.xml"
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-csharp.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-nodejs-test:
|
||||
if: ${{ success() }}
|
||||
name: Nodejs E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: nodejs e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: nodejs
|
||||
CMD: |
|
||||
cd /root/code/nodejs/nacosnodejstest && npm install
|
||||
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=../target/surefire-reports/TEST-report.xml
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-nodejs.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-python-test:
|
||||
if: ${{ success() }}
|
||||
name: Python E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: python e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: python
|
||||
CMD: |
|
||||
cd /root/code/python
|
||||
pip3 install -r requirements.txt
|
||||
source ~/.bashrc
|
||||
cd nacospythontest && pytest --junitxml ../target/surefire-reports/TEST-report.xml test/*_test.py --log-cli-level=DEBUG
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-python.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
||||
clean:
|
||||
if: always()
|
||||
name: Clean
|
||||
needs: [list-version, e2e-test]
|
||||
needs: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: clean
|
||||
with:
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
yamlString: |
|
||||
action: clean
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
|
484
.github/workflows/push-ci.yaml
vendored
484
.github/workflows/push-ci.yaml
vendored
@ -5,15 +5,15 @@ on:
|
||||
branches: [master, develop, v1.x-develop, v1.X]
|
||||
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: nacos-${{ github.ref }}
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||
|
||||
jobs:
|
||||
dist-tar:
|
||||
@ -50,10 +50,15 @@ jobs:
|
||||
needs: [dist-tar]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
DOCKERHUB_USER_ACTUAL: ${{ secrets.DOCKERHUB_USER }}
|
||||
DOCKERHUB_TOKEN_ACTUAL: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
strategy:
|
||||
matrix:
|
||||
base-image: ["centos"]
|
||||
java-version: ["8"]
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
@ -65,13 +70,7 @@ jobs:
|
||||
with:
|
||||
name: nacos
|
||||
path: ./
|
||||
- name: docker-login
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and save docker images
|
||||
- name: Generate image tag
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*.tar.gz nacos-e2e/cicd/build/
|
||||
@ -80,42 +79,44 @@ jobs:
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
||||
echo $tag
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
||||
docker push ${DOCKER_REPO}:${tag}
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||
- name: docker-login-1
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
name: versionlist
|
||||
path: nacos-e2e/cicd/build/versionlist/*
|
||||
|
||||
|
||||
list-version:
|
||||
if: always()
|
||||
name: List version
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
name: Download versionlist
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: save docker_1 images
|
||||
run: |
|
||||
mkdir build_backup
|
||||
cp -rf nacos-e2e/cicd/build/* ./build_backup/
|
||||
cd nacos-e2e/cicd/build
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${{ env.TAG }} .
|
||||
docker push ${DOCKER_REPO}:${{ env.TAG }}
|
||||
- name: docker-login-2
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
name: versionlist
|
||||
path: versionlist
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER_B }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN_B }}
|
||||
- name: save docker_2 images
|
||||
run: |
|
||||
rm -rf nacos-e2e/cicd/build/*
|
||||
mv ./build_backup/* nacos-e2e/cicd/build/
|
||||
cd nacos-e2e/cicd/build
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO_B}:${{ env.TAG }} .
|
||||
docker push ${DOCKER_REPO_B}:${{ env.TAG }}
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls versionlist`)
|
||||
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
deploy:
|
||||
if: ${{ success() }}
|
||||
name: Deploy nacos
|
||||
needs: [list-version,docker]
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
@ -123,99 +124,390 @@ jobs:
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
echo "REPLICA_COUNT=1" >> $GITHUB_ENV
|
||||
echo "DATABASE=embedded" >> $GITHUB_ENV
|
||||
- name: allocate docker repo
|
||||
run: |
|
||||
if [[ $(expr $(expr ${{ github.run_id }} + ${{ strategy.job-index }} ) % 2 ) -eq 1 ]]; then
|
||||
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO }}" >> $GITHUB_ENV
|
||||
else
|
||||
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO_B }}" >> $GITHUB_ENV
|
||||
fi
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: Deploy nacos
|
||||
with:
|
||||
action: "deploy"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
chart-git: "https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git"
|
||||
chart-branch: "main"
|
||||
chart-path: "./cicd/helm"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
helm-values: |
|
||||
yamlString: |
|
||||
action: deploy
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-test:
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
waitTimes: 2000
|
||||
velaAppDescription: nacos-${{ env.GITHUB_WORKFLOW }}-${{ github.run_id }}@${{ matrix.version }}
|
||||
repoName: nacos
|
||||
helm:
|
||||
chart: ./cicd/helm
|
||||
git:
|
||||
branch: main
|
||||
repoType: git
|
||||
retries: 3
|
||||
url: https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git
|
||||
values:
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO_ACTUAL }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-java-test:
|
||||
if: ${{ success() }}
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
name: Java e2e Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: e2e test
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: java e2e test
|
||||
with:
|
||||
action: "test"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
||||
test-code-branch: "main"
|
||||
test-code-path: "java/nacos-2X"
|
||||
test-cmd: 'mvn clean test -B'
|
||||
job-id: ${{ strategy.job-index }}
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v3
|
||||
if: always() # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/test_report/TEST-*.xml'
|
||||
annotate_only: true
|
||||
include_passed: true
|
||||
detailed_summary: true
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: java/nacos-2X
|
||||
CMD: mvn clean test -B
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
name: testlog-${{ matrix.mode }}-java.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
||||
e2e-go-test:
|
||||
if: ${{ success() }}
|
||||
name: GO E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: go e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: golang
|
||||
CMD: |
|
||||
cd /root/code/golang && go mod init nacos_go_test && go mod tidy
|
||||
gotestsum --junitfile ./target/surefire-reports/TEST-report.xml ./nacosgotest
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-go.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-cpp-test:
|
||||
if: ${{ success() }}
|
||||
name: Cpp E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: cpp e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: cpp
|
||||
CMD: |
|
||||
cd /root/code/cpp && make install
|
||||
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc && source ~/.bashrc
|
||||
cd /root/code/cpp/nacoscpptest
|
||||
g++ nacos_test.cpp -o nacos_test -lgtest -lpthread -I/usr/local/include/nacos/ -L/usr/local/lib/ -lnacos-cli
|
||||
chmod 777 nacos_test && ./nacos_test --gtest_output="xml:../target/surefire-reports/TEST-gtestresults.xml"
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-cpp.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-csharp-test:
|
||||
if: ${{ success() }}
|
||||
name: Csharp E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: csharp e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: csharp
|
||||
CMD: |
|
||||
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
|
||||
yum -y install dotnet-sdk-3.1 && yum -y install aspnetcore-runtime-7.0
|
||||
cd /root/code/csharp/nacos-csharp-sdk-test && dotnet restore
|
||||
dotnet test --logger:"junit;LogFilePath=../target/surefire-reports/TEST-result.xml"
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-csharp.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-nodejs-test:
|
||||
if: ${{ success() }}
|
||||
name: Nodejs E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: nodejs e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: nodejs
|
||||
CMD: |
|
||||
cd /root/code/nodejs/nacosnodejstest && npm install
|
||||
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=../target/surefire-reports/TEST-report.xml
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-nodejs.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
e2e-python-test:
|
||||
if: ${{ success() }}
|
||||
name: Python E2E Test
|
||||
needs: [docker, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: python e2e test
|
||||
with:
|
||||
yamlString: |
|
||||
action: test
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
API_VERSION: v1
|
||||
KIND: Pod
|
||||
RESTART_POLICY: Never
|
||||
ENV:
|
||||
WAIT_TIME: 900
|
||||
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||
BRANCH: main
|
||||
CODE_PATH: python
|
||||
CMD: |
|
||||
cd /root/code/python && pip3 install -r requirements.txt && source ~/.bashrc
|
||||
cd nacospythontest && pytest --junitxml ../target/surefire-reports/TEST-report.xml test/*_test.py --log-cli-level=DEBUG
|
||||
ALL_IP: null
|
||||
CONTAINER:
|
||||
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||
RESOURCE_LIMITS:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
RESOURCE_REQUIRE:
|
||||
cpu: 2
|
||||
memory: 2Gi
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-python.txt
|
||||
path: testlog.txt
|
||||
- name: add markdown
|
||||
if: always()
|
||||
run: |
|
||||
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
||||
clean:
|
||||
if: always()
|
||||
name: Clean
|
||||
needs: [list-version, e2e-test]
|
||||
needs: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: clean
|
||||
with:
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
yamlString: |
|
||||
action: clean
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ test/logs
|
||||
derby.log
|
||||
yarn.lock
|
||||
.flattened-pom.xml
|
||||
lefthook.yml
|
||||
|
@ -116,7 +116,7 @@
|
||||
* [#175] Support deregistering instance automatically.
|
||||
* [#176] Naming client query instance method should bypass local cache at client start.
|
||||
* [#177] Console supports registering new empty service and delete empty service.
|
||||
* [#181] NPE when adding a instance if no leader in the raft cluster.
|
||||
* [#181] NPE when adding an instance if no leader in the raft cluster.
|
||||
* [#193] Configure host domain name cause nacos server cluster is unavailable.
|
||||
* [#209] Disable service and cluster level customization in client registerInstance method.
|
||||
* [#214] Please support Java 11.
|
||||
|
14
README.md
14
README.md
@ -86,7 +86,7 @@ You can view the full documentation from the [Nacos website](https://nacos.io/en
|
||||
|
||||
You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).
|
||||
|
||||
All the latest and long-term notice can also be found here from [Github notice issue](https://github.com/alibaba/nacos/labels/notice).
|
||||
All the latest and long-term notice can also be found here from [GitHub notice issue](https://github.com/alibaba/nacos/labels/notice).
|
||||
|
||||
## Contributing
|
||||
|
||||
@ -121,19 +121,21 @@ Contributors are welcomed to join Nacos project. Please check [CONTRIBUTING](./C
|
||||
* commits-nacos@googlegroups.com: Commits notice, very high frequency.
|
||||
* Join us from DingDing(Group 1: 21708933(full), Group 2: 30438813(full), Group 3: 31222241(full), Group 4: 12810027056).
|
||||
|
||||
![Nacos](https://img.alicdn.com/imgextra/i1/O1CN01ULSVXu1DRbANwVC6r_!!6000000000213-2-tps-666-884.png)
|
||||
|
||||
<img src="https://img.alicdn.com/imgextra/i4/O1CN01MI7re41xTrZNdB7Yv_!!6000000006445-0-tps-974-1228.jpg" width="500">
|
||||
|
||||
## Enterprise Service
|
||||
If you need Nacos enterprise service support, or purchase cloud product services, you can join the discussion by scanning the following DingTalk group. It can also be directly activated and used through the microservice engine (MSE) provided by Alibaba Cloud.
|
||||
https://cn.aliyun.com/product/aliware/mse?spm=nacos-website.topbar.0.0.0
|
||||
|
||||
![image](https://user-images.githubusercontent.com/17695352/128659442-65b030b8-c5f4-4bb7-baa2-e5b3ef0cbc15.png)
|
||||
<img src="https://img.alicdn.com/imgextra/i3/O1CN01RTfN7q1KUzX4TcH08_!!6000000001168-2-tps-864-814.png" width="500">
|
||||
|
||||
|
||||
## Download
|
||||
|
||||
- [Github Release](https://github.com/alibaba/nacos/releases)
|
||||
- [Baidu Netdisk](https://pan.baidu.com/s/1186nmlqPGows9gUZKAx8Zw) Fetch Code : `rest`
|
||||
|
||||
- [Nacos Official Website](https://nacos.io/download/nacos-server)
|
||||
- [GitHub Release](https://github.com/alibaba/nacos/releases)
|
||||
|
||||
## Who is using
|
||||
|
||||
These are only part of the companies using Nacos, for reference only. If you are using Nacos, please [add your company here](https://github.com/alibaba/nacos/issues/273) to tell us your scenario to make Nacos better.
|
||||
|
@ -41,8 +41,8 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -96,7 +96,7 @@ public class AddressServerGeneratorManager {
|
||||
/**
|
||||
* Generate response ips.
|
||||
*
|
||||
* @param instanceList a instance set will generate string response to client.
|
||||
* @param instanceList an instance set will generate string response to client.
|
||||
* @return the result of response to client
|
||||
*/
|
||||
public String generateResponseIps(List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList) {
|
||||
@ -113,7 +113,7 @@ public class AddressServerGeneratorManager {
|
||||
/**
|
||||
* Generate nacos service name.
|
||||
*
|
||||
* @param rawServiceName the raw service name will not contains the {@link Constants#DEFAULT_GROUP}.
|
||||
* @param rawServiceName the raw service name will not contain the {@link Constants#DEFAULT_GROUP}.
|
||||
* @return the nacos service name
|
||||
*/
|
||||
public String generateNacosServiceName(String rawServiceName) {
|
||||
|
@ -16,22 +16,26 @@
|
||||
|
||||
package com.alibaba.nacos.address.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
/**
|
||||
* nacos web security configuration.
|
||||
*
|
||||
* @author onewe
|
||||
*/
|
||||
@Configuration
|
||||
@Order(99)
|
||||
public class AddressServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
public class AddressServerSecurityConfiguration {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests(requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated())
|
||||
.csrf().disable().httpBasic();
|
||||
@Bean
|
||||
@Order(99)
|
||||
public SecurityFilterChain addressServerSecurityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests(
|
||||
requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated()).csrf()
|
||||
.disable().httpBasic();
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
|
@ -18,55 +18,59 @@ package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddressServerGeneratorManagerTest {
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class AddressServerGeneratorManagerTest {
|
||||
|
||||
@Test
|
||||
public void testGenerateProductName() {
|
||||
void testGenerateProductName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final String blankName = manager.generateProductName("");
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||
|
||||
final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||
|
||||
final String testName = manager.generateProductName("test");
|
||||
Assert.assertEquals("nacos.as.test", testName);
|
||||
assertEquals("nacos.as.test", testName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateInstancesByIps() {
|
||||
void testGenerateInstancesByIps() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
|
||||
Assert.assertNotNull(empty);
|
||||
Assert.assertTrue(empty.isEmpty());
|
||||
assertNotNull(empty);
|
||||
assertTrue(empty.isEmpty());
|
||||
|
||||
String[] ipArray = new String[]{"192.168.3.1:8848", "192.168.3.2:8848", "192.168.3.3:8848"};
|
||||
final List<Instance> instanceList = manager.generateInstancesByIps("DEFAULT_GROUP@@nacos.as.test", "test", "test",
|
||||
ipArray);
|
||||
Assert.assertNotNull(instanceList);
|
||||
Assert.assertFalse(instanceList.isEmpty());
|
||||
Assert.assertEquals(3, instanceList.size());
|
||||
assertNotNull(instanceList);
|
||||
assertFalse(instanceList.isEmpty());
|
||||
assertEquals(3, instanceList.size());
|
||||
|
||||
final Instance instance1 = instanceList.get(0);
|
||||
Assert.assertEquals("192.168.3.1", instance1.getIp());
|
||||
assertEquals("192.168.3.1", instance1.getIp());
|
||||
|
||||
final Instance instance2 = instanceList.get(1);
|
||||
Assert.assertEquals("192.168.3.2", instance2.getIp());
|
||||
assertEquals("192.168.3.2", instance2.getIp());
|
||||
|
||||
final Instance instance3 = instanceList.get(2);
|
||||
Assert.assertEquals("192.168.3.3", instance3.getIp());
|
||||
assertEquals("192.168.3.3", instance3.getIp());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateResponseIps() {
|
||||
void testGenerateResponseIps() {
|
||||
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
|
||||
Instance instance1 = new Instance();
|
||||
instance1.setIp("192.168.3.1");
|
||||
@ -92,19 +96,19 @@ public class AddressServerGeneratorManagerTest {
|
||||
.append("192.168.3.1:8848").append('\n')
|
||||
.append("192.168.3.2:8848").append('\n')
|
||||
.append("192.168.3.3:8848").append('\n');
|
||||
Assert.assertEquals(ret.toString(), ipListStr);
|
||||
assertEquals(ret.toString(), ipListStr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerateNacosServiceName() {
|
||||
void testGenerateNacosServiceName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
|
||||
final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
|
||||
Assert.assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||
assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||
|
||||
final String product = manager.generateNacosServiceName("product");
|
||||
Assert.assertEquals("DEFAULT_GROUP@@product", product);
|
||||
assertEquals("DEFAULT_GROUP@@product", product);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,38 +17,38 @@
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AddressServerManagerTests {
|
||||
class AddressServerManagerTests {
|
||||
|
||||
private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();
|
||||
|
||||
|
||||
@Test
|
||||
public void getRawProductName() {
|
||||
void getRawProductName() {
|
||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT, ADDRESS_SERVER_MANAGER.getRawProductName(""));
|
||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT,
|
||||
ADDRESS_SERVER_MANAGER.getRawProductName(AddressServerConstants.DEFAULT_PRODUCT));
|
||||
assertEquals("otherProduct", ADDRESS_SERVER_MANAGER.getRawProductName("otherProduct"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getDefaultClusterNameIfEmpty() {
|
||||
void getDefaultClusterNameIfEmpty() {
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(""));
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER,
|
||||
ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(AddressServerConstants.DEFAULT_GET_CLUSTER));
|
||||
assertEquals("otherServerList", ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty("otherServerList"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetRawClusterName() {
|
||||
void testGetRawClusterName() {
|
||||
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSplitIps() {
|
||||
void testSplitIps() {
|
||||
final String[] emptyArr = ADDRESS_SERVER_MANAGER.splitIps("");
|
||||
assertEquals(0, emptyArr.length);
|
||||
final String[] one = ADDRESS_SERVER_MANAGER.splitIps("192.168.1.12:8848");
|
||||
|
@ -26,13 +26,13 @@ import com.alibaba.nacos.naming.core.InstanceOperator;
|
||||
import com.alibaba.nacos.naming.core.v2.ServiceManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
@ -40,8 +40,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AddressServerClusterControllerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AddressServerClusterControllerTest {
|
||||
|
||||
@Mock
|
||||
private InstanceOperator instanceOperator;
|
||||
@ -53,9 +53,9 @@ public class AddressServerClusterControllerTest {
|
||||
private ClusterOperator clusterOperator;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(
|
||||
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
|
||||
new AddressServerManager(), new AddressServerGeneratorManager())).build();
|
||||
@ -63,30 +63,30 @@ public class AddressServerClusterControllerTest {
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().getSingleton(service);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPostCluster() throws Exception {
|
||||
void testPostCluster() throws Exception {
|
||||
|
||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPostClusterWithErrorIps() throws Exception {
|
||||
void testPostClusterWithErrorIps() throws Exception {
|
||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPostClusterThrowException() throws Exception {
|
||||
void testPostClusterThrowException() throws Exception {
|
||||
|
||||
Mockito.doThrow(new NacosException(500, "create service error")).when(clusterOperator)
|
||||
.updateClusterMetadata(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||
@ -97,34 +97,34 @@ public class AddressServerClusterControllerTest {
|
||||
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteCluster() throws Exception {
|
||||
void testDeleteCluster() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterCannotFindService() throws Exception {
|
||||
void testDeleteClusterCannotFindService() throws Exception {
|
||||
tearDown();
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterEmptyIps() throws Exception {
|
||||
void testDeleteClusterEmptyIps() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterErrorIps() throws Exception {
|
||||
void testDeleteClusterErrorIps() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteClusterThrowException() throws Exception {
|
||||
void testDeleteClusterThrowException() throws Exception {
|
||||
Mockito.doThrow(new NacosException(500, "remove service error")).when(instanceOperator)
|
||||
.removeInstance(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||
Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + "nacos.as.default"),
|
||||
|
@ -26,12 +26,12 @@ import com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
@ -43,8 +43,8 @@ import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServerListControllerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ServerListControllerTest {
|
||||
|
||||
@Mock
|
||||
private NamingMetadataManager metadataManager;
|
||||
@ -55,23 +55,23 @@ public class ServerListControllerTest {
|
||||
private Service service;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(
|
||||
new ServerListController(new AddressServerGeneratorManager(), metadataManager, serviceStorage)).build();
|
||||
service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().getSingleton(service);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCluster() throws Exception {
|
||||
void testGetCluster() throws Exception {
|
||||
|
||||
final Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
@ -86,16 +86,16 @@ public class ServerListControllerTest {
|
||||
when(serviceStorage.getData(service)).thenReturn(serviceInfo);
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetClusterCannotFindService() throws Exception {
|
||||
void testGetClusterCannotFindService() throws Exception {
|
||||
tearDown();
|
||||
mockMvc.perform(get("/default/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetClusterCannotFindCluster() throws Exception {
|
||||
void testGetClusterCannotFindCluster() throws Exception {
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
@ -63,11 +63,6 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
@ -85,6 +80,10 @@
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api.grpc</groupId>
|
||||
<artifactId>proto-google-common-protos</artifactId>
|
||||
|
@ -33,6 +33,10 @@ public class PropertyKeyConst {
|
||||
|
||||
public static final String ENDPOINT_PORT = "endpointPort";
|
||||
|
||||
public static final String ENDPOINT_CONTEXT_PATH = "endpointContextPath";
|
||||
|
||||
public static final String ENDPOINT_CLUSTER_NAME = "endpointClusterName";
|
||||
|
||||
public static final String SERVER_NAME = "serverName";
|
||||
|
||||
public static final String NAMESPACE = "namespace";
|
||||
@ -59,6 +63,10 @@ public class PropertyKeyConst {
|
||||
|
||||
public static final String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
public static final String CLIENT_WORKER_MAX_THREAD_COUNT = "clientWorkerMaxThreadCount";
|
||||
|
||||
public static final String CLIENT_WORKER_THREAD_COUNT = "clientWorkerThreadCount";
|
||||
|
||||
public static final String MAX_RETRY = "maxRetry";
|
||||
|
||||
public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
@ -69,6 +77,8 @@ public class PropertyKeyConst {
|
||||
|
||||
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_MAX_THREAD_COUNT = "namingPollingMaxThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";
|
||||
@ -81,6 +91,15 @@ public class PropertyKeyConst {
|
||||
|
||||
public static final String REDO_DELAY_THREAD_COUNT = "redoDelayThreadCount";
|
||||
|
||||
public static final String SIGNATURE_REGION_ID = "signatureRegionId";
|
||||
|
||||
public static final String LOG_ALL_PROPERTIES = "logAllProperties";
|
||||
|
||||
/**
|
||||
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
|
||||
*/
|
||||
public static final String IS_USE_RAM_INFO_PARSING = "isUseRamInfoParsing";
|
||||
|
||||
/**
|
||||
* Get the key value of some variable value from the system property.
|
||||
*/
|
||||
@ -88,6 +107,8 @@ public class PropertyKeyConst {
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_CONTEXT_PATH = "ALIBABA_ALIWARE_ENDPOINT_CONTEXT_PATH";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_NAMESPACE = "ALIBABA_ALIWARE_NAMESPACE";
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||
|
@ -46,4 +46,9 @@ public interface SystemPropertyKeyConst {
|
||||
* It is also supported by the -D parameter.
|
||||
*/
|
||||
String IS_USE_ENDPOINT_PARSING_RULE = "nacos.use.endpoint.parsing.rule";
|
||||
|
||||
/**
|
||||
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
|
||||
*/
|
||||
String IS_USE_RAM_INFO_PARSING = "nacos.use.ram.info.parsing";
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ public class Constants {
|
||||
|
||||
public static final String APPNAME = "AppName";
|
||||
|
||||
public static final String CLIENT_VERSION_KEY = "ClientVersion";
|
||||
|
||||
public static final String UNKNOWN_APP = "UnknownApp";
|
||||
|
||||
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
|
||||
@ -41,10 +43,14 @@ public class Constants {
|
||||
|
||||
public static final String NULL = "";
|
||||
|
||||
public static final String DATAID = "dataId";
|
||||
|
||||
public static final String DATA_ID = "dataId";
|
||||
|
||||
public static final String TENANT = "tenant";
|
||||
|
||||
public static final String GROUP = "group";
|
||||
|
||||
|
||||
public static final String NAMESPACE_ID = "namespaceId";
|
||||
|
||||
public static final String LAST_MODIFIED = "Last-Modified";
|
||||
|
||||
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
||||
@ -223,6 +229,29 @@ public class Constants {
|
||||
|
||||
public static final int DEFAULT_REDO_THREAD_COUNT = 1;
|
||||
|
||||
public static final String APP_CONN_LABELS_KEY = "nacos.app.conn.labels";
|
||||
|
||||
public static final String DOT = ".";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
|
||||
public static final String PROPERTIES_KEY = "properties";
|
||||
|
||||
public static final String JVM_KEY = "jvm";
|
||||
|
||||
public static final String ENV_KEY = "env";
|
||||
|
||||
public static final String APP_CONN_LABELS_PREFERRED = "nacos_app_conn_labels_preferred";
|
||||
|
||||
public static final String APP_CONN_PREFIX = "app_";
|
||||
|
||||
public static final String CONFIG_GRAY_LABEL = "nacos.config.gray.label";
|
||||
|
||||
/**
|
||||
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
|
||||
*/
|
||||
public static final String DEFAULT_USE_RAM_INFO_PARSING = "true";
|
||||
|
||||
/**
|
||||
* The constants in config directory.
|
||||
*/
|
||||
@ -237,9 +266,9 @@ public class Constants {
|
||||
* The constants in naming directory.
|
||||
*/
|
||||
public static class Naming {
|
||||
|
||||
|
||||
public static final String NAMING_MODULE = "naming";
|
||||
|
||||
|
||||
public static final String CMDB_CONTEXT_TYPE = "CMDB";
|
||||
}
|
||||
|
||||
@ -247,7 +276,7 @@ public class Constants {
|
||||
* The constants in remote directory.
|
||||
*/
|
||||
public static class Remote {
|
||||
|
||||
|
||||
public static final String INTERNAL_MODULE = "internal";
|
||||
}
|
||||
|
||||
@ -259,9 +288,9 @@ public class Constants {
|
||||
public static final int SERIALIZE_ERROR_CODE = 100;
|
||||
|
||||
public static final int DESERIALIZE_ERROR_CODE = 101;
|
||||
|
||||
|
||||
public static final int FIND_DATASOURCE_ERROR_CODE = 102;
|
||||
|
||||
|
||||
public static final int FIND_TABLE_ERROR_CODE = 103;
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public enum ErrorCode {
|
||||
/**
|
||||
* node down failure.
|
||||
*/
|
||||
NODE_DOWN_FAILURE(23001, "node down failure"),
|
||||
NODE_DOWN_FAILURE(23002, "node down failure"),
|
||||
|
||||
/**
|
||||
* server error.
|
||||
|
@ -21,6 +21,7 @@ import com.alibaba.nacos.api.naming.listener.EventListener;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||
import com.alibaba.nacos.api.naming.selector.NamingSelector;
|
||||
import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||
|
||||
import java.util.List;
|
||||
@ -33,7 +34,7 @@ import java.util.List;
|
||||
public interface NamingService {
|
||||
|
||||
/**
|
||||
* register a instance to service.
|
||||
* register an instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
@ -43,7 +44,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String ip, int port) throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service.
|
||||
* register an instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -54,7 +55,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service with specified cluster name.
|
||||
* register an instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
@ -65,7 +66,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service with specified cluster name.
|
||||
* register an instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -78,7 +79,7 @@ public interface NamingService {
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service with specified instance properties.
|
||||
* register an instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param instance instance to register
|
||||
@ -87,7 +88,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, Instance instance) throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service with specified instance properties.
|
||||
* register an instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -491,6 +492,28 @@ public interface NamingService {
|
||||
void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param selector selector of instances
|
||||
* @param listener event listener
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, NamingSelector selector, EventListener listener) throws NacosException;
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param selector selector of instances
|
||||
* @param listener event listener
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, String groupName, NamingSelector selector, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
@ -532,6 +555,28 @@ public interface NamingService {
|
||||
void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param selector selector of instances
|
||||
* @param listener event listener
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, NamingSelector selector, EventListener listener) throws NacosException;
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param selector selector of instances
|
||||
* @param listener event listener
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, String groupName, NamingSelector selector, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get all service names from server.
|
||||
*
|
||||
|
@ -69,7 +69,7 @@ public class HealthCheckerFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize and create a instance of health checker.
|
||||
* Deserialize and create an instance of health checker.
|
||||
*
|
||||
* @param jsonString json string of health checker
|
||||
* @return new instance
|
||||
@ -83,7 +83,7 @@ public class HealthCheckerFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a instance of health checker to json.
|
||||
* Serialize an instance of health checker to json.
|
||||
*
|
||||
* @param healthChecker health checker instance
|
||||
* @return son string after serializing
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.api.naming.selector;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Naming selector context.
|
||||
*
|
||||
* @author lideyou
|
||||
*/
|
||||
public interface NamingContext {
|
||||
|
||||
/**
|
||||
* Get service name.
|
||||
*
|
||||
* @return service name
|
||||
*/
|
||||
String getServiceName();
|
||||
|
||||
/**
|
||||
* Get group name.
|
||||
*
|
||||
* @return group name
|
||||
*/
|
||||
String getGroupName();
|
||||
|
||||
/**
|
||||
* Get clusters.
|
||||
*
|
||||
* @return clusters
|
||||
*/
|
||||
String getClusters();
|
||||
|
||||
/**
|
||||
* Get current instances.
|
||||
*
|
||||
* @return current instances
|
||||
*/
|
||||
List<Instance> getInstances();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.api.naming.selector;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.selector.client.SelectResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Naming select result.
|
||||
*
|
||||
* @author lideyou
|
||||
*/
|
||||
public interface NamingResult extends SelectResult<List<Instance>> {
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.api.naming.selector;
|
||||
|
||||
import com.alibaba.nacos.api.selector.client.Selector;
|
||||
|
||||
/**
|
||||
* Naming selector.
|
||||
*
|
||||
* @author lideyou
|
||||
*/
|
||||
public interface NamingSelector extends Selector<NamingContext, NamingResult> {
|
||||
|
||||
}
|
@ -16,17 +16,27 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.spi.generator;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
|
||||
/**
|
||||
* Generator SPI for Instance Id.
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public interface IdGenerator {
|
||||
public interface InstanceIdGenerator {
|
||||
|
||||
/**
|
||||
* Generate instance id.
|
||||
*
|
||||
* @param instance instance
|
||||
* @return instance id
|
||||
*/
|
||||
String generateInstanceId();
|
||||
String generateInstanceId(Instance instance);
|
||||
|
||||
/**
|
||||
* Generator type.
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
String type();
|
||||
}
|
@ -87,6 +87,16 @@ public class NamingUtils {
|
||||
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check serviceName is compatibility mode or not.
|
||||
*
|
||||
* @param serviceName serviceName
|
||||
* @return if serviceName is compatibility mode, return true
|
||||
*/
|
||||
public static boolean isServiceNameCompatibilityMode(final String serviceName) {
|
||||
return !StringUtils.isBlank(serviceName) && serviceName.contains(Constants.SERVICE_INFO_SPLITER);
|
||||
}
|
||||
|
||||
/**
|
||||
* check combineServiceName format. the serviceName can't be blank.
|
||||
* <pre>
|
||||
|
@ -57,6 +57,7 @@ public class ErrorResponse extends Response {
|
||||
}
|
||||
ErrorResponse response = new ErrorResponse();
|
||||
response.setErrorInfo(errorCode, exception.getMessage());
|
||||
response.setResultCode(errorCode);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2022 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,19 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.common.log;
|
||||
package com.alibaba.nacos.api.selector.client;
|
||||
|
||||
/**
|
||||
* nacos logback properties.
|
||||
* @author hujun
|
||||
* Select result.
|
||||
*
|
||||
* @param <T> the type of result
|
||||
* @author lideyou
|
||||
*/
|
||||
public interface NacosLogbackProperties {
|
||||
public interface SelectResult<T> {
|
||||
|
||||
/**
|
||||
* get value.
|
||||
* Get select result.
|
||||
*
|
||||
* @param source source
|
||||
* @param defaultValue defaultValue
|
||||
* @return value
|
||||
* @return select result
|
||||
*/
|
||||
String getValue(String source, String defaultValue);
|
||||
T getResult();
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.api.selector.client;
|
||||
|
||||
/**
|
||||
* Client selector.
|
||||
*
|
||||
* @param <C> the type of selector context
|
||||
* @param <E> the type of select result
|
||||
* @author lideyou
|
||||
*/
|
||||
public interface Selector<C, E> {
|
||||
|
||||
/**
|
||||
* select the target result.
|
||||
*
|
||||
* @param context selector context
|
||||
* @return select result
|
||||
*/
|
||||
E select(C context);
|
||||
}
|
@ -20,25 +20,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClientAbilitiesTest {
|
||||
class ClientAbilitiesTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
ClientAbilities abilities = new ClientAbilities();
|
||||
String json = mapper.writeValueAsString(abilities);
|
||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||
@ -47,7 +47,7 @@ public class ClientAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||
+ "\"supportRemoteMetric\":false}}";
|
||||
|
@ -20,35 +20,35 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServerAbilitiesTest {
|
||||
class ServerAbilitiesTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
private ServerAbilities serverAbilities;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUpBeforeClass() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
serverAbilities = new ServerAbilities();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
serverAbilities = new ServerAbilities();
|
||||
String json = mapper.writeValueAsString(serverAbilities);
|
||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||
@ -57,7 +57,7 @@ public class ServerAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||
+ "\"supportRemoteMetric\":false}}";
|
||||
@ -68,10 +68,10 @@ public class ServerAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
void testEqualsAndHashCode() {
|
||||
assertEquals(serverAbilities, serverAbilities);
|
||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||
assertNotEquals(serverAbilities, null);
|
||||
assertNotEquals(null, serverAbilities);
|
||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||
ServerAbilities test = new ServerAbilities();
|
||||
assertEquals(serverAbilities, test);
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClusterClientAbilitiesTest {
|
||||
class ClusterClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testGetStaticAbilities() {
|
||||
void testGetStaticAbilities() {
|
||||
// TODO add the cluster client abilities.
|
||||
assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty());
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SdkClientAbilitiesTest {
|
||||
class SdkClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testGetStaticAbilities() {
|
||||
void testGetStaticAbilities() {
|
||||
// TODO add the sdk client abilities.
|
||||
assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty());
|
||||
}
|
||||
|
@ -17,20 +17,20 @@
|
||||
package com.alibaba.nacos.api.ability.register.impl;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServerAbilitiesTest {
|
||||
class ServerAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testGetStaticAbilities() {
|
||||
void testGetStaticAbilities() {
|
||||
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSupportPersistentInstanceByGrpcAbilities() {
|
||||
void testSupportPersistentInstanceByGrpcAbilities() {
|
||||
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||
}
|
||||
}
|
@ -16,8 +16,7 @@
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
||||
@ -28,23 +27,24 @@ import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOL
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class NacosPropertiesTest {
|
||||
class NacosPropertiesTest {
|
||||
|
||||
@Test
|
||||
public void testPlaceholders() {
|
||||
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
||||
void testPlaceholders() {
|
||||
assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
||||
assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
||||
assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
||||
assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
||||
assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
||||
assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
||||
assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
||||
assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolvePlaceholders() {
|
||||
void testResolvePlaceholders() {
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
@ -75,11 +75,11 @@ public class NacosPropertiesTest {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty(propertyName, propertyValue);
|
||||
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
||||
Assert.assertEquals(expectValue, resolvedValue);
|
||||
assertEquals(expectValue, resolvedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort() {
|
||||
void testSort() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class EntityEventTest {
|
||||
class EntityEventTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
EntityEvent entity = new EntityEvent();
|
||||
entity.setEntityName("test-entity");
|
||||
entity.setEntityType("CMDB");
|
||||
@ -50,7 +50,7 @@ public class EntityEventTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
||||
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
||||
assertEquals("test-entity", entity.getEntityName());
|
||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class EntityTest {
|
||||
class EntityTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
Entity entity = new Entity();
|
||||
entity.setName("test-entity");
|
||||
entity.setType(PreservedEntityTypes.ip.name());
|
||||
@ -51,7 +51,7 @@ public class EntityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
||||
Entity entity = mapper.readValue(json, Entity.class);
|
||||
assertEquals("test-entity", entity.getName());
|
||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class LabelTest {
|
||||
class LabelTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
Label label = new Label();
|
||||
label.setName("test-label");
|
||||
label.setDescription("CMDB description");
|
||||
@ -52,7 +52,7 @@ public class LabelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
||||
Label label = mapper.readValue(json, Label.class);
|
||||
assertEquals("test-label", label.getName());
|
||||
|
@ -16,18 +16,18 @@
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ConfigChangeEventTest {
|
||||
class ConfigChangeEventTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
void testConstructor() {
|
||||
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
||||
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
||||
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
||||
|
@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ConfigChangeItemTest {
|
||||
class ConfigChangeItemTest {
|
||||
|
||||
@Test
|
||||
public void testSetNewValue() {
|
||||
void testSetNewValue() {
|
||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||
item.setType(PropertyChangeType.ADDED);
|
||||
assertEquals("testKey", item.getKey());
|
||||
@ -46,7 +46,7 @@ public class ConfigChangeItemTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||
item.setType(PropertyChangeType.ADDED);
|
||||
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
||||
|
@ -16,16 +16,16 @@
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigTypeTest {
|
||||
class ConfigTypeTest {
|
||||
|
||||
@Test
|
||||
public void isValidType() {
|
||||
void isValidType() {
|
||||
assertTrue(ConfigType.isValidType("xml"));
|
||||
assertTrue(ConfigType.isValidType("properties"));
|
||||
assertTrue(ConfigType.isValidType("json"));
|
||||
@ -38,7 +38,7 @@ public class ConfigTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultType() {
|
||||
void testGetDefaultType() {
|
||||
assertEquals("text", ConfigType.getDefaultType().getType());
|
||||
}
|
||||
}
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClientRemoteAbilityTest {
|
||||
class ClientRemoteAbilityTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
||||
String json = mapper.writeValueAsString(abilities);
|
||||
assertEquals("{\"supportRemoteConnection\":false}", json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"supportRemoteConnection\":true}";
|
||||
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
||||
assertTrue(abilities.isSupportRemoteConnection());
|
||||
|
@ -16,21 +16,20 @@
|
||||
|
||||
package com.alibaba.nacos.api.config.ability;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class ServerConfigAbilityTest {
|
||||
class ServerConfigAbilityTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
void testEquals() {
|
||||
ServerConfigAbility ability = new ServerConfigAbility();
|
||||
ability.setSupportRemoteMetrics(true);
|
||||
assertEquals(ability, ability);
|
||||
assertFalse(ability.equals(null));
|
||||
assertFalse(ability.equals(new ClientConfigAbility()));
|
||||
assertNotEquals(null, ability);
|
||||
assertNotEquals(ability, new ClientConfigAbility());
|
||||
ServerConfigAbility newOne = new ServerConfigAbility();
|
||||
assertNotEquals(ability, newOne);
|
||||
newOne.setSupportRemoteMetrics(true);
|
||||
|
@ -23,35 +23,35 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServerRemoteAbilityTest {
|
||||
class ServerRemoteAbilityTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
private ServerRemoteAbility serverAbilities;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUpBeforeClass() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
serverAbilities = new ServerRemoteAbility();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
serverAbilities = new ServerRemoteAbility();
|
||||
String json = mapper.writeValueAsString(serverAbilities);
|
||||
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
||||
@ -59,7 +59,7 @@ public class ServerRemoteAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
||||
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
||||
assertTrue(abilities.isSupportRemoteConnection());
|
||||
@ -67,10 +67,10 @@ public class ServerRemoteAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
void testEqualsAndHashCode() {
|
||||
assertEquals(serverAbilities, serverAbilities);
|
||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||
assertNotEquals(serverAbilities, null);
|
||||
assertNotEquals(null, serverAbilities);
|
||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||
ServerRemoteAbility test = new ServerRemoteAbility();
|
||||
assertEquals(serverAbilities, test);
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class AbstractListenerTest {
|
||||
class AbstractListenerTest {
|
||||
|
||||
@Test
|
||||
public void testGetExecutor() {
|
||||
void testGetExecutor() {
|
||||
// Default listener executor is null.
|
||||
assertNull(new AbstractListener() {
|
||||
@Override
|
||||
|
@ -16,28 +16,28 @@
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class AbstractSharedListenerTest {
|
||||
class AbstractSharedListenerTest {
|
||||
|
||||
private static final String CONFIG_CONTENT = "test";
|
||||
|
||||
private static Map<String, String> receivedMap;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
receivedMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillContext() {
|
||||
void testFillContext() {
|
||||
assertEquals(0, receivedMap.size());
|
||||
MockShardListener listener = new MockShardListener();
|
||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||
@ -52,7 +52,7 @@ public class AbstractSharedListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExecutor() {
|
||||
void getExecutor() {
|
||||
// Default listener executor is null.
|
||||
assertNull(new MockShardListener().getExecutor());
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -30,8 +30,6 @@ import java.util.UUID;
|
||||
|
||||
public abstract class BasedConfigRequestTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
protected static final String DATA_ID = "test_data";
|
||||
|
||||
protected static final String GROUP = "group";
|
||||
@ -52,11 +50,13 @@ public abstract class BasedConfigRequestTest {
|
||||
|
||||
protected static final String CONTENT = "content";
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
@ -18,18 +18,17 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.CACHE_DATA;
|
||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@ -57,35 +56,36 @@ public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
||||
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
||||
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
||||
assertEquals(actual.getMetricsKeys().size(), 2);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
assertEquals(2, actual.getMetricsKeys().size());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsKeysEquals() {
|
||||
void testMetricsKeysEquals() {
|
||||
String dataKey = String.join("+", KEY);
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||
assertEquals(key, key);
|
||||
assertFalse(key.equals(null));
|
||||
assertFalse(key.equals(new ClientConfigMetricRequest()));
|
||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey
|
||||
.build(SNAPSHOT_DATA, dataKey);
|
||||
assertNotEquals(null, key);
|
||||
assertNotEquals(key, new ClientConfigMetricRequest());
|
||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA,
|
||||
dataKey);
|
||||
assertNotEquals(key, newOne);
|
||||
newOne.setType(CACHE_DATA);
|
||||
assertEquals(key, newOne);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsHashCode() {
|
||||
void testMetricsHashCode() {
|
||||
String dataKey = String.join("+", KEY);
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsToString() {
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY));
|
||||
void testMetricsToString() {
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA,
|
||||
String.join("+", KEY));
|
||||
assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString());
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@ -47,14 +47,14 @@ public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
||||
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
||||
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
||||
assertEquals(actual.isListen(), true);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
assertEquals(actual.getConfigListenContexts().size(), 1);
|
||||
assertEquals(true, actual.isListen());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||
assertEquals(1, actual.getConfigListenContexts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigListenContextToString() {
|
||||
void testConfigListenContextToString() {
|
||||
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
||||
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
||||
assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}",
|
||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
||||
configChangeNotifyRequest.putAllHeader(HEADERS);
|
||||
requestId = injectRequestUuId(configChangeNotifyRequest);
|
||||
@ -54,10 +54,10 @@ public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
||||
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
||||
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
assertEquals(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||
}
|
||||
}
|
||||
|
@ -18,24 +18,24 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigPublishRequest configPublishRequest;
|
||||
class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
private static final String TAG_PARAM = "tag";
|
||||
|
||||
private static final String APP_NAME_PARAM = "appName";
|
||||
|
||||
ConfigPublishRequest configPublishRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
||||
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
||||
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
||||
@ -64,13 +64,13 @@ public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
||||
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
||||
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getContent(), CONTENT);
|
||||
assertEquals(actual.getCasMd5(), MD5);
|
||||
assertEquals(actual.getAdditionParam(TAG_PARAM), TAG_PARAM);
|
||||
assertEquals(actual.getAdditionParam(APP_NAME_PARAM), APP_NAME_PARAM);
|
||||
assertEquals(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(CONTENT, actual.getContent());
|
||||
assertEquals(MD5, actual.getCasMd5());
|
||||
assertEquals(TAG_PARAM, actual.getAdditionParam(TAG_PARAM));
|
||||
assertEquals(APP_NAME_PARAM, actual.getAdditionParam(APP_NAME_PARAM));
|
||||
}
|
||||
}
|
||||
|
@ -18,16 +18,16 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigQueryRequest configQueryRequest;
|
||||
|
||||
@ -35,8 +35,8 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
||||
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
||||
configQueryRequest.putAllHeader(headers);
|
||||
@ -45,7 +45,7 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotify() {
|
||||
void testIsNotify() {
|
||||
assertTrue(configQueryRequest.isNotify());
|
||||
}
|
||||
|
||||
@ -67,10 +67,10 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
||||
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
||||
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(TAG, actual.getTag());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
}
|
||||
}
|
||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigRemoveRequest configRemoveRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
||||
requestId = injectRequestUuId(configRemoveRequest);
|
||||
|
||||
@ -56,10 +56,10 @@ public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
||||
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
||||
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
assertEquals(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(TAG, actual.getTag());
|
||||
}
|
||||
}
|
||||
|
@ -19,20 +19,20 @@ package com.alibaba.nacos.api.config.remote.request.cluster;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
||||
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
||||
configChangeClusterSyncRequest.setGroup(GROUP);
|
||||
@ -64,15 +64,16 @@ public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
||||
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
||||
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
||||
String json =
|
||||
"{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
||||
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
||||
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
||||
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getLastModified(), 0L);
|
||||
assertEquals(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(0L, actual.getLastModified());
|
||||
assertTrue(actual.isBeta());
|
||||
}
|
||||
}
|
||||
|
@ -18,14 +18,14 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
@ -33,8 +33,8 @@ public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
Map<String, Object> metric = new HashMap<>(16);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
metric.put("m1", "v1");
|
||||
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
||||
clientConfigMetricResponse.setMetrics(metric);
|
||||
|
@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||
class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
||||
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
||||
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
||||
@ -50,8 +50,8 @@ public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse
|
||||
.buildFailResponse("Fail");
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse.buildFailResponse(
|
||||
"Fail");
|
||||
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
||||
requestId = injectResponseUuId(configChangeNotifyResponse);
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||
class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigPublishResponse configPublishResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
||||
requestId = injectResponseUuId(configPublishResponse);
|
||||
}
|
||||
|
@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||
class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigQueryResponse configQueryResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
||||
configQueryResponse.setContentType("text");
|
||||
configQueryResponse.setEncryptedDataKey("encryptedKey");
|
||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||
class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigRemoveResponse configRemoveResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
||||
requestId = injectResponseUuId(configRemoveResponse);
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.config.remote.response.cluster;
|
||||
import com.alibaba.nacos.api.config.remote.response.BasedConfigResponseTest;
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
||||
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
||||
}
|
||||
|
@ -17,14 +17,14 @@
|
||||
package com.alibaba.nacos.api.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class NacosExceptionTest {
|
||||
class NacosExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
void testEmptyConstructor() {
|
||||
NacosException exception = new NacosException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||
@ -35,7 +35,7 @@ public class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrMsg() {
|
||||
void testConstructorWithErrMsg() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
@ -43,7 +43,7 @@ public class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
void testConstructorWithCause() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("cause test", exception.getErrMsg());
|
||||
@ -51,7 +51,7 @@ public class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithMultiCauses() {
|
||||
void testConstructorWithMultiCauses() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
||||
new RuntimeException("cause test", new RuntimeException("multi")));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
@ -60,7 +60,7 @@ public class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithFull() {
|
||||
void testConstructorWithFull() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
||||
new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
|
@ -18,14 +18,14 @@ package com.alibaba.nacos.api.exception.api;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class NacosApiExceptionTest {
|
||||
class NacosApiExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
void testEmptyConstructor() {
|
||||
NacosApiException exception = new NacosApiException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(0, exception.getDetailErrCode());
|
||||
@ -34,7 +34,7 @@ public class NacosApiExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithoutCause() {
|
||||
void testConstructorWithoutCause() {
|
||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
||||
assertEquals(500, exception.getErrCode());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
||||
@ -43,7 +43,7 @@ public class NacosApiExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
void testConstructorWithCause() {
|
||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
||||
new RuntimeException("cause test"), "test");
|
||||
assertEquals(500, exception.getErrCode());
|
||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class NacosDeserializationExceptionTest {
|
||||
class NacosDeserializationExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
void testEmptyConstructor() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException();
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -36,7 +36,7 @@ public class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetClass() {
|
||||
void testConstructorWithTargetClass() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class);
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
@ -46,7 +46,7 @@ public class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetType() {
|
||||
void testConstructorWithTargetType() {
|
||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||
NacosDeserializationException exception = new NacosDeserializationException(type);
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
@ -57,7 +57,7 @@ public class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
void testConstructorWithCause() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
||||
@ -65,7 +65,7 @@ public class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetClassAndCause() {
|
||||
void testConstructorWithTargetClassAndCause() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
@ -75,7 +75,7 @@ public class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetTypeAndCause() {
|
||||
void testConstructorWithTargetTypeAndCause() {
|
||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
|
@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class NacosLoadExceptionTest {
|
||||
class NacosLoadExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
void testConstructor() {
|
||||
NacosLoadException exception = new NacosLoadException("test");
|
||||
assertEquals("test", exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
|
@ -17,16 +17,16 @@
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NacosRuntimeExceptionTest {
|
||||
class NacosRuntimeExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCode() {
|
||||
void testConstructorWithErrorCode() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -34,7 +34,7 @@ public class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCodeAndMsg() {
|
||||
void testConstructorWithErrorCodeAndMsg() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||
@ -42,7 +42,7 @@ public class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCodeAndCause() {
|
||||
void testConstructorWithErrorCodeAndCause() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
@ -51,9 +51,9 @@ public class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithFull() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||
"test", new RuntimeException("cause test"));
|
||||
void testConstructorWithFull() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test",
|
||||
new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||
assertTrue(exception.getCause() instanceof RuntimeException);
|
||||
|
@ -17,15 +17,15 @@
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class NacosSerializationExceptionTest {
|
||||
class NacosSerializationExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
void testEmptyConstructor() {
|
||||
NacosSerializationException exception = new NacosSerializationException();
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -33,7 +33,7 @@ public class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithSerializedClass() {
|
||||
void testConstructorWithSerializedClass() {
|
||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
||||
@ -42,7 +42,7 @@ public class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
void testConstructorWithCause() {
|
||||
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
||||
@ -50,7 +50,7 @@ public class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithSerializedClassAndCause() {
|
||||
void testConstructorWithSerializedClassAndCause() {
|
||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2021 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.api.model.v2;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ErrorCodeTest {
|
||||
|
||||
@Test
|
||||
void testCodeNotSame() {
|
||||
Class<ErrorCode> errorCodeClass = ErrorCode.class;
|
||||
|
||||
ErrorCode[] errorCodes = errorCodeClass.getEnumConstants();
|
||||
Set<Integer> codeSet = new HashSet<Integer>(errorCodes.length);
|
||||
|
||||
for (ErrorCode errorCode : errorCodes) {
|
||||
codeSet.add(errorCode.getCode());
|
||||
}
|
||||
|
||||
assertEquals(errorCodes.length, codeSet.size());
|
||||
}
|
||||
}
|
@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.nacos.api.model.v2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ResultTest {
|
||||
class ResultTest {
|
||||
|
||||
@Test
|
||||
public void testSuccessEmptyResult() {
|
||||
void testSuccessEmptyResult() {
|
||||
Result<String> result = Result.success();
|
||||
assertNull(result.getData());
|
||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||
@ -32,7 +32,7 @@ public class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessWithData() {
|
||||
void testSuccessWithData() {
|
||||
Result<String> result = Result.success("test");
|
||||
assertEquals("test", result.getData());
|
||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||
@ -40,7 +40,7 @@ public class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureMessageResult() {
|
||||
void testFailureMessageResult() {
|
||||
Result<String> result = Result.failure("test");
|
||||
assertNull(result.getData());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
||||
@ -48,7 +48,7 @@ public class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureWithoutData() {
|
||||
void testFailureWithoutData() {
|
||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
|
||||
assertNull(result.getData());
|
||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||
@ -56,7 +56,7 @@ public class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureWithData() {
|
||||
void testFailureWithData() {
|
||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
|
||||
assertEquals("error", result.getData());
|
||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||
@ -64,7 +64,7 @@ public class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
Result<String> result = Result.success("test");
|
||||
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
|
||||
}
|
||||
|
@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.ability;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClientNamingAbilityTest {
|
||||
class ClientNamingAbilityTest {
|
||||
|
||||
@Test
|
||||
public void testGetAndSet() {
|
||||
void testGetAndSet() {
|
||||
ClientNamingAbility ability = new ClientNamingAbility();
|
||||
assertFalse(ability.isSupportDeltaPush());
|
||||
assertFalse(ability.isSupportRemoteMetric());
|
||||
|
@ -20,34 +20,33 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class ServerNamingAbilityTest {
|
||||
class ServerNamingAbilityTest {
|
||||
|
||||
private static ObjectMapper jacksonMapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUpClass() throws Exception {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||
void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||
String nonExistItemJson = "{\"exampleAbility\":false}";
|
||||
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
||||
assertFalse(actual.isSupportJraft());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws JsonProcessingException {
|
||||
void testEquals() throws JsonProcessingException {
|
||||
ServerNamingAbility expected = new ServerNamingAbility();
|
||||
expected.setSupportJraft(true);
|
||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||
@ -60,19 +59,19 @@ public class ServerNamingAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsForOneObject() {
|
||||
void testEqualsForOneObject() {
|
||||
ServerNamingAbility ability = new ServerNamingAbility();
|
||||
assertTrue(ability.equals(ability));
|
||||
assertEquals(ability, ability);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsForOtherAbility() {
|
||||
void testEqualsForOtherAbility() {
|
||||
ServerNamingAbility ability = new ServerNamingAbility();
|
||||
assertFalse(ability.equals(new ClientNamingAbility()));
|
||||
assertNotEquals(ability, new ClientNamingAbility());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() throws JsonProcessingException {
|
||||
void testHashCode() throws JsonProcessingException {
|
||||
ServerNamingAbility expected = new ServerNamingAbility();
|
||||
expected.setSupportJraft(true);
|
||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||
|
@ -16,26 +16,26 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.listener;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NamingEventTest {
|
||||
class NamingEventTest {
|
||||
|
||||
private MockNamingEventListener eventListener;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
eventListener = new MockNamingEventListener();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingEventWithSimpleConstructor() {
|
||||
void testNamingEventWithSimpleConstructor() {
|
||||
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
||||
assertEquals("serviceName", event.getServiceName());
|
||||
assertNull(event.getGroupName());
|
||||
@ -49,7 +49,7 @@ public class NamingEventTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingEventWithFullConstructor() {
|
||||
void testNamingEventWithFullConstructor() {
|
||||
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
|
||||
assertEquals("serviceName", event.getServiceName());
|
||||
assertEquals("group", event.getGroupName());
|
||||
|
@ -22,29 +22,29 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ClusterTest {
|
||||
class ClusterTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
void testSetAndGet() {
|
||||
Cluster actual = new Cluster();
|
||||
assertNull(actual.getName());
|
||||
assertNull(actual.getServiceName());
|
||||
@ -72,7 +72,7 @@ public class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonSerialize() throws JsonProcessingException {
|
||||
void testJsonSerialize() throws JsonProcessingException {
|
||||
Cluster actual = new Cluster("cluster");
|
||||
actual.setServiceName("group@@service");
|
||||
actual.setHealthChecker(new Http());
|
||||
@ -91,7 +91,7 @@ public class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonDeserialize() throws JsonProcessingException {
|
||||
void testJsonDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
|
||||
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
|
||||
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
|
||||
|
@ -22,30 +22,31 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class InstanceTest {
|
||||
class InstanceTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
void testSetAndGet() {
|
||||
Instance instance = new Instance();
|
||||
assertNull(instance.getInstanceId());
|
||||
assertNull(instance.getIp());
|
||||
@ -62,7 +63,7 @@ public class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonSerialize() throws JsonProcessingException {
|
||||
void testJsonSerialize() throws JsonProcessingException {
|
||||
Instance instance = new Instance();
|
||||
setInstance(instance);
|
||||
String actual = mapper.writeValueAsString(instance);
|
||||
@ -82,7 +83,7 @@ public class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonDeserialize() throws JsonProcessingException {
|
||||
void testJsonDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
|
||||
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
|
||||
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
|
||||
@ -92,21 +93,21 @@ public class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckClusterNameFormat() {
|
||||
void testCheckClusterNameFormat() {
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("demo");
|
||||
assertEquals("demo", instance.getClusterName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToInetAddr() {
|
||||
void testToInetAddr() {
|
||||
Instance instance = new Instance();
|
||||
setInstance(instance);
|
||||
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsMetadata() {
|
||||
void testContainsMetadata() {
|
||||
Instance instance = new Instance();
|
||||
assertFalse(instance.containsMetadata("a"));
|
||||
instance.setMetadata(null);
|
||||
@ -116,7 +117,7 @@ public class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstanceIdGenerator() {
|
||||
void testGetInstanceIdGenerator() {
|
||||
Instance instance = new Instance();
|
||||
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
||||
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
||||
@ -124,19 +125,19 @@ public class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
void testEquals() {
|
||||
Instance actual = new Instance();
|
||||
setInstance(actual);
|
||||
actual.setMetadata(new HashMap<>());
|
||||
actual.addMetadata("a", "b");
|
||||
assertFalse(actual.equals(new Object()));
|
||||
assertNotEquals(actual, new Object());
|
||||
Instance expected = new Instance();
|
||||
setInstance(expected);
|
||||
expected.setMetadata(new HashMap<>());
|
||||
expected.addMetadata("a", "b");
|
||||
assertTrue(actual.equals(expected));
|
||||
assertEquals(actual, expected);
|
||||
expected.addMetadata("a", "c");
|
||||
assertFalse(actual.equals(expected));
|
||||
assertNotEquals(actual, expected);
|
||||
}
|
||||
|
||||
private void setInstance(Instance instance) {
|
||||
|
@ -16,19 +16,19 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ListViewTest {
|
||||
class ListViewTest {
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
List<String> data = new LinkedList<>();
|
||||
data.add("1");
|
||||
data.add("2");
|
||||
@ -41,7 +41,7 @@ public class ListViewTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
void testSetAndGet() {
|
||||
ListView<String> listView = new ListView<>();
|
||||
assertEquals(0, listView.getCount());
|
||||
assertNull(listView.getData());
|
||||
|
@ -20,8 +20,8 @@ import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -30,25 +30,26 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServiceInfoTest {
|
||||
class ServiceInfoTest {
|
||||
|
||||
private ObjectMapper mapper;
|
||||
|
||||
private ServiceInfo serviceInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
String actual = mapper.writeValueAsString(serviceInfo);
|
||||
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
||||
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
||||
@ -64,7 +65,7 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
void testDeserialize() throws IOException {
|
||||
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
|
||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
||||
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
||||
@ -82,14 +83,14 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKey() {
|
||||
void testGetKey() {
|
||||
String key = serviceInfo.getKey();
|
||||
assertEquals("G@@testName@@testClusters", key);
|
||||
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKeyEncode() {
|
||||
void testGetKeyEncode() {
|
||||
String key = serviceInfo.getKeyEncoded();
|
||||
String encodeName = null;
|
||||
try {
|
||||
@ -101,7 +102,7 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceInfoConstructor() {
|
||||
void testServiceInfoConstructor() {
|
||||
String key1 = "group@@name";
|
||||
String key2 = "group@@name@@c2";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
@ -110,32 +111,34 @@ public class ServiceInfoTest {
|
||||
assertEquals(key2, s2.getKey());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testServiceInfoConstructorWithError() {
|
||||
String key1 = "name";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
@Test
|
||||
void testServiceInfoConstructorWithError() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String key1 = "name";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateForAllIps() {
|
||||
void testValidateForAllIps() {
|
||||
serviceInfo.setAllIPs(true);
|
||||
assertTrue(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateForNullHosts() {
|
||||
void testValidateForNullHosts() {
|
||||
serviceInfo.setHosts(null);
|
||||
assertFalse(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateForEmptyHosts() {
|
||||
void testValidateForEmptyHosts() {
|
||||
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
||||
assertFalse(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateForUnhealthyHosts() {
|
||||
void testValidateForUnhealthyHosts() {
|
||||
Instance instance = new Instance();
|
||||
instance.setHealthy(false);
|
||||
serviceInfo.addHost(instance);
|
||||
@ -143,7 +146,7 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||
void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||
List<Instance> instanceList = new LinkedList<>();
|
||||
Instance instance = new Instance();
|
||||
instanceList.add(instance);
|
||||
@ -155,7 +158,7 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromKey() {
|
||||
void testFromKey() {
|
||||
String key1 = "group@@name";
|
||||
String key2 = "group@@name@@c2";
|
||||
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
||||
@ -165,7 +168,7 @@ public class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() throws JsonProcessingException {
|
||||
void testSetAndGet() throws JsonProcessingException {
|
||||
serviceInfo.setReachProtectionThreshold(true);
|
||||
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
|
||||
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
|
||||
|
@ -16,19 +16,19 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServiceTest {
|
||||
class ServiceTest {
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
void testSetAndGet() {
|
||||
Service service = new Service();
|
||||
assertNull(service.getName());
|
||||
assertNull(service.getAppName());
|
||||
@ -51,12 +51,13 @@ public class ServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
Service service = new Service("service");
|
||||
service.setGroupName("group");
|
||||
service.setAppName("app");
|
||||
service.setProtectThreshold(1.0f);
|
||||
service.setMetadata(Collections.singletonMap("a", "b"));
|
||||
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", service.toString());
|
||||
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}",
|
||||
service.toString());
|
||||
}
|
||||
}
|
@ -17,18 +17,16 @@
|
||||
package com.alibaba.nacos.api.naming.pojo.builder;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class InstanceBuilderTest {
|
||||
class InstanceBuilderTest {
|
||||
|
||||
private static final String SERVICE_NAME = "testService";
|
||||
|
||||
@ -53,26 +51,26 @@ public class InstanceBuilderTest {
|
||||
private static final String META_VALUE = "value";
|
||||
|
||||
@Test
|
||||
public void testBuildFullInstance() {
|
||||
void testBuildFullInstance() {
|
||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
|
||||
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
|
||||
.setEphemeral(EPHEMERAL).addMetadata(META_KEY, META_VALUE).build();
|
||||
assertThat(actual.getServiceName(), is(SERVICE_NAME));
|
||||
assertThat(actual.getClusterName(), is(CLUSTER_NAME));
|
||||
assertThat(actual.getInstanceId(), is(INSTANCE_ID));
|
||||
assertThat(actual.getIp(), is(IP));
|
||||
assertThat(actual.getPort(), is(PORT));
|
||||
assertThat(actual.getWeight(), is(WEIGHT));
|
||||
assertThat(actual.isHealthy(), is(HEALTHY));
|
||||
assertThat(actual.isEnabled(), is(ENABLED));
|
||||
assertThat(actual.isEphemeral(), is(EPHEMERAL));
|
||||
assertThat(actual.getMetadata().size(), is(1));
|
||||
assertThat(actual.getMetadata().get(META_KEY), is(META_VALUE));
|
||||
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID).setIp(IP)
|
||||
.setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED).setEphemeral(EPHEMERAL)
|
||||
.addMetadata(META_KEY, META_VALUE).build();
|
||||
assertEquals(actual.getServiceName(), SERVICE_NAME);
|
||||
assertEquals(actual.getClusterName(), CLUSTER_NAME);
|
||||
assertEquals(actual.getInstanceId(), INSTANCE_ID);
|
||||
assertEquals(actual.getIp(), IP);
|
||||
assertEquals(actual.getPort(), PORT);
|
||||
assertEquals(actual.getWeight(), WEIGHT);
|
||||
assertEquals(actual.isHealthy(), HEALTHY);
|
||||
assertEquals(actual.isEnabled(), ENABLED);
|
||||
assertEquals(actual.isEphemeral(), EPHEMERAL);
|
||||
assertEquals(actual.getMetadata().size(), 1);
|
||||
assertEquals(actual.getMetadata().get(META_KEY), META_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildInstanceWithoutNewMetadata() {
|
||||
void testBuildInstanceWithoutNewMetadata() {
|
||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("test", "test");
|
||||
@ -81,8 +79,8 @@ public class InstanceBuilderTest {
|
||||
assertNull(actual.getClusterName());
|
||||
assertNull(actual.getInstanceId());
|
||||
assertNull(actual.getIp());
|
||||
assertThat(actual.getPort(), is(0));
|
||||
assertThat(actual.getWeight(), is(1.0));
|
||||
assertEquals(actual.getPort(), 0);
|
||||
assertEquals(actual.getWeight(), 1.0);
|
||||
assertTrue(actual.isHealthy());
|
||||
assertTrue(actual.isEnabled());
|
||||
assertTrue(actual.isEphemeral());
|
||||
@ -90,15 +88,15 @@ public class InstanceBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildEmptyInstance() {
|
||||
void testBuildEmptyInstance() {
|
||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||
Instance actual = builder.build();
|
||||
assertNull(actual.getServiceName());
|
||||
assertNull(actual.getClusterName());
|
||||
assertNull(actual.getInstanceId());
|
||||
assertNull(actual.getIp());
|
||||
assertThat(actual.getPort(), is(0));
|
||||
assertThat(actual.getWeight(), is(1.0));
|
||||
assertEquals(actual.getPort(), 0);
|
||||
assertEquals(actual.getWeight(), 1.0);
|
||||
assertTrue(actual.isHealthy());
|
||||
assertTrue(actual.isEnabled());
|
||||
assertTrue(actual.isEphemeral());
|
||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AbstractHealthCheckerTest {
|
||||
class AbstractHealthCheckerTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
TestChecker testChecker = new TestChecker();
|
||||
testChecker.setTestValue("");
|
||||
String actual = objectMapper.writeValueAsString(testChecker);
|
||||
@ -48,7 +48,7 @@ public class AbstractHealthCheckerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
||||
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
||||
assertEquals("", actual.getTestValue());
|
||||
@ -56,7 +56,7 @@ public class AbstractHealthCheckerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
|
||||
assertEquals(AbstractHealthChecker.None.class, none.getClass());
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class HealthCheckTypeTest {
|
||||
class HealthCheckTypeTest {
|
||||
|
||||
@Test
|
||||
public void testOfHealthCheckerClassForBuildInType() {
|
||||
void testOfHealthCheckerClassForBuildInType() {
|
||||
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
||||
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
||||
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
||||
@ -37,18 +37,18 @@ public class HealthCheckTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfHealthCheckerClassForExtendType() {
|
||||
void testOfHealthCheckerClassForExtendType() {
|
||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfHealthCheckerClassForNonExistType() {
|
||||
void testOfHealthCheckerClassForNonExistType() {
|
||||
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLoadedHealthCheckerClasses() {
|
||||
void testGetLoadedHealthCheckerClasses() {
|
||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
||||
assertEquals(5, actual.size());
|
||||
|
@ -19,75 +19,80 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosSerializationException;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class HealthCheckerFactoryTest {
|
||||
class HealthCheckerFactoryTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
@BeforeAll
|
||||
static void beforeClass() {
|
||||
HealthCheckerFactory.registerSubType(new TestChecker());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() {
|
||||
void testSerialize() {
|
||||
Tcp tcp = new Tcp();
|
||||
String actual = HealthCheckerFactory.serialize(tcp);
|
||||
assertTrue(actual.contains("\"type\":\"TCP\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeExtend() {
|
||||
void testSerializeExtend() {
|
||||
TestChecker testChecker = new TestChecker();
|
||||
String actual = HealthCheckerFactory.serialize(testChecker);
|
||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() {
|
||||
void testDeserialize() {
|
||||
String tcpString = "{\"type\":\"TCP\"}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(Tcp.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeExtend() {
|
||||
void testDeserializeExtend() {
|
||||
String tcpString = "{\"type\":\"TEST\",\"testValue\":null}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(TestChecker.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeNoRegister() {
|
||||
void testSerializeNoRegister() {
|
||||
NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker();
|
||||
assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeNoRegister() {
|
||||
void testDeserializeNoRegister() {
|
||||
String tcpString = "{\"type\":\"no register\",\"testValue\":null}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(AbstractHealthChecker.None.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test(expected = NacosSerializationException.class)
|
||||
public void testSerializeFailure() {
|
||||
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
|
||||
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
|
||||
}
|
||||
|
||||
@Test(expected = NacosDeserializationException.class)
|
||||
public void testDeserializeFailure() {
|
||||
String errorString = "{\"type\"=\"TCP\"}";
|
||||
System.out.println(HealthCheckerFactory.deserialize(errorString));
|
||||
@Test
|
||||
void testSerializeFailure() {
|
||||
assertThrows(NacosSerializationException.class, () -> {
|
||||
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
|
||||
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNoneHealthChecker() {
|
||||
void testDeserializeFailure() {
|
||||
assertThrows(NacosDeserializationException.class, () -> {
|
||||
String errorString = "{\"type\"=\"TCP\"}";
|
||||
System.out.println(HealthCheckerFactory.deserialize(errorString));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateNoneHealthChecker() {
|
||||
assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass());
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,10 @@ public class TestChecker extends AbstractHealthChecker {
|
||||
|
||||
private String testValue;
|
||||
|
||||
public TestChecker() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
public String getTestValue() {
|
||||
return testValue;
|
||||
}
|
||||
@ -36,10 +40,6 @@ public class TestChecker extends AbstractHealthChecker {
|
||||
this.testValue = testValue;
|
||||
}
|
||||
|
||||
public TestChecker() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
||||
return null;
|
||||
|
@ -18,36 +18,37 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class HttpTest {
|
||||
class HttpTest {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private Http http;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
http = new Http();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpectedResponseCodeWithEmpty() {
|
||||
void testGetExpectedResponseCodeWithEmpty() {
|
||||
http.setHeaders("");
|
||||
assertTrue(http.getCustomHeaders().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpectedResponseCodeWithoutEmpty() {
|
||||
void testGetExpectedResponseCodeWithoutEmpty() {
|
||||
http.setHeaders("x:a|y:");
|
||||
Map<String, String> actual = http.getCustomHeaders();
|
||||
assertFalse(actual.isEmpty());
|
||||
@ -56,7 +57,7 @@ public class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
http.setHeaders("x:a|y:");
|
||||
http.setPath("/x");
|
||||
String actual = objectMapper.writeValueAsString(http);
|
||||
@ -67,7 +68,7 @@ public class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"HTTP\",\"path\":\"/x\",\"headers\":\"x:a|y:\",\"expectedResponseCode\":200}";
|
||||
Http actual = objectMapper.readValue(testChecker, Http.class);
|
||||
assertEquals("x:a|y:", actual.getHeaders());
|
||||
@ -78,23 +79,23 @@ public class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
Http cloned = http.clone();
|
||||
assertEquals(http.hashCode(), cloned.hashCode());
|
||||
assertTrue(http.equals(cloned));
|
||||
assertEquals(http, cloned);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() throws CloneNotSupportedException {
|
||||
assertFalse(http.equals(new Tcp()));
|
||||
void testNotEquals() throws CloneNotSupportedException {
|
||||
assertNotEquals(http, new Tcp());
|
||||
Http cloned = http.clone();
|
||||
cloned.setPath("aaa");
|
||||
assertFalse(http.equals(cloned));
|
||||
assertNotEquals(http, cloned);
|
||||
cloned = http.clone();
|
||||
cloned.setHeaders("aaa");
|
||||
assertFalse(http.equals(cloned));
|
||||
assertNotEquals(http, cloned);
|
||||
cloned = http.clone();
|
||||
cloned.setExpectedResponseCode(500);
|
||||
assertFalse(http.equals(cloned));
|
||||
assertNotEquals(http, cloned);
|
||||
}
|
||||
}
|
||||
|
@ -18,23 +18,23 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class MysqlTest {
|
||||
class MysqlTest {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private Mysql mysql;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
mysql = new Mysql();
|
||||
mysql.setUser("user");
|
||||
mysql.setPwd("pwd");
|
||||
@ -43,7 +43,7 @@ public class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
String actual = objectMapper.writeValueAsString(mysql);
|
||||
assertTrue(actual.contains("\"user\":\"user\""));
|
||||
assertTrue(actual.contains("\"type\":\"MYSQL\""));
|
||||
@ -52,7 +52,7 @@ public class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"MYSQL\",\"user\":\"user\",\"pwd\":\"pwd\",\"cmd\":\"cmd\"}";
|
||||
Mysql actual = objectMapper.readValue(testChecker, Mysql.class);
|
||||
assertEquals("cmd", actual.getCmd());
|
||||
@ -62,23 +62,23 @@ public class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
Mysql cloned = mysql.clone();
|
||||
assertEquals(mysql.hashCode(), cloned.hashCode());
|
||||
assertTrue(mysql.equals(cloned));
|
||||
assertEquals(mysql, cloned);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() throws CloneNotSupportedException {
|
||||
assertFalse(mysql.equals(new Tcp()));
|
||||
void testNotEquals() throws CloneNotSupportedException {
|
||||
assertNotEquals(mysql, new Tcp());
|
||||
Mysql cloned = mysql.clone();
|
||||
cloned.setUser("aaa");
|
||||
assertFalse(mysql.equals(cloned));
|
||||
assertNotEquals(mysql, cloned);
|
||||
cloned = mysql.clone();
|
||||
cloned.setPwd("aaa");
|
||||
assertFalse(mysql.equals(cloned));
|
||||
assertNotEquals(mysql, cloned);
|
||||
cloned = mysql.clone();
|
||||
cloned.setCmd("aaa");
|
||||
assertFalse(mysql.equals(cloned));
|
||||
assertNotEquals(mysql, cloned);
|
||||
}
|
||||
}
|
||||
|
@ -16,18 +16,17 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TcpTest {
|
||||
class TcpTest {
|
||||
|
||||
@Test
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
Tcp original = new Tcp();
|
||||
Tcp cloned = original.clone();
|
||||
assertEquals(original.hashCode(), cloned.hashCode());
|
||||
assertTrue(original.equals(cloned));
|
||||
assertEquals(original, cloned);
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ package com.alibaba.nacos.api.naming.remote.request;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public abstract class BasedNamingRequestTest {
|
||||
|
||||
@ -35,7 +35,7 @@ public abstract class BasedNamingRequestTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.remote.request;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
BatchInstanceRequest request = new BatchInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||
NamingRemoteConstants.BATCH_REGISTER_INSTANCE, Collections.singletonList(new Instance()));
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -39,7 +39,7 @@ public class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"type\":\"batchRegisterInstance\",\"instances\":[{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||
|
@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
InstanceRequest request = new InstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -37,7 +37,7 @@ public class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||
|
@ -21,14 +21,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NotifySubscriberRequestTest {
|
||||
class NotifySubscriberRequestTest {
|
||||
|
||||
private static final String SERVICE = "service";
|
||||
|
||||
@ -38,15 +38,15 @@ public class NotifySubscriberRequestTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE);
|
||||
NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo);
|
||||
request.setServiceName(SERVICE);
|
||||
@ -58,7 +58,7 @@ public class NotifySubscriberRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"serviceInfo\":{\"name\":\"service\",\"groupName\":\"group\",\"cacheMillis\":1000,\"hosts\":[],"
|
||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||
|
@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
PersistentInstanceRequest request = new PersistentInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -37,7 +37,7 @@ public class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||
|
@ -17,16 +17,16 @@
|
||||
package com.alibaba.nacos.api.naming.remote.request;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10);
|
||||
request.setSelector("label");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -39,7 +39,7 @@ public class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"\",\"groupName\":\"group\","
|
||||
+ "\"pageNo\":1,\"pageSize\":10,\"selector\":\"label\",\"module\":\"naming\"}";
|
||||
ServiceListRequest actual = mapper.readValue(json, ServiceListRequest.class);
|
||||
|
@ -18,15 +18,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
ServiceQueryRequest request = new ServiceQueryRequest(NAMESPACE, SERVICE, GROUP);
|
||||
request.setCluster(Constants.DEFAULT_CLUSTER_NAME);
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -37,7 +37,7 @@ public class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"cluster\":\"DEFAULT\",\"healthyOnly\":true,\"udpPort\":0,\"module\":\"naming\"}";
|
||||
ServiceQueryRequest actual = mapper.readValue(json, ServiceQueryRequest.class);
|
||||
|
@ -17,16 +17,16 @@
|
||||
package com.alibaba.nacos.api.naming.remote.request;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true);
|
||||
String json = mapper.writeValueAsString(request);
|
||||
checkSerializeBasedInfo(json);
|
||||
@ -35,7 +35,7 @@ public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||
+ "\"subscribe\":false,\"clusters\":\"aa,bb\",\"module\":\"naming\"}";
|
||||
SubscribeServiceRequest actual = mapper.readValue(json, SubscribeServiceRequest.class);
|
||||
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class BatchInstanceResponseTest {
|
||||
class BatchInstanceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"registerInstance\",\"success\":true}";
|
||||
BatchInstanceResponse response = mapper.readValue(json, BatchInstanceResponse.class);
|
||||
assertEquals(NamingRemoteConstants.REGISTER_INSTANCE, response.getType());
|
||||
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class InstanceResponseTest {
|
||||
class InstanceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"deregisterInstance\",\"success\":true}";
|
||||
InstanceResponse response = mapper.readValue(json, InstanceResponse.class);
|
||||
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, response.getType());
|
||||
|
@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class QueryServiceResponseTest {
|
||||
class QueryServiceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo());
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"serviceInfo\":{"));
|
||||
@ -49,7 +49,7 @@ public class QueryServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test");
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"resultCode\":500"));
|
||||
@ -59,7 +59,7 @@ public class QueryServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||
+ "\"valid\":true},\"success\":true}";
|
||||
|
@ -20,27 +20,27 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ServiceListResponseTest {
|
||||
class ServiceListResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
ServiceListResponse response = ServiceListResponse.buildSuccessResponse(10, Collections.singletonList("a"));
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"count\":10"));
|
||||
@ -51,7 +51,7 @@ public class ServiceListResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ServiceListResponse response = ServiceListResponse.buildFailResponse("test");
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"resultCode\":500"));
|
||||
@ -61,7 +61,7 @@ public class ServiceListResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"count\":10,\"serviceNames\":[\"a\"],\"success\":true}";
|
||||
ServiceListResponse response = mapper.readValue(json, ServiceListResponse.class);
|
||||
assertEquals(10, response.getCount());
|
||||
|
@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SubscribeServiceResponseTest {
|
||||
class SubscribeServiceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
SubscribeServiceResponse response = new SubscribeServiceResponse(200, null, new ServiceInfo());
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"serviceInfo\":{"));
|
||||
@ -49,7 +49,7 @@ public class SubscribeServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
SubscribeServiceResponse response = new SubscribeServiceResponse(500, "test", null);
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"resultCode\":500"));
|
||||
@ -59,7 +59,7 @@ public class SubscribeServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||
+ "\"valid\":true},\"success\":true}";
|
||||
|
@ -21,94 +21,117 @@ import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NamingUtilsTest {
|
||||
class NamingUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetGroupedName() {
|
||||
void testGetGroupedName() {
|
||||
assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetGroupedNameWithoutGroup() {
|
||||
NamingUtils.getGroupedName("serviceName", "");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetGroupedNameWithoutServiceName() {
|
||||
NamingUtils.getGroupedName("", "group");
|
||||
@Test
|
||||
void testGetGroupedNameWithoutGroup() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
NamingUtils.getGroupedName("serviceName", "");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServiceName() {
|
||||
void testGetGroupedNameWithoutServiceName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
NamingUtils.getGroupedName("", "group");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetServiceName() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
assertEquals("serviceName", NamingUtils.getServiceName(validServiceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServiceNameWithoutGroup() {
|
||||
void testGetServiceNameWithoutGroup() {
|
||||
String serviceName = "serviceName";
|
||||
assertEquals(serviceName, NamingUtils.getServiceName(serviceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServiceNameWithEmpty() {
|
||||
void testGetServiceNameWithEmpty() {
|
||||
assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupName() {
|
||||
void testGetGroupName() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
assertEquals("group", NamingUtils.getGroupName(validServiceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupNameWithoutGroup() {
|
||||
void testGetGroupNameWithoutGroup() {
|
||||
String serviceName = "serviceName";
|
||||
assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupNameWithEmpty() {
|
||||
void testGetGroupNameWithEmpty() {
|
||||
assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckServiceNameFormat() {
|
||||
void testIsServiceNameCompatibilityMode() {
|
||||
String serviceName1 = "group@@serviceName";
|
||||
assertTrue(NamingUtils.isServiceNameCompatibilityMode(serviceName1));
|
||||
|
||||
String serviceName2 = "serviceName";
|
||||
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName2));
|
||||
|
||||
String serviceName3 = null;
|
||||
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckServiceNameFormat() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCheckServiceNameFormatWithoutGroupAndService() {
|
||||
String validServiceName = "@@";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCheckServiceNameFormatWithoutGroup() {
|
||||
String validServiceName = "@@service";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCheckServiceNameFormatWithoutService() {
|
||||
String validServiceName = "group@@";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
@Test
|
||||
void testCheckServiceNameFormatWithoutGroupAndService() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String validServiceName = "@@";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupedNameOptional() {
|
||||
void testCheckServiceNameFormatWithoutGroup() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String validServiceName = "@@service";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckServiceNameFormatWithoutService() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String validServiceName = "group@@";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupedNameOptional() {
|
||||
String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA");
|
||||
assertEquals("groupA@@", onlyGroupName);
|
||||
|
||||
@ -120,7 +143,7 @@ public class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckInstanceIsLegal() throws NacosException {
|
||||
void testCheckInstanceIsLegal() throws NacosException {
|
||||
// check invalid clusterName
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("cluster1,cluster2");
|
||||
@ -138,7 +161,7 @@ public class NamingUtilsTest {
|
||||
instance.setClusterName("cluster1");
|
||||
NamingUtils.checkInstanceIsLegal(instance);
|
||||
assertTrue(true);
|
||||
|
||||
|
||||
// check heartBeatTimeout, heartBeatInterval, ipDeleteTimeout
|
||||
Map<String, String> meta = new HashMap<>();
|
||||
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "1");
|
||||
@ -150,8 +173,7 @@ public class NamingUtilsTest {
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof NacosException);
|
||||
assertEquals(
|
||||
"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||
assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||
e.getMessage());
|
||||
}
|
||||
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "3");
|
||||
@ -162,7 +184,7 @@ public class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchCheckInstanceIsLegal() throws NacosException {
|
||||
void testBatchCheckInstanceIsLegal() throws NacosException {
|
||||
// check invalid clusterName
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("cluster1,cluster2");
|
||||
@ -199,8 +221,7 @@ public class NamingUtilsTest {
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof NacosException);
|
||||
assertEquals(
|
||||
"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||
assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||
e.getMessage());
|
||||
}
|
||||
instanceList.remove(instance);
|
||||
@ -215,7 +236,7 @@ public class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckInstanceIsEphemeral() throws NacosException {
|
||||
void testCheckInstanceIsEphemeral() throws NacosException {
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("127.0.0.1");
|
||||
instance.setPort(9089);
|
||||
@ -228,12 +249,12 @@ public class NamingUtilsTest {
|
||||
instance.setEphemeral(false);
|
||||
NamingUtils.checkInstanceIsEphemeral(instance);
|
||||
} catch (NacosException e) {
|
||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
||||
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckInstanceIsNull() throws NacosException {
|
||||
void testCheckInstanceIsNull() throws NacosException {
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("127.0.0.1");
|
||||
instance.setPort(9089);
|
||||
@ -241,15 +262,15 @@ public class NamingUtilsTest {
|
||||
try {
|
||||
NamingUtils.checkInstanceIsLegal(null);
|
||||
} catch (NacosException e) {
|
||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
||||
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNumber() {
|
||||
void testIsNumber() {
|
||||
String str1 = "abc";
|
||||
assertTrue(!NamingUtils.isNumber(str1));
|
||||
|
||||
assertFalse(NamingUtils.isNumber(str1));
|
||||
|
||||
String str2 = "123456";
|
||||
assertTrue(NamingUtils.isNumber(str2));
|
||||
}
|
||||
|
@ -16,18 +16,18 @@
|
||||
|
||||
package com.alibaba.nacos.api.remote;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AbstractPushCallBackTest {
|
||||
class AbstractPushCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
public void testAbstractPushCallBack() {
|
||||
void testAbstractPushCallBack() {
|
||||
AbstractPushCallBack callBack = new AbstractPushCallBack(2000) {
|
||||
|
||||
@Override
|
||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.remote;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ErrorResponse;
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AbstractRequestCallBackTest {
|
||||
class AbstractRequestCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
public void testAbstractPushCallBack() {
|
||||
void testAbstractPushCallBack() {
|
||||
AbstractRequestCallBack callBack = new AbstractRequestCallBack() {
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user