Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e43767e963 | ||
|
8ac6c84a58 | ||
|
ca6d1518bf | ||
|
cb0422ed74 | ||
|
38faeea58d | ||
|
2eb7f739fd | ||
|
41859be6a9 | ||
|
b584531331 | ||
|
8e9f718d68 | ||
|
5a4d433970 | ||
|
1fac5c8334 | ||
|
11be620808 | ||
|
a18c27c385 | ||
|
1d88d5d773 | ||
|
023f50cb61 | ||
|
b9a842c83f | ||
|
c0ffb1d7e3 | ||
|
a341b65151 | ||
|
5e53396f78 | ||
|
c648249822 |
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@ -6,10 +6,11 @@ name: "Continuous Integration"
|
||||
on:
|
||||
push:
|
||||
branches: [ master, develop, v1.x-develop, v1.X ]
|
||||
pull_request_target:
|
||||
pull_request:
|
||||
branches: [ develop, v1.x-develop ]
|
||||
|
||||
permissions: read-all
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
@ -20,16 +21,16 @@ jobs:
|
||||
java: [8]
|
||||
steps:
|
||||
- name: "Cache Maven Repos"
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: "Set up JDK ${{ matrix.java }}"
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'zulu'
|
||||
@ -43,11 +44,6 @@ 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@v4.2.0
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
uses: codecov/codecov-action@v3.1.0
|
||||
with:
|
||||
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 }}
|
||||
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
|
||||
|
488
.github/workflows/pr-e2e-test.yml
vendored
488
.github/workflows/pr-e2e-test.yml
vendored
@ -6,11 +6,10 @@ on:
|
||||
workflows: ["PR-CI"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
@ -23,8 +22,6 @@ 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
|
||||
@ -36,7 +33,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,
|
||||
@ -50,12 +47,19 @@ 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: Generate image tag
|
||||
- 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
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*.tar.gz nacos-e2e/cicd/build
|
||||
@ -64,44 +68,43 @@ jobs:
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||
- name: docker-login-1
|
||||
uses: docker/login-action@v2
|
||||
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
|
||||
with:
|
||||
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
|
||||
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
|
||||
with:
|
||||
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: versionlist
|
||||
path: versionlist
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||
run: |
|
||||
a=(`ls 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: [docker]
|
||||
needs: [list-version,docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
@ -109,392 +112,99 @@ jobs:
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
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
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: Deploy nacos
|
||||
with:
|
||||
yamlString: |
|
||||
action: deploy
|
||||
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: |
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
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:
|
||||
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:
|
||||
if: ${{ success() }}
|
||||
name: Java e2e Test
|
||||
needs: [docker, deploy]
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: java e2e test
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: 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: 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
|
||||
|
||||
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
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-java.txt
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
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: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||
needs: [list-version, e2e-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: clean
|
||||
with:
|
||||
yamlString: |
|
||||
action: clean
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
|
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
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
|
||||
concurrency:
|
||||
group: nacos-${{ github.ref }}
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
|
||||
jobs:
|
||||
dist-tar:
|
||||
@ -50,15 +50,10 @@ 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:
|
||||
@ -70,7 +65,13 @@ jobs:
|
||||
with:
|
||||
name: nacos
|
||||
path: ./
|
||||
- name: Generate image tag
|
||||
- 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
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*.tar.gz nacos-e2e/cicd/build/
|
||||
@ -79,44 +80,42 @@ jobs:
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||
- name: docker-login-1
|
||||
uses: docker/login-action@v2
|
||||
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
|
||||
with:
|
||||
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
|
||||
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
|
||||
with:
|
||||
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: versionlist
|
||||
path: versionlist
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||
a=(`ls 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: [docker]
|
||||
needs: [list-version,docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
@ -124,390 +123,99 @@ jobs:
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
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
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: Deploy nacos
|
||||
with:
|
||||
yamlString: |
|
||||
action: deploy
|
||||
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: |
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
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:
|
||||
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:
|
||||
if: ${{ success() }}
|
||||
name: Java e2e Test
|
||||
needs: [docker, deploy]
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
name: java e2e test
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: 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: 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
|
||||
|
||||
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
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog-${{ matrix.mode }}-java.txt
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
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: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||
needs: [list-version, e2e-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@java-dev
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: clean
|
||||
with:
|
||||
yamlString: |
|
||||
action: clean
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,4 +18,3 @@ 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 an instance if no leader in the raft cluster.
|
||||
* [#181] NPE when adding a 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,21 +121,19 @@ 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).
|
||||
|
||||
|
||||
<img src="https://img.alicdn.com/imgextra/i4/O1CN01MI7re41xTrZNdB7Yv_!!6000000006445-0-tps-974-1228.jpg" width="500">
|
||||
![Nacos](https://img.alicdn.com/imgextra/i1/O1CN01ULSVXu1DRbANwVC6r_!!6000000000213-2-tps-666-884.png)
|
||||
|
||||
## 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
|
||||
|
||||
<img src="https://img.alicdn.com/imgextra/i3/O1CN01RTfN7q1KUzX4TcH08_!!6000000001168-2-tps-864-814.png" width="500">
|
||||
|
||||
![image](https://user-images.githubusercontent.com/17695352/128659442-65b030b8-c5f4-4bb7-baa2-e5b3ef0cbc15.png)
|
||||
|
||||
## Download
|
||||
|
||||
- [Nacos Official Website](https://nacos.io/download/nacos-server)
|
||||
- [GitHub Release](https://github.com/alibaba/nacos/releases)
|
||||
|
||||
- [Github Release](https://github.com/alibaba/nacos/releases)
|
||||
- [Baidu Netdisk](https://pan.baidu.com/s/1186nmlqPGows9gUZKAx8Zw) Fetch Code : `rest`
|
||||
|
||||
## 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</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -96,7 +96,7 @@ public class AddressServerGeneratorManager {
|
||||
/**
|
||||
* Generate response ips.
|
||||
*
|
||||
* @param instanceList an instance set will generate string response to client.
|
||||
* @param instanceList a 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 contain the {@link Constants#DEFAULT_GROUP}.
|
||||
* @param rawServiceName the raw service name will not contains the {@link Constants#DEFAULT_GROUP}.
|
||||
* @return the nacos service name
|
||||
*/
|
||||
public String generateNacosServiceName(String rawServiceName) {
|
||||
|
@ -16,26 +16,22 @@
|
||||
|
||||
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.web.SecurityFilterChain;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* nacos web security configuration.
|
||||
*
|
||||
* @author onewe
|
||||
*/
|
||||
@Configuration
|
||||
public class AddressServerSecurityConfiguration {
|
||||
@Order(99)
|
||||
public class AddressServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@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();
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests(requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated())
|
||||
.csrf().disable().httpBasic();
|
||||
}
|
||||
}
|
||||
|
@ -18,59 +18,55 @@ package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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 {
|
||||
|
||||
public class AddressServerGeneratorManagerTest {
|
||||
|
||||
@Test
|
||||
void testGenerateProductName() {
|
||||
public void testGenerateProductName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final String blankName = manager.generateProductName("");
|
||||
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||
|
||||
final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
|
||||
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||
|
||||
final String testName = manager.generateProductName("test");
|
||||
assertEquals("nacos.as.test", testName);
|
||||
Assert.assertEquals("nacos.as.test", testName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenerateInstancesByIps() {
|
||||
public void testGenerateInstancesByIps() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
|
||||
assertNotNull(empty);
|
||||
assertTrue(empty.isEmpty());
|
||||
Assert.assertNotNull(empty);
|
||||
Assert.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);
|
||||
assertNotNull(instanceList);
|
||||
assertFalse(instanceList.isEmpty());
|
||||
assertEquals(3, instanceList.size());
|
||||
Assert.assertNotNull(instanceList);
|
||||
Assert.assertFalse(instanceList.isEmpty());
|
||||
Assert.assertEquals(3, instanceList.size());
|
||||
|
||||
final Instance instance1 = instanceList.get(0);
|
||||
assertEquals("192.168.3.1", instance1.getIp());
|
||||
Assert.assertEquals("192.168.3.1", instance1.getIp());
|
||||
|
||||
final Instance instance2 = instanceList.get(1);
|
||||
assertEquals("192.168.3.2", instance2.getIp());
|
||||
Assert.assertEquals("192.168.3.2", instance2.getIp());
|
||||
|
||||
final Instance instance3 = instanceList.get(2);
|
||||
assertEquals("192.168.3.3", instance3.getIp());
|
||||
Assert.assertEquals("192.168.3.3", instance3.getIp());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenerateResponseIps() {
|
||||
public void testGenerateResponseIps() {
|
||||
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
|
||||
Instance instance1 = new Instance();
|
||||
instance1.setIp("192.168.3.1");
|
||||
@ -96,19 +92,19 @@ 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');
|
||||
assertEquals(ret.toString(), ipListStr);
|
||||
Assert.assertEquals(ret.toString(), ipListStr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenerateNacosServiceName() {
|
||||
public void testGenerateNacosServiceName() {
|
||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||
|
||||
final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
|
||||
assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||
Assert.assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||
|
||||
final String product = manager.generateNacosServiceName("product");
|
||||
assertEquals("DEFAULT_GROUP@@product", product);
|
||||
Assert.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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
class AddressServerManagerTests {
|
||||
public class AddressServerManagerTests {
|
||||
|
||||
private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();
|
||||
|
||||
|
||||
@Test
|
||||
void getRawProductName() {
|
||||
public 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
|
||||
void getDefaultClusterNameIfEmpty() {
|
||||
public 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
|
||||
void testGetRawClusterName() {
|
||||
public void testGetRawClusterName() {
|
||||
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
|
||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSplitIps() {
|
||||
public 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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
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;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AddressServerClusterControllerTest {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AddressServerClusterControllerTest {
|
||||
|
||||
@Mock
|
||||
private InstanceOperator instanceOperator;
|
||||
@ -53,9 +53,9 @@ class AddressServerClusterControllerTest {
|
||||
private ClusterOperator clusterOperator;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(
|
||||
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
|
||||
new AddressServerManager(), new AddressServerGeneratorManager())).build();
|
||||
@ -63,30 +63,30 @@ class AddressServerClusterControllerTest {
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().getSingleton(service);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testPostCluster() throws Exception {
|
||||
public 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
|
||||
void testPostClusterWithErrorIps() throws Exception {
|
||||
public 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
|
||||
void testPostClusterThrowException() throws Exception {
|
||||
public 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 @@ class AddressServerClusterControllerTest {
|
||||
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testDeleteCluster() throws Exception {
|
||||
public 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
|
||||
void testDeleteClusterCannotFindService() throws Exception {
|
||||
public 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
|
||||
void testDeleteClusterEmptyIps() throws Exception {
|
||||
public void testDeleteClusterEmptyIps() throws Exception {
|
||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||
.param("ips", "")).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testDeleteClusterErrorIps() throws Exception {
|
||||
public 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
|
||||
void testDeleteClusterThrowException() throws Exception {
|
||||
public 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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
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;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ServerListControllerTest {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServerListControllerTest {
|
||||
|
||||
@Mock
|
||||
private NamingMetadataManager metadataManager;
|
||||
@ -55,23 +55,23 @@ class ServerListControllerTest {
|
||||
private Service service;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
|
||||
@Before
|
||||
public 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);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServiceManager.getInstance().removeSingleton(service);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGetCluster() throws Exception {
|
||||
public void testGetCluster() throws Exception {
|
||||
|
||||
final Service service = Service
|
||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||
@ -86,16 +86,16 @@ class ServerListControllerTest {
|
||||
when(serviceStorage.getData(service)).thenReturn(serviceInfo);
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGetClusterCannotFindService() throws Exception {
|
||||
public void testGetClusterCannotFindService() throws Exception {
|
||||
tearDown();
|
||||
mockMvc.perform(get("/default/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGetClusterCannotFindCluster() throws Exception {
|
||||
public void testGetClusterCannotFindCluster() throws Exception {
|
||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,11 @@
|
||||
<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>
|
||||
@ -80,10 +85,6 @@
|
||||
<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,10 +33,6 @@ 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";
|
||||
@ -63,10 +59,6 @@ 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";
|
||||
@ -77,8 +69,6 @@ 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";
|
||||
@ -91,15 +81,6 @@ 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.
|
||||
*/
|
||||
@ -107,8 +88,6 @@ 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,9 +46,4 @@ 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,8 +33,6 @@ 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";
|
||||
@ -43,14 +41,10 @@ public class Constants {
|
||||
|
||||
public static final String NULL = "";
|
||||
|
||||
public static final String DATA_ID = "dataId";
|
||||
|
||||
public static final String TENANT = "tenant";
|
||||
|
||||
public static final String DATAID = "dataId";
|
||||
|
||||
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";
|
||||
@ -229,29 +223,6 @@ 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.
|
||||
*/
|
||||
@ -266,9 +237,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";
|
||||
}
|
||||
|
||||
@ -276,7 +247,7 @@ public class Constants {
|
||||
* The constants in remote directory.
|
||||
*/
|
||||
public static class Remote {
|
||||
|
||||
|
||||
public static final String INTERNAL_MODULE = "internal";
|
||||
}
|
||||
|
||||
@ -288,9 +259,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(23002, "node down failure"),
|
||||
NODE_DOWN_FAILURE(23001, "node down failure"),
|
||||
|
||||
/**
|
||||
* server error.
|
||||
|
@ -21,7 +21,6 @@ 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;
|
||||
@ -34,7 +33,7 @@ import java.util.List;
|
||||
public interface NamingService {
|
||||
|
||||
/**
|
||||
* register an instance to service.
|
||||
* register a instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
@ -44,7 +43,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String ip, int port) throws NacosException;
|
||||
|
||||
/**
|
||||
* register an instance to service.
|
||||
* register a instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -55,7 +54,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
||||
|
||||
/**
|
||||
* register an instance to service with specified cluster name.
|
||||
* register a instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
@ -66,7 +65,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
/**
|
||||
* register an instance to service with specified cluster name.
|
||||
* register a instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -79,7 +78,7 @@ public interface NamingService {
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* register an instance to service with specified instance properties.
|
||||
* register a instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param instance instance to register
|
||||
@ -88,7 +87,7 @@ public interface NamingService {
|
||||
void registerInstance(String serviceName, Instance instance) throws NacosException;
|
||||
|
||||
/**
|
||||
* register an instance to service with specified instance properties.
|
||||
* register a instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -492,28 +491,6 @@ 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.
|
||||
*
|
||||
@ -555,28 +532,6 @@ 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 an instance of health checker.
|
||||
* Deserialize and create a instance of health checker.
|
||||
*
|
||||
* @param jsonString json string of health checker
|
||||
* @return new instance
|
||||
@ -83,7 +83,7 @@ public class HealthCheckerFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize an instance of health checker to json.
|
||||
* Serialize a instance of health checker to json.
|
||||
*
|
||||
* @param healthChecker health checker instance
|
||||
* @return son string after serializing
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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>> {
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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,27 +16,17 @@
|
||||
|
||||
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 InstanceIdGenerator {
|
||||
public interface IdGenerator {
|
||||
|
||||
/**
|
||||
* Generate instance id.
|
||||
*
|
||||
* @param instance instance
|
||||
* @return instance id
|
||||
*/
|
||||
String generateInstanceId(Instance instance);
|
||||
|
||||
/**
|
||||
* Generator type.
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
String type();
|
||||
String generateInstanceId();
|
||||
}
|
@ -87,16 +87,6 @@ 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,7 +57,6 @@ public class ErrorResponse extends Response {
|
||||
}
|
||||
ErrorResponse response = new ErrorResponse();
|
||||
response.setErrorInfo(errorCode, exception.getMessage());
|
||||
response.setResultCode(errorCode);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClientAbilitiesTest {
|
||||
public class ClientAbilitiesTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ClientAbilities abilities = new ClientAbilities();
|
||||
String json = mapper.writeValueAsString(abilities);
|
||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||
@ -47,7 +47,7 @@ class ClientAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServerAbilitiesTest {
|
||||
public class ServerAbilitiesTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
private ServerAbilities serverAbilities;
|
||||
|
||||
@BeforeAll
|
||||
static void setUpBeforeClass() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
serverAbilities = new ServerAbilities();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
serverAbilities = new ServerAbilities();
|
||||
String json = mapper.writeValueAsString(serverAbilities);
|
||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||
@ -57,7 +57,7 @@ class ServerAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||
+ "\"supportRemoteMetric\":false}}";
|
||||
@ -68,10 +68,10 @@ class ServerAbilitiesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsAndHashCode() {
|
||||
public void testEqualsAndHashCode() {
|
||||
assertEquals(serverAbilities, serverAbilities);
|
||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||
assertNotEquals(null, serverAbilities);
|
||||
assertNotEquals(serverAbilities, null);
|
||||
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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClusterClientAbilitiesTest {
|
||||
public class ClusterClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
void testGetStaticAbilities() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class SdkClientAbilitiesTest {
|
||||
public class SdkClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
void testGetStaticAbilities() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServerAbilitiesTest {
|
||||
public class ServerAbilitiesTest {
|
||||
|
||||
@Test
|
||||
void testGetStaticAbilities() {
|
||||
public void testGetStaticAbilities() {
|
||||
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSupportPersistentInstanceByGrpcAbilities() {
|
||||
public void testSupportPersistentInstanceByGrpcAbilities() {
|
||||
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
||||
@ -27,24 +28,23 @@ 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;
|
||||
|
||||
class NacosPropertiesTest {
|
||||
public class NacosPropertiesTest {
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResolvePlaceholders() {
|
||||
public void testResolvePlaceholders() {
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
@ -75,11 +75,11 @@ class NacosPropertiesTest {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty(propertyName, propertyValue);
|
||||
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
||||
assertEquals(expectValue, resolvedValue);
|
||||
Assert.assertEquals(expectValue, resolvedValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSort() {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class EntityEventTest {
|
||||
public class EntityEventTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
EntityEvent entity = new EntityEvent();
|
||||
entity.setEntityName("test-entity");
|
||||
entity.setEntityType("CMDB");
|
||||
@ -50,7 +50,7 @@ class EntityEventTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class EntityTest {
|
||||
public class EntityTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
Entity entity = new Entity();
|
||||
entity.setName("test-entity");
|
||||
entity.setType(PreservedEntityTypes.ip.name());
|
||||
@ -51,7 +51,7 @@ class EntityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class LabelTest {
|
||||
public class LabelTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialization() throws JsonProcessingException {
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
Label label = new Label();
|
||||
label.setName("test-label");
|
||||
label.setDescription("CMDB description");
|
||||
@ -52,7 +52,7 @@ class LabelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialization() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class ConfigChangeEventTest {
|
||||
public class ConfigChangeEventTest {
|
||||
|
||||
@Test
|
||||
void testConstructor() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class ConfigChangeItemTest {
|
||||
public class ConfigChangeItemTest {
|
||||
|
||||
@Test
|
||||
void testSetNewValue() {
|
||||
public void testSetNewValue() {
|
||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||
item.setType(PropertyChangeType.ADDED);
|
||||
assertEquals("testKey", item.getKey());
|
||||
@ -46,7 +46,7 @@ class ConfigChangeItemTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigTypeTest {
|
||||
public class ConfigTypeTest {
|
||||
|
||||
@Test
|
||||
void isValidType() {
|
||||
public void isValidType() {
|
||||
assertTrue(ConfigType.isValidType("xml"));
|
||||
assertTrue(ConfigType.isValidType("properties"));
|
||||
assertTrue(ConfigType.isValidType("json"));
|
||||
@ -38,7 +38,7 @@ class ConfigTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDefaultType() {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClientRemoteAbilityTest {
|
||||
public class ClientRemoteAbilityTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
||||
String json = mapper.writeValueAsString(abilities);
|
||||
assertEquals("{\"supportRemoteConnection\":false}", json);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"supportRemoteConnection\":true}";
|
||||
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
||||
assertTrue(abilities.isSupportRemoteConnection());
|
||||
|
@ -16,20 +16,21 @@
|
||||
|
||||
package com.alibaba.nacos.api.config.ability;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
class ServerConfigAbilityTest {
|
||||
public class ServerConfigAbilityTest {
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
public void testEquals() {
|
||||
ServerConfigAbility ability = new ServerConfigAbility();
|
||||
ability.setSupportRemoteMetrics(true);
|
||||
assertEquals(ability, ability);
|
||||
assertNotEquals(null, ability);
|
||||
assertNotEquals(ability, new ClientConfigAbility());
|
||||
assertFalse(ability.equals(null));
|
||||
assertFalse(ability.equals(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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServerRemoteAbilityTest {
|
||||
public class ServerRemoteAbilityTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
private ServerRemoteAbility serverAbilities;
|
||||
|
||||
@BeforeAll
|
||||
static void setUpBeforeClass() throws Exception {
|
||||
@BeforeClass
|
||||
public 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);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
serverAbilities = new ServerRemoteAbility();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
serverAbilities = new ServerRemoteAbility();
|
||||
String json = mapper.writeValueAsString(serverAbilities);
|
||||
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
||||
@ -59,7 +59,7 @@ class ServerRemoteAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
||||
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
||||
assertTrue(abilities.isSupportRemoteConnection());
|
||||
@ -67,10 +67,10 @@ class ServerRemoteAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsAndHashCode() {
|
||||
public void testEqualsAndHashCode() {
|
||||
assertEquals(serverAbilities, serverAbilities);
|
||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||
assertNotEquals(null, serverAbilities);
|
||||
assertNotEquals(serverAbilities, null);
|
||||
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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class AbstractListenerTest {
|
||||
public class AbstractListenerTest {
|
||||
|
||||
@Test
|
||||
void testGetExecutor() {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class AbstractSharedListenerTest {
|
||||
public class AbstractSharedListenerTest {
|
||||
|
||||
private static final String CONFIG_CONTENT = "test";
|
||||
|
||||
private static Map<String, String> receivedMap;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@Before
|
||||
public void setUp() {
|
||||
receivedMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFillContext() {
|
||||
public void testFillContext() {
|
||||
assertEquals(0, receivedMap.size());
|
||||
MockShardListener listener = new MockShardListener();
|
||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||
@ -52,7 +52,7 @@ class AbstractSharedListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getExecutor() {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -30,6 +30,8 @@ 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";
|
||||
@ -50,13 +52,11 @@ public abstract class BasedConfigRequestTest {
|
||||
|
||||
protected static final String CONTENT = "content";
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
@ -18,17 +18,18 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@ -56,36 +57,35 @@ 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(2, actual.getMetricsKeys().size());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||
assertEquals(actual.getMetricsKeys().size(), 2);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMetricsKeysEquals() {
|
||||
public void testMetricsKeysEquals() {
|
||||
String dataKey = String.join("+", KEY);
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||
assertEquals(key, key);
|
||||
assertNotEquals(null, key);
|
||||
assertNotEquals(key, new ClientConfigMetricRequest());
|
||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA,
|
||||
dataKey);
|
||||
assertFalse(key.equals(null));
|
||||
assertFalse(key.equals(new ClientConfigMetricRequest()));
|
||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey
|
||||
.build(SNAPSHOT_DATA, dataKey);
|
||||
assertNotEquals(key, newOne);
|
||||
newOne.setType(CACHE_DATA);
|
||||
assertEquals(key, newOne);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMetricsHashCode() {
|
||||
public 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
|
||||
void testMetricsToString() {
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA,
|
||||
String.join("+", KEY));
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@ -47,14 +47,14 @@ 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(true, actual.isListen());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||
assertEquals(1, actual.getConfigListenContexts().size());
|
||||
assertEquals(actual.isListen(), true);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
assertEquals(actual.getConfigListenContexts().size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConfigListenContextToString() {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
||||
configChangeNotifyRequest.putAllHeader(HEADERS);
|
||||
requestId = injectRequestUuId(configChangeNotifyRequest);
|
||||
@ -54,10 +54,10 @@ 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(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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigPublishRequest configPublishRequest;
|
||||
|
||||
private static final String TAG_PARAM = "tag";
|
||||
|
||||
private static final String APP_NAME_PARAM = "appName";
|
||||
|
||||
ConfigPublishRequest configPublishRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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 @@ 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(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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigQueryRequest configQueryRequest;
|
||||
|
||||
@ -35,8 +35,8 @@ class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
String requestId;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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 @@ class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsNotify() {
|
||||
public void testIsNotify() {
|
||||
assertTrue(configQueryRequest.isNotify());
|
||||
}
|
||||
|
||||
@ -67,10 +67,10 @@ 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(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(TAG, actual.getTag());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
}
|
||||
}
|
||||
|
@ -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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigRemoveRequest configRemoveRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public void before() {
|
||||
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
||||
requestId = injectRequestUuId(configRemoveRequest);
|
||||
|
||||
@ -56,10 +56,10 @@ 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(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(TAG, actual.getTag());
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
}
|
||||
}
|
||||
|
@ -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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
||||
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
||||
configChangeClusterSyncRequest.setGroup(GROUP);
|
||||
@ -64,16 +64,15 @@ 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(DATA_ID, actual.getDataId());
|
||||
assertEquals(GROUP, actual.getGroup());
|
||||
assertEquals(TENANT, actual.getTenant());
|
||||
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||
assertEquals(0L, actual.getLastModified());
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getLastModified(), 0L);
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
@ -33,8 +33,8 @@ public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
Map<String, Object> metric = new HashMap<>(16);
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||
public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
||||
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
||||
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
||||
@ -50,8 +50,8 @@ 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||
public class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigPublishResponse configPublishResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||
public class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigQueryResponse configQueryResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||
public class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigRemoveResponse configRemoveResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
||||
|
||||
@BeforeEach
|
||||
void before() {
|
||||
@Before
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
class NacosExceptionTest {
|
||||
public class NacosExceptionTest {
|
||||
|
||||
@Test
|
||||
void testEmptyConstructor() {
|
||||
public void testEmptyConstructor() {
|
||||
NacosException exception = new NacosException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||
@ -35,7 +35,7 @@ class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithErrMsg() {
|
||||
public void testConstructorWithErrMsg() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
@ -43,7 +43,7 @@ class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithCause() {
|
||||
public 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 @@ class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithMultiCauses() {
|
||||
public 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 @@ class NacosExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithFull() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
class NacosApiExceptionTest {
|
||||
public class NacosApiExceptionTest {
|
||||
|
||||
@Test
|
||||
void testEmptyConstructor() {
|
||||
public void testEmptyConstructor() {
|
||||
NacosApiException exception = new NacosApiException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(0, exception.getDetailErrCode());
|
||||
@ -34,7 +34,7 @@ class NacosApiExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithoutCause() {
|
||||
public 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 @@ class NacosApiExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithCause() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class NacosDeserializationExceptionTest {
|
||||
public class NacosDeserializationExceptionTest {
|
||||
|
||||
@Test
|
||||
void testEmptyConstructor() {
|
||||
public void testEmptyConstructor() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException();
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -36,7 +36,7 @@ class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithTargetClass() {
|
||||
public void testConstructorWithTargetClass() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class);
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
@ -46,7 +46,7 @@ class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithTargetType() {
|
||||
public 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 @@ class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithCause() {
|
||||
public 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 @@ class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithTargetClassAndCause() {
|
||||
public void testConstructorWithTargetClassAndCause() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
@ -75,7 +75,7 @@ class NacosDeserializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithTargetTypeAndCause() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class NacosLoadExceptionTest {
|
||||
public class NacosLoadExceptionTest {
|
||||
|
||||
@Test
|
||||
void testConstructor() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class NacosRuntimeExceptionTest {
|
||||
public class NacosRuntimeExceptionTest {
|
||||
|
||||
@Test
|
||||
void testConstructorWithErrorCode() {
|
||||
public void testConstructorWithErrorCode() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -34,7 +34,7 @@ class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithErrorCodeAndMsg() {
|
||||
public 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 @@ class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithErrorCodeAndCause() {
|
||||
public void testConstructorWithErrorCodeAndCause() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
@ -51,9 +51,9 @@ class NacosRuntimeExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithFull() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test",
|
||||
new RuntimeException("cause test"));
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class NacosSerializationExceptionTest {
|
||||
public class NacosSerializationExceptionTest {
|
||||
|
||||
@Test
|
||||
void testEmptyConstructor() {
|
||||
public void testEmptyConstructor() {
|
||||
NacosSerializationException exception = new NacosSerializationException();
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
@ -33,7 +33,7 @@ class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithSerializedClass() {
|
||||
public 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 @@ class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithCause() {
|
||||
public 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 @@ class NacosSerializationExceptionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorWithSerializedClassAndCause() {
|
||||
public void testConstructorWithSerializedClassAndCause() {
|
||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class ResultTest {
|
||||
public class ResultTest {
|
||||
|
||||
@Test
|
||||
void testSuccessEmptyResult() {
|
||||
public void testSuccessEmptyResult() {
|
||||
Result<String> result = Result.success();
|
||||
assertNull(result.getData());
|
||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||
@ -32,7 +32,7 @@ class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccessWithData() {
|
||||
public void testSuccessWithData() {
|
||||
Result<String> result = Result.success("test");
|
||||
assertEquals("test", result.getData());
|
||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||
@ -40,7 +40,7 @@ class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailureMessageResult() {
|
||||
public void testFailureMessageResult() {
|
||||
Result<String> result = Result.failure("test");
|
||||
assertNull(result.getData());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
||||
@ -48,7 +48,7 @@ class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailureWithoutData() {
|
||||
public 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 @@ class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailureWithData() {
|
||||
public 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 @@ class ResultTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClientNamingAbilityTest {
|
||||
public class ClientNamingAbilityTest {
|
||||
|
||||
@Test
|
||||
void testGetAndSet() {
|
||||
public void testGetAndSet() {
|
||||
ClientNamingAbility ability = new ClientNamingAbility();
|
||||
assertFalse(ability.isSupportDeltaPush());
|
||||
assertFalse(ability.isSupportRemoteMetric());
|
||||
|
@ -20,33 +20,34 @@ 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
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.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServerNamingAbilityTest {
|
||||
public class ServerNamingAbilityTest {
|
||||
|
||||
private static ObjectMapper jacksonMapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUpClass() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||
public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||
String nonExistItemJson = "{\"exampleAbility\":false}";
|
||||
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
||||
assertFalse(actual.isSupportJraft());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() throws JsonProcessingException {
|
||||
public void testEquals() throws JsonProcessingException {
|
||||
ServerNamingAbility expected = new ServerNamingAbility();
|
||||
expected.setSupportJraft(true);
|
||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||
@ -59,19 +60,19 @@ class ServerNamingAbilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsForOneObject() {
|
||||
public void testEqualsForOneObject() {
|
||||
ServerNamingAbility ability = new ServerNamingAbility();
|
||||
assertEquals(ability, ability);
|
||||
assertTrue(ability.equals(ability));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsForOtherAbility() {
|
||||
public void testEqualsForOtherAbility() {
|
||||
ServerNamingAbility ability = new ServerNamingAbility();
|
||||
assertNotEquals(ability, new ClientNamingAbility());
|
||||
assertFalse(ability.equals(new ClientNamingAbility()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHashCode() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class NamingEventTest {
|
||||
public class NamingEventTest {
|
||||
|
||||
private MockNamingEventListener eventListener;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
eventListener = new MockNamingEventListener();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNamingEventWithSimpleConstructor() {
|
||||
public void testNamingEventWithSimpleConstructor() {
|
||||
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
||||
assertEquals("serviceName", event.getServiceName());
|
||||
assertNull(event.getGroupName());
|
||||
@ -49,7 +49,7 @@ class NamingEventTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNamingEventWithFullConstructor() {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ClusterTest {
|
||||
public class ClusterTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAndGet() {
|
||||
public void testSetAndGet() {
|
||||
Cluster actual = new Cluster();
|
||||
assertNull(actual.getName());
|
||||
assertNull(actual.getServiceName());
|
||||
@ -72,7 +72,7 @@ class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJsonSerialize() throws JsonProcessingException {
|
||||
public void testJsonSerialize() throws JsonProcessingException {
|
||||
Cluster actual = new Cluster("cluster");
|
||||
actual.setServiceName("group@@service");
|
||||
actual.setHealthChecker(new Http());
|
||||
@ -91,7 +91,7 @@ class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJsonDeserialize() throws JsonProcessingException {
|
||||
public 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,31 +22,30 @@ 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class InstanceTest {
|
||||
public class InstanceTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAndGet() {
|
||||
public void testSetAndGet() {
|
||||
Instance instance = new Instance();
|
||||
assertNull(instance.getInstanceId());
|
||||
assertNull(instance.getIp());
|
||||
@ -63,7 +62,7 @@ class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJsonSerialize() throws JsonProcessingException {
|
||||
public void testJsonSerialize() throws JsonProcessingException {
|
||||
Instance instance = new Instance();
|
||||
setInstance(instance);
|
||||
String actual = mapper.writeValueAsString(instance);
|
||||
@ -83,7 +82,7 @@ class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJsonDeserialize() throws JsonProcessingException {
|
||||
public 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,"
|
||||
@ -93,21 +92,21 @@ class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckClusterNameFormat() {
|
||||
public void testCheckClusterNameFormat() {
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("demo");
|
||||
assertEquals("demo", instance.getClusterName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToInetAddr() {
|
||||
public void testToInetAddr() {
|
||||
Instance instance = new Instance();
|
||||
setInstance(instance);
|
||||
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testContainsMetadata() {
|
||||
public void testContainsMetadata() {
|
||||
Instance instance = new Instance();
|
||||
assertFalse(instance.containsMetadata("a"));
|
||||
instance.setMetadata(null);
|
||||
@ -117,7 +116,7 @@ class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetInstanceIdGenerator() {
|
||||
public void testGetInstanceIdGenerator() {
|
||||
Instance instance = new Instance();
|
||||
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
||||
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
||||
@ -125,19 +124,19 @@ class InstanceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
public void testEquals() {
|
||||
Instance actual = new Instance();
|
||||
setInstance(actual);
|
||||
actual.setMetadata(new HashMap<>());
|
||||
actual.addMetadata("a", "b");
|
||||
assertNotEquals(actual, new Object());
|
||||
assertFalse(actual.equals(new Object()));
|
||||
Instance expected = new Instance();
|
||||
setInstance(expected);
|
||||
expected.setMetadata(new HashMap<>());
|
||||
expected.addMetadata("a", "b");
|
||||
assertEquals(actual, expected);
|
||||
assertTrue(actual.equals(expected));
|
||||
expected.addMetadata("a", "c");
|
||||
assertNotEquals(actual, expected);
|
||||
assertFalse(actual.equals(expected));
|
||||
}
|
||||
|
||||
private void setInstance(Instance instance) {
|
||||
|
@ -16,19 +16,19 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class ListViewTest {
|
||||
public class ListViewTest {
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
public void testToString() {
|
||||
List<String> data = new LinkedList<>();
|
||||
data.add("1");
|
||||
data.add("2");
|
||||
@ -41,7 +41,7 @@ class ListViewTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAndGet() {
|
||||
public 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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -30,26 +30,25 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServiceInfoTest {
|
||||
public class ServiceInfoTest {
|
||||
|
||||
private ObjectMapper mapper;
|
||||
|
||||
private ServiceInfo serviceInfo;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String actual = mapper.writeValueAsString(serviceInfo);
|
||||
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
||||
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
||||
@ -65,7 +64,7 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws IOException {
|
||||
public 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);
|
||||
@ -83,14 +82,14 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetKey() {
|
||||
public void testGetKey() {
|
||||
String key = serviceInfo.getKey();
|
||||
assertEquals("G@@testName@@testClusters", key);
|
||||
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetKeyEncode() {
|
||||
public void testGetKeyEncode() {
|
||||
String key = serviceInfo.getKeyEncoded();
|
||||
String encodeName = null;
|
||||
try {
|
||||
@ -102,7 +101,7 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceInfoConstructor() {
|
||||
public void testServiceInfoConstructor() {
|
||||
String key1 = "group@@name";
|
||||
String key2 = "group@@name@@c2";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
@ -111,34 +110,32 @@ class ServiceInfoTest {
|
||||
assertEquals(key2, s2.getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServiceInfoConstructorWithError() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String key1 = "name";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
});
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testServiceInfoConstructorWithError() {
|
||||
String key1 = "name";
|
||||
ServiceInfo s1 = new ServiceInfo(key1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateForAllIps() {
|
||||
public void testValidateForAllIps() {
|
||||
serviceInfo.setAllIPs(true);
|
||||
assertTrue(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateForNullHosts() {
|
||||
public void testValidateForNullHosts() {
|
||||
serviceInfo.setHosts(null);
|
||||
assertFalse(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateForEmptyHosts() {
|
||||
public void testValidateForEmptyHosts() {
|
||||
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
||||
assertFalse(serviceInfo.validate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateForUnhealthyHosts() {
|
||||
public void testValidateForUnhealthyHosts() {
|
||||
Instance instance = new Instance();
|
||||
instance.setHealthy(false);
|
||||
serviceInfo.addHost(instance);
|
||||
@ -146,7 +143,7 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||
public void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||
List<Instance> instanceList = new LinkedList<>();
|
||||
Instance instance = new Instance();
|
||||
instanceList.add(instance);
|
||||
@ -158,7 +155,7 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromKey() {
|
||||
public void testFromKey() {
|
||||
String key1 = "group@@name";
|
||||
String key2 = "group@@name@@c2";
|
||||
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
||||
@ -168,7 +165,7 @@ class ServiceInfoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAndGet() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServiceTest {
|
||||
public class ServiceTest {
|
||||
|
||||
@Test
|
||||
void testSetAndGet() {
|
||||
public void testSetAndGet() {
|
||||
Service service = new Service();
|
||||
assertNull(service.getName());
|
||||
assertNull(service.getAppName());
|
||||
@ -51,13 +51,12 @@ class ServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
public 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,16 +17,18 @@
|
||||
package com.alibaba.nacos.api.naming.pojo.builder;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
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;
|
||||
|
||||
class InstanceBuilderTest {
|
||||
public class InstanceBuilderTest {
|
||||
|
||||
private static final String SERVICE_NAME = "testService";
|
||||
|
||||
@ -51,26 +53,26 @@ class InstanceBuilderTest {
|
||||
private static final String META_VALUE = "value";
|
||||
|
||||
@Test
|
||||
void testBuildFullInstance() {
|
||||
public 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();
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuildInstanceWithoutNewMetadata() {
|
||||
public void testBuildInstanceWithoutNewMetadata() {
|
||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("test", "test");
|
||||
@ -79,8 +81,8 @@ class InstanceBuilderTest {
|
||||
assertNull(actual.getClusterName());
|
||||
assertNull(actual.getInstanceId());
|
||||
assertNull(actual.getIp());
|
||||
assertEquals(actual.getPort(), 0);
|
||||
assertEquals(actual.getWeight(), 1.0);
|
||||
assertThat(actual.getPort(), is(0));
|
||||
assertThat(actual.getWeight(), is(1.0));
|
||||
assertTrue(actual.isHealthy());
|
||||
assertTrue(actual.isEnabled());
|
||||
assertTrue(actual.isEphemeral());
|
||||
@ -88,15 +90,15 @@ class InstanceBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuildEmptyInstance() {
|
||||
public void testBuildEmptyInstance() {
|
||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||
Instance actual = builder.build();
|
||||
assertNull(actual.getServiceName());
|
||||
assertNull(actual.getClusterName());
|
||||
assertNull(actual.getInstanceId());
|
||||
assertNull(actual.getIp());
|
||||
assertEquals(actual.getPort(), 0);
|
||||
assertEquals(actual.getWeight(), 1.0);
|
||||
assertThat(actual.getPort(), is(0));
|
||||
assertThat(actual.getWeight(), is(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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class AbstractHealthCheckerTest {
|
||||
public class AbstractHealthCheckerTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@Before
|
||||
public void setUp() {
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
TestChecker testChecker = new TestChecker();
|
||||
testChecker.setTestValue("");
|
||||
String actual = objectMapper.writeValueAsString(testChecker);
|
||||
@ -48,7 +48,7 @@ class AbstractHealthCheckerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws IOException {
|
||||
public void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
||||
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
||||
assertEquals("", actual.getTestValue());
|
||||
@ -56,7 +56,7 @@ class AbstractHealthCheckerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
class HealthCheckTypeTest {
|
||||
public class HealthCheckTypeTest {
|
||||
|
||||
@Test
|
||||
void testOfHealthCheckerClassForBuildInType() {
|
||||
public void testOfHealthCheckerClassForBuildInType() {
|
||||
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
||||
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
||||
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
||||
@ -37,18 +37,18 @@ class HealthCheckTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOfHealthCheckerClassForExtendType() {
|
||||
public void testOfHealthCheckerClassForExtendType() {
|
||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOfHealthCheckerClassForNonExistType() {
|
||||
public void testOfHealthCheckerClassForNonExistType() {
|
||||
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetLoadedHealthCheckerClasses() {
|
||||
public void testGetLoadedHealthCheckerClasses() {
|
||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
||||
assertEquals(5, actual.size());
|
||||
|
@ -19,80 +19,75 @@ 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class HealthCheckerFactoryTest {
|
||||
public class HealthCheckerFactoryTest {
|
||||
|
||||
@BeforeAll
|
||||
static void beforeClass() {
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
HealthCheckerFactory.registerSubType(new TestChecker());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() {
|
||||
public void testSerialize() {
|
||||
Tcp tcp = new Tcp();
|
||||
String actual = HealthCheckerFactory.serialize(tcp);
|
||||
assertTrue(actual.contains("\"type\":\"TCP\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeExtend() {
|
||||
public void testSerializeExtend() {
|
||||
TestChecker testChecker = new TestChecker();
|
||||
String actual = HealthCheckerFactory.serialize(testChecker);
|
||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() {
|
||||
public void testDeserialize() {
|
||||
String tcpString = "{\"type\":\"TCP\"}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(Tcp.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserializeExtend() {
|
||||
public void testDeserializeExtend() {
|
||||
String tcpString = "{\"type\":\"TEST\",\"testValue\":null}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(TestChecker.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeNoRegister() {
|
||||
public void testSerializeNoRegister() {
|
||||
NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker();
|
||||
assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserializeNoRegister() {
|
||||
public void testDeserializeNoRegister() {
|
||||
String tcpString = "{\"type\":\"no register\",\"testValue\":null}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(AbstractHealthChecker.None.class, actual.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeFailure() {
|
||||
assertThrows(NacosSerializationException.class, () -> {
|
||||
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
|
||||
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
|
||||
});
|
||||
@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 testDeserializeFailure() {
|
||||
assertThrows(NacosDeserializationException.class, () -> {
|
||||
String errorString = "{\"type\"=\"TCP\"}";
|
||||
System.out.println(HealthCheckerFactory.deserialize(errorString));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateNoneHealthChecker() {
|
||||
public void testCreateNoneHealthChecker() {
|
||||
assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass());
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,6 @@ public class TestChecker extends AbstractHealthChecker {
|
||||
|
||||
private String testValue;
|
||||
|
||||
public TestChecker() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
public String getTestValue() {
|
||||
return testValue;
|
||||
}
|
||||
@ -40,6 +36,10 @@ public class TestChecker extends AbstractHealthChecker {
|
||||
this.testValue = testValue;
|
||||
}
|
||||
|
||||
public TestChecker() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
||||
return null;
|
||||
|
@ -18,37 +18,36 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class HttpTest {
|
||||
public class HttpTest {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private Http http;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@Before
|
||||
public void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
http = new Http();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetExpectedResponseCodeWithEmpty() {
|
||||
public void testGetExpectedResponseCodeWithEmpty() {
|
||||
http.setHeaders("");
|
||||
assertTrue(http.getCustomHeaders().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetExpectedResponseCodeWithoutEmpty() {
|
||||
public void testGetExpectedResponseCodeWithoutEmpty() {
|
||||
http.setHeaders("x:a|y:");
|
||||
Map<String, String> actual = http.getCustomHeaders();
|
||||
assertFalse(actual.isEmpty());
|
||||
@ -57,7 +56,7 @@ class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
http.setHeaders("x:a|y:");
|
||||
http.setPath("/x");
|
||||
String actual = objectMapper.writeValueAsString(http);
|
||||
@ -68,7 +67,7 @@ class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws IOException {
|
||||
public 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());
|
||||
@ -79,23 +78,23 @@ class HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
Http cloned = http.clone();
|
||||
assertEquals(http.hashCode(), cloned.hashCode());
|
||||
assertEquals(http, cloned);
|
||||
assertTrue(http.equals(cloned));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotEquals() throws CloneNotSupportedException {
|
||||
assertNotEquals(http, new Tcp());
|
||||
public void testNotEquals() throws CloneNotSupportedException {
|
||||
assertFalse(http.equals(new Tcp()));
|
||||
Http cloned = http.clone();
|
||||
cloned.setPath("aaa");
|
||||
assertNotEquals(http, cloned);
|
||||
assertFalse(http.equals(cloned));
|
||||
cloned = http.clone();
|
||||
cloned.setHeaders("aaa");
|
||||
assertNotEquals(http, cloned);
|
||||
assertFalse(http.equals(cloned));
|
||||
cloned = http.clone();
|
||||
cloned.setExpectedResponseCode(500);
|
||||
assertNotEquals(http, cloned);
|
||||
assertFalse(http.equals(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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class MysqlTest {
|
||||
public class MysqlTest {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private Mysql mysql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mysql = new Mysql();
|
||||
mysql.setUser("user");
|
||||
mysql.setPwd("pwd");
|
||||
@ -43,7 +43,7 @@ class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String actual = objectMapper.writeValueAsString(mysql);
|
||||
assertTrue(actual.contains("\"user\":\"user\""));
|
||||
assertTrue(actual.contains("\"type\":\"MYSQL\""));
|
||||
@ -52,7 +52,7 @@ class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws IOException {
|
||||
public 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 @@ class MysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
Mysql cloned = mysql.clone();
|
||||
assertEquals(mysql.hashCode(), cloned.hashCode());
|
||||
assertEquals(mysql, cloned);
|
||||
assertTrue(mysql.equals(cloned));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotEquals() throws CloneNotSupportedException {
|
||||
assertNotEquals(mysql, new Tcp());
|
||||
public void testNotEquals() throws CloneNotSupportedException {
|
||||
assertFalse(mysql.equals(new Tcp()));
|
||||
Mysql cloned = mysql.clone();
|
||||
cloned.setUser("aaa");
|
||||
assertNotEquals(mysql, cloned);
|
||||
assertFalse(mysql.equals(cloned));
|
||||
cloned = mysql.clone();
|
||||
cloned.setPwd("aaa");
|
||||
assertNotEquals(mysql, cloned);
|
||||
assertFalse(mysql.equals(cloned));
|
||||
cloned = mysql.clone();
|
||||
cloned.setCmd("aaa");
|
||||
assertNotEquals(mysql, cloned);
|
||||
assertFalse(mysql.equals(cloned));
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,18 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class TcpTest {
|
||||
public class TcpTest {
|
||||
|
||||
@Test
|
||||
void testClone() throws CloneNotSupportedException {
|
||||
public void testClone() throws CloneNotSupportedException {
|
||||
Tcp original = new Tcp();
|
||||
Tcp cloned = original.clone();
|
||||
assertEquals(original.hashCode(), cloned.hashCode());
|
||||
assertEquals(original, cloned);
|
||||
assertTrue(original.equals(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.jupiter.api.BeforeAll;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class BasedNamingRequestTest {
|
||||
|
||||
@ -35,7 +35,7 @@ public abstract class BasedNamingRequestTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
@BeforeClass
|
||||
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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
public class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public 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 @@ class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
public class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public 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 @@ class InstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class NotifySubscriberRequestTest {
|
||||
public class NotifySubscriberRequestTest {
|
||||
|
||||
private static final String SERVICE = "service";
|
||||
|
||||
@ -38,15 +38,15 @@ class NotifySubscriberRequestTest {
|
||||
|
||||
private static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE);
|
||||
NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo);
|
||||
request.setServiceName(SERVICE);
|
||||
@ -58,7 +58,7 @@ class NotifySubscriberRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
public class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public 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 @@ class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
public class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10);
|
||||
request.setSelector("label");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
@ -39,7 +39,7 @@ class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
public class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public 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 @@ class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true);
|
||||
String json = mapper.writeValueAsString(request);
|
||||
checkSerializeBasedInfo(json);
|
||||
@ -35,7 +35,7 @@ class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class BatchInstanceResponseTest {
|
||||
public class BatchInstanceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class InstanceResponseTest {
|
||||
public class InstanceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() throws JsonProcessingException {
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class QueryServiceResponseTest {
|
||||
public class QueryServiceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo());
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"serviceInfo\":{"));
|
||||
@ -49,7 +49,7 @@ class QueryServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test");
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"resultCode\":500"));
|
||||
@ -59,7 +59,7 @@ class QueryServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class ServiceListResponseTest {
|
||||
public class ServiceListResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
public 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 @@ class ServiceListResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ServiceListResponse response = ServiceListResponse.buildFailResponse("test");
|
||||
String json = mapper.writeValueAsString(response);
|
||||
assertTrue(json.contains("\"resultCode\":500"));
|
||||
@ -61,7 +61,7 @@ class ServiceListResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class SubscribeServiceResponseTest {
|
||||
public class SubscribeServiceResponseTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
public 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 @@ class SubscribeServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeFailResponse() throws JsonProcessingException {
|
||||
public 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 @@ class SubscribeServiceResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserialize() throws JsonProcessingException {
|
||||
public 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,117 +21,94 @@ 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.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class NamingUtilsTest {
|
||||
public class NamingUtilsTest {
|
||||
|
||||
@Test
|
||||
void testGetGroupedName() {
|
||||
public void testGetGroupedName() {
|
||||
assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupedNameWithoutGroup() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
NamingUtils.getGroupedName("serviceName", "");
|
||||
});
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetGroupedNameWithoutGroup() {
|
||||
NamingUtils.getGroupedName("serviceName", "");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetGroupedNameWithoutServiceName() {
|
||||
NamingUtils.getGroupedName("", "group");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupedNameWithoutServiceName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
NamingUtils.getGroupedName("", "group");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetServiceName() {
|
||||
public void testGetServiceName() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
assertEquals("serviceName", NamingUtils.getServiceName(validServiceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetServiceNameWithoutGroup() {
|
||||
public void testGetServiceNameWithoutGroup() {
|
||||
String serviceName = "serviceName";
|
||||
assertEquals(serviceName, NamingUtils.getServiceName(serviceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetServiceNameWithEmpty() {
|
||||
public void testGetServiceNameWithEmpty() {
|
||||
assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupName() {
|
||||
public void testGetGroupName() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
assertEquals("group", NamingUtils.getGroupName(validServiceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupNameWithoutGroup() {
|
||||
public void testGetGroupNameWithoutGroup() {
|
||||
String serviceName = "serviceName";
|
||||
assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetGroupNameWithEmpty() {
|
||||
public void testGetGroupNameWithEmpty() {
|
||||
assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
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() {
|
||||
public void testCheckServiceNameFormat() {
|
||||
String validServiceName = "group@@serviceName";
|
||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckServiceNameFormatWithoutGroupAndService() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
String validServiceName = "@@";
|
||||
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 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() {
|
||||
public void testGetGroupedNameOptional() {
|
||||
String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA");
|
||||
assertEquals("groupA@@", onlyGroupName);
|
||||
|
||||
@ -143,7 +120,7 @@ class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckInstanceIsLegal() throws NacosException {
|
||||
public void testCheckInstanceIsLegal() throws NacosException {
|
||||
// check invalid clusterName
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("cluster1,cluster2");
|
||||
@ -161,7 +138,7 @@ 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");
|
||||
@ -173,7 +150,8 @@ 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");
|
||||
@ -184,7 +162,7 @@ class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBatchCheckInstanceIsLegal() throws NacosException {
|
||||
public void testBatchCheckInstanceIsLegal() throws NacosException {
|
||||
// check invalid clusterName
|
||||
Instance instance = new Instance();
|
||||
instance.setClusterName("cluster1,cluster2");
|
||||
@ -221,7 +199,8 @@ 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);
|
||||
@ -236,7 +215,7 @@ class NamingUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckInstanceIsEphemeral() throws NacosException {
|
||||
public void testCheckInstanceIsEphemeral() throws NacosException {
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("127.0.0.1");
|
||||
instance.setPort(9089);
|
||||
@ -249,12 +228,12 @@ class NamingUtilsTest {
|
||||
instance.setEphemeral(false);
|
||||
NamingUtils.checkInstanceIsEphemeral(instance);
|
||||
} catch (NacosException e) {
|
||||
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCheckInstanceIsNull() throws NacosException {
|
||||
public void testCheckInstanceIsNull() throws NacosException {
|
||||
Instance instance = new Instance();
|
||||
instance.setIp("127.0.0.1");
|
||||
instance.setPort(9089);
|
||||
@ -262,15 +241,15 @@ class NamingUtilsTest {
|
||||
try {
|
||||
NamingUtils.checkInstanceIsLegal(null);
|
||||
} catch (NacosException e) {
|
||||
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsNumber() {
|
||||
public void testIsNumber() {
|
||||
String str1 = "abc";
|
||||
assertFalse(NamingUtils.isNumber(str1));
|
||||
|
||||
assertTrue(!NamingUtils.isNumber(str1));
|
||||
|
||||
String str2 = "123456";
|
||||
assertTrue(NamingUtils.isNumber(str2));
|
||||
}
|
||||
|
@ -16,18 +16,18 @@
|
||||
|
||||
package com.alibaba.nacos.api.remote;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class AbstractPushCallBackTest {
|
||||
public class AbstractPushCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
void testAbstractPushCallBack() {
|
||||
public 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.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class AbstractRequestCallBackTest {
|
||||
public class AbstractRequestCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
void testAbstractPushCallBack() {
|
||||
public void testAbstractPushCallBack() {
|
||||
AbstractRequestCallBack callBack = new AbstractRequestCallBack() {
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
|
@ -17,28 +17,27 @@
|
||||
package com.alibaba.nacos.api.remote;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
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.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
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.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DefaultRequestFutureTest {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultRequestFutureTest {
|
||||
|
||||
private static final String CONNECTION_ID = "1233_1.1.1.1_3306";
|
||||
|
||||
@ -52,17 +51,17 @@ class DefaultRequestFutureTest {
|
||||
|
||||
private long timestamp;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
public void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
@ -80,7 +79,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
public void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
@ -98,7 +97,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException {
|
||||
public void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
@ -116,7 +115,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException {
|
||||
public void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
@ -133,16 +132,14 @@ class DefaultRequestFutureTest {
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException {
|
||||
assertThrows(TimeoutException.class, () -> {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
requestFuture.get(100L);
|
||||
});
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
requestFuture.get(100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException {
|
||||
public void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
@ -162,7 +159,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException {
|
||||
public void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
@ -182,7 +179,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
public void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
@ -201,21 +198,19 @@ class DefaultRequestFutureTest {
|
||||
assertFalse(trigger.isTimeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
assertThrows(TimeoutException.class, () -> {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
try {
|
||||
requestFuture.get(100L);
|
||||
} finally {
|
||||
assertTrue(trigger.isTimeout);
|
||||
}
|
||||
});
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
try {
|
||||
requestFuture.get(100L);
|
||||
} finally {
|
||||
assertTrue(trigger.isTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
public void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(200L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
@ -234,7 +229,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException {
|
||||
public void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(executor, 200L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
@ -251,7 +246,7 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
public void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(1000L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
@ -270,11 +265,10 @@ class DefaultRequestFutureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testASyncGetResponseFailureWithTimeout() throws InterruptedException {
|
||||
public void testASyncGetResponseFailureWithTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(100L);
|
||||
final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback,
|
||||
trigger);
|
||||
final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
assertNull(callback.response);
|
||||
assertTrue(callback.exception instanceof TimeoutException);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user