Merge branch 'refs/heads/upstream-develop' into summer-ospp#10374
# Conflicts: # client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingService.java # client/src/main/java/com/alibaba/nacos/client/naming/cache/ServiceInfoHolder.java # client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingServiceTest.java # client/src/test/java/com/alibaba/nacos/client/naming/event/InstancesChangeEventTest.java # client/src/test/java/com/alibaba/nacos/client/naming/event/InstancesChangeNotifierTest.java
This commit is contained in:
commit
5f7801b341
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -44,6 +44,7 @@ jobs:
|
|||||||
- name: "Test With Maven"
|
- name: "Test With Maven"
|
||||||
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||||
- name: "Codecov"
|
- name: "Codecov"
|
||||||
uses: codecov/codecov-action@v3.1.0
|
uses: codecov/codecov-action@v4.0.1
|
||||||
with:
|
with:
|
||||||
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./plugin-default-impl/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
|
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 }}
|
2
.github/workflows/pr-ci.yml
vendored
2
.github/workflows/pr-ci.yml
vendored
@ -25,7 +25,7 @@ jobs:
|
|||||||
name: Upload distribution tar
|
name: Upload distribution tar
|
||||||
with:
|
with:
|
||||||
name: nacos
|
name: nacos
|
||||||
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
|
path: distribution/target/nacos-server-*.tar.gz
|
||||||
- name: Save PR number
|
- name: Save PR number
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ./pr
|
mkdir -p ./pr
|
||||||
|
490
.github/workflows/pr-e2e-test.yml
vendored
490
.github/workflows/pr-e2e-test.yml
vendored
@ -6,10 +6,11 @@ on:
|
|||||||
workflows: ["PR-CI"]
|
workflows: ["PR-CI"]
|
||||||
types:
|
types:
|
||||||
- completed
|
- completed
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||||
|
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
@ -22,6 +23,8 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
base-image: ["ubuntu"]
|
base-image: ["ubuntu"]
|
||||||
java-version: ["8"]
|
java-version: ["8"]
|
||||||
|
outputs:
|
||||||
|
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||||
steps:
|
steps:
|
||||||
- name: 'Download artifact'
|
- name: 'Download artifact'
|
||||||
uses: actions/github-script@v3.1.0
|
uses: actions/github-script@v3.1.0
|
||||||
@ -33,7 +36,7 @@ jobs:
|
|||||||
run_id: ${{ github.event.workflow_run.id }},
|
run_id: ${{ github.event.workflow_run.id }},
|
||||||
});
|
});
|
||||||
var matchArtifactNacos = artifacts.data.artifacts.filter((artifact) => {
|
var matchArtifactNacos = artifacts.data.artifacts.filter((artifact) => {
|
||||||
return artifact.name == "nacos"
|
return artifact.name == "nacos"
|
||||||
})[0];
|
})[0];
|
||||||
var download = await github.actions.downloadArtifact({
|
var download = await github.actions.downloadArtifact({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@ -47,64 +50,58 @@ jobs:
|
|||||||
unzip nacos.zip
|
unzip nacos.zip
|
||||||
mkdir nacos
|
mkdir nacos
|
||||||
cp -r nacos-* nacos/
|
cp -r nacos-* nacos/
|
||||||
ls
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: nacos-group/nacos-e2e.git
|
repository: nacos-group/nacos-e2e.git
|
||||||
ref: main
|
ref: main
|
||||||
path: nacos-e2e
|
path: nacos-e2e
|
||||||
- name: docker-login
|
- name: Generate image tag
|
||||||
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
|
id: build-images
|
||||||
run: |
|
run: |
|
||||||
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build
|
mv nacos-server-*.tar.gz nacos-e2e/cicd/build
|
||||||
cd nacos-e2e/cicd/build
|
cd nacos-e2e/cicd/build
|
||||||
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
||||||
mkdir versionlist
|
mkdir versionlist
|
||||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||||
ls versionlist/
|
ls versionlist/
|
||||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||||
echo $tag
|
- name: docker-login-1
|
||||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
uses: docker/login-action@v2
|
||||||
docker push ${DOCKER_REPO}:${tag}
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
name: Upload distribution tar
|
|
||||||
with:
|
with:
|
||||||
name: versionlist
|
registry: ${{ env.REGISTRY }}
|
||||||
path: nacos-e2e/cicd/build/versionlist/*
|
username: ${{ secrets.DOCKERHUB_USER }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
- name: save docker_1 images
|
||||||
list-version:
|
run: |
|
||||||
if: always()
|
mkdir build_backup
|
||||||
name: List version
|
cp -rf nacos-e2e/cicd/build/* ./build_backup/
|
||||||
needs: [docker]
|
cd nacos-e2e/cicd/build
|
||||||
runs-on: ubuntu-latest
|
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${{ env.TAG }} .
|
||||||
timeout-minutes: 30
|
docker push ${DOCKER_REPO}:${{ env.TAG }}
|
||||||
outputs:
|
- name: docker-login-2
|
||||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
uses: docker/login-action@v2
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v3
|
|
||||||
name: Download versionlist
|
|
||||||
with:
|
with:
|
||||||
name: versionlist
|
registry: ${{ env.REGISTRY }}
|
||||||
path: versionlist
|
username: ${{ secrets.DOCKERHUB_USER_B }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN_B }}
|
||||||
|
- name: save docker_2 images
|
||||||
|
run: |
|
||||||
|
rm -rf nacos-e2e/cicd/build/*
|
||||||
|
mv ./build_backup/* nacos-e2e/cicd/build/
|
||||||
|
cd nacos-e2e/cicd/build
|
||||||
|
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO_B}:${{ env.TAG }} .
|
||||||
|
docker push ${DOCKER_REPO_B}:${{ env.TAG }}
|
||||||
- name: Show versions
|
- name: Show versions
|
||||||
id: show_versions
|
id: show_versions
|
||||||
run: |
|
run: |
|
||||||
a=(`ls versionlist`)
|
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
if: ${{ success() }}
|
if: ${{ success() }}
|
||||||
name: Deploy nacos
|
name: Deploy nacos
|
||||||
needs: [list-version,docker]
|
needs: [docker]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
env:
|
env:
|
||||||
@ -112,99 +109,392 @@ jobs:
|
|||||||
DATABASE: mysql
|
DATABASE: mysql
|
||||||
NODE_PORT: 30000
|
NODE_PORT: 30000
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- name: set nodeport
|
- name: set nodeport
|
||||||
run: |
|
run: |
|
||||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||||
- name: set cluster params
|
- name: set cluster params
|
||||||
if: ${{ matrix.mode == 'standalone' }}
|
if: ${{ matrix.mode == 'standalone' }}
|
||||||
run: |
|
run: |
|
||||||
echo "::set-env name=REPLICA_COUNT::1"
|
echo "REPLICA_COUNT=1" >> $GITHUB_ENV
|
||||||
echo "::set-env name=DATABASE::embedded"
|
echo "DATABASE=embedded" >> $GITHUB_ENV
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- name: allocate docker repo
|
||||||
|
run: |
|
||||||
|
if [[ $(expr $(expr ${{ github.run_id }} + ${{ strategy.job-index }} ) % 2 ) -eq 1 ]]; then
|
||||||
|
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO }}" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO_B }}" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: Deploy nacos
|
name: Deploy nacos
|
||||||
with:
|
with:
|
||||||
action: "deploy"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: deploy
|
||||||
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 }}
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
global:
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
mode: ${{ matrix.mode }}
|
waitTimes: 2000
|
||||||
nacos:
|
velaAppDescription: nacos-${{ env.GITHUB_WORKFLOW }}-${{ github.run_id }}@${{ matrix.version }}
|
||||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
repoName: nacos
|
||||||
image:
|
helm:
|
||||||
repository: ${{ env.DOCKER_REPO }}
|
chart: ./cicd/helm
|
||||||
tag: ${{ matrix.version }}
|
git:
|
||||||
storage:
|
branch: main
|
||||||
type: ${{ env.DATABASE }}
|
repoType: git
|
||||||
db:
|
retries: 3
|
||||||
port: 3306
|
url: https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git
|
||||||
username: nacos
|
values:
|
||||||
password: nacos
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
global:
|
||||||
service:
|
mode: ${{ matrix.mode }}
|
||||||
nodePort: ${{ env.NODE_PORT }}
|
nacos:
|
||||||
type: ClusterIP
|
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||||
e2e-test:
|
image:
|
||||||
|
repository: ${{ env.DOCKER_REPO_ACTUAL }}
|
||||||
|
tag: ${{ matrix.version }}
|
||||||
|
storage:
|
||||||
|
type: ${{ env.DATABASE }}
|
||||||
|
db:
|
||||||
|
port: 3306
|
||||||
|
username: nacos
|
||||||
|
password: nacos
|
||||||
|
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||||
|
service:
|
||||||
|
nodePort: ${{ env.NODE_PORT }}
|
||||||
|
type: ClusterIP
|
||||||
|
e2e-java-test:
|
||||||
if: ${{ success() }}
|
if: ${{ success() }}
|
||||||
name: E2E Test
|
name: Java e2e Test
|
||||||
needs: [list-version, deploy]
|
needs: [docker, deploy]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: e2e test
|
name: java e2e test
|
||||||
with:
|
with:
|
||||||
action: "test"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: test
|
||||||
test-version: "${{ matrix.version }}"
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
test-code-branch: "master"
|
API_VERSION: v1
|
||||||
test-code-path: "java/nacos-2X"
|
KIND: Pod
|
||||||
test-cmd: 'mvn clean test -B'
|
RESTART_POLICY: Never
|
||||||
job-id: ${{ strategy.job-index }}
|
ENV:
|
||||||
- name: Publish Test Report
|
WAIT_TIME: 900
|
||||||
uses: mikepenz/action-junit-report@v3
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
if: always() # always run even if the previous step fails
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
with:
|
BRANCH: main
|
||||||
report_paths: '**/test_report/TEST-*.xml'
|
CODE_PATH: java/nacos-2X
|
||||||
annotate_only: true
|
CMD: mvn clean test -B
|
||||||
include_passed: true
|
ALL_IP: null
|
||||||
detailed_summary: true
|
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
|
- uses: actions/upload-artifact@v3
|
||||||
if: always()
|
if: always()
|
||||||
name: Upload test log
|
name: Upload test log
|
||||||
with:
|
with:
|
||||||
name: testlog.txt ${{ matrix.mode }}
|
name: testlog-${{ matrix.mode }}-java.txt
|
||||||
path: testlog.txt
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
|
||||||
|
e2e-go-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: GO E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: go e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: golang
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/golang && go mod init nacos_go_test && go mod tidy
|
||||||
|
gotestsum --junitfile ./target/surefire-reports/TEST-report.xml ./nacosgotest
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-go.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-cpp-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Cpp E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: cpp e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: cpp
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/cpp && make install
|
||||||
|
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc && source ~/.bashrc
|
||||||
|
cd /root/code/cpp/nacoscpptest
|
||||||
|
g++ nacos_test.cpp -o nacos_test -lgtest -lpthread -I/usr/local/include/nacos/ -L/usr/local/lib/ -lnacos-cli
|
||||||
|
chmod 777 nacos_test && ./nacos_test --gtest_output="xml:../target/surefire-reports/TEST-gtestresults.xml"
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-cpp.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-csharp-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Csharp E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: csharp e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: csharp
|
||||||
|
CMD: |
|
||||||
|
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
|
||||||
|
yum -y install dotnet-sdk-3.1 && yum -y install aspnetcore-runtime-7.0
|
||||||
|
cd /root/code/csharp/nacos-csharp-sdk-test && dotnet restore
|
||||||
|
dotnet test --logger:"junit;LogFilePath=../target/surefire-reports/TEST-result.xml"
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-csharp.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-nodejs-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Nodejs E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: nodejs e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: nodejs
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/nodejs/nacosnodejstest && npm install
|
||||||
|
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=../target/surefire-reports/TEST-report.xml
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-nodejs.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-python-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Python E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: python e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: python
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/python
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
source ~/.bashrc
|
||||||
|
cd nacospythontest && pytest --junitxml ../target/surefire-reports/TEST-report.xml test/*_test.py --log-cli-level=DEBUG
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-python.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
if: always()
|
if: always()
|
||||||
name: Clean
|
name: Clean
|
||||||
needs: [list-version, e2e-test]
|
needs: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: clean
|
name: clean
|
||||||
with:
|
with:
|
||||||
action: "clean"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: clean
|
||||||
test-version: "${{ matrix.version }}"
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
job-id: ${{ strategy.job-index }}
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
488
.github/workflows/push-ci.yaml
vendored
488
.github/workflows/push-ci.yaml
vendored
@ -5,15 +5,15 @@ on:
|
|||||||
branches: [master, develop, v1.x-develop, v1.X]
|
branches: [master, develop, v1.x-develop, v1.X]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read # to fetch code (actions/checkout)
|
contents: read
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: nacos-${{ github.ref }}
|
group: nacos-${{ github.ref }}
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
DOCKER_REPO_B: wuyfeehub/nacos-ci
|
||||||
|
TEST_REPO_NAME: nacos-group/nacos-e2e
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
dist-tar:
|
dist-tar:
|
||||||
@ -42,7 +42,7 @@ jobs:
|
|||||||
name: Upload distribution tar
|
name: Upload distribution tar
|
||||||
with:
|
with:
|
||||||
name: nacos
|
name: nacos
|
||||||
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
|
path: distribution/target/nacos-server-*.tar.gz
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
if: ${{ success() }}
|
if: ${{ success() }}
|
||||||
@ -50,10 +50,15 @@ jobs:
|
|||||||
needs: [dist-tar]
|
needs: [dist-tar]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
env:
|
||||||
|
DOCKERHUB_USER_ACTUAL: ${{ secrets.DOCKERHUB_USER }}
|
||||||
|
DOCKERHUB_TOKEN_ACTUAL: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
base-image: ["centos"]
|
base-image: ["centos"]
|
||||||
java-version: ["8"]
|
java-version: ["8"]
|
||||||
|
outputs:
|
||||||
|
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
@ -65,57 +70,53 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: nacos
|
name: nacos
|
||||||
path: ./
|
path: ./
|
||||||
- name: docker-login
|
- name: Generate image tag
|
||||||
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
|
id: build-images
|
||||||
run: |
|
run: |
|
||||||
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build/
|
mv nacos-server-*.tar.gz nacos-e2e/cicd/build/
|
||||||
cd nacos-e2e/cicd/build
|
cd nacos-e2e/cicd/build
|
||||||
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
||||||
mkdir versionlist
|
mkdir versionlist
|
||||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||||
ls versionlist/
|
ls versionlist/
|
||||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
echo TAG=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g") >> $GITHUB_ENV
|
||||||
echo $tag
|
- name: docker-login-1
|
||||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
uses: docker/login-action@v2
|
||||||
docker push ${DOCKER_REPO}:${tag}
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
name: Upload distribution tar
|
|
||||||
with:
|
with:
|
||||||
name: versionlist
|
registry: ${{ env.REGISTRY }}
|
||||||
path: nacos-e2e/cicd/build/versionlist/*
|
username: ${{ secrets.DOCKERHUB_USER }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
- name: save docker_1 images
|
||||||
list-version:
|
run: |
|
||||||
if: always()
|
mkdir build_backup
|
||||||
name: List version
|
cp -rf nacos-e2e/cicd/build/* ./build_backup/
|
||||||
needs: [docker]
|
cd nacos-e2e/cicd/build
|
||||||
runs-on: ubuntu-latest
|
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${{ env.TAG }} .
|
||||||
timeout-minutes: 30
|
docker push ${DOCKER_REPO}:${{ env.TAG }}
|
||||||
outputs:
|
- name: docker-login-2
|
||||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
uses: docker/login-action@v2
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v3
|
|
||||||
name: Download versionlist
|
|
||||||
with:
|
with:
|
||||||
name: versionlist
|
registry: ${{ env.REGISTRY }}
|
||||||
path: versionlist
|
username: ${{ secrets.DOCKERHUB_USER_B }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN_B }}
|
||||||
|
- name: save docker_2 images
|
||||||
|
run: |
|
||||||
|
rm -rf nacos-e2e/cicd/build/*
|
||||||
|
mv ./build_backup/* nacos-e2e/cicd/build/
|
||||||
|
cd nacos-e2e/cicd/build
|
||||||
|
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO_B}:${{ env.TAG }} .
|
||||||
|
docker push ${DOCKER_REPO_B}:${{ env.TAG }}
|
||||||
- name: Show versions
|
- name: Show versions
|
||||||
id: show_versions
|
id: show_versions
|
||||||
run: |
|
run: |
|
||||||
a=(`ls versionlist`)
|
a=(`ls nacos-e2e/cicd/build/versionlist`)
|
||||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
if: ${{ success() }}
|
if: ${{ success() }}
|
||||||
name: Deploy nacos
|
name: Deploy nacos
|
||||||
needs: [list-version,docker]
|
needs: [docker]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
env:
|
env:
|
||||||
@ -123,99 +124,390 @@ jobs:
|
|||||||
DATABASE: mysql
|
DATABASE: mysql
|
||||||
NODE_PORT: 30000
|
NODE_PORT: 30000
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- name: set nodeport
|
- name: set nodeport
|
||||||
run: |
|
run: |
|
||||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
echo "NODE_PORT=$(expr $(expr $(expr $(expr ${{ strategy.job-index }} + 1) * ${{ github.run_number }}) % 30000) + 30000)" >> $GITHUB_ENV
|
||||||
- name: set cluster params
|
- name: set cluster params
|
||||||
if: ${{ matrix.mode == 'standalone' }}
|
if: ${{ matrix.mode == 'standalone' }}
|
||||||
run: |
|
run: |
|
||||||
echo "::set-env name=REPLICA_COUNT::1"
|
echo "REPLICA_COUNT=1" >> $GITHUB_ENV
|
||||||
echo "::set-env name=DATABASE::embedded"
|
echo "DATABASE=embedded" >> $GITHUB_ENV
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- name: allocate docker repo
|
||||||
|
run: |
|
||||||
|
if [[ $(expr $(expr ${{ github.run_id }} + ${{ strategy.job-index }} ) % 2 ) -eq 1 ]]; then
|
||||||
|
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO }}" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "DOCKER_REPO_ACTUAL=${{ env.DOCKER_REPO_B }}" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: Deploy nacos
|
name: Deploy nacos
|
||||||
with:
|
with:
|
||||||
action: "deploy"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: deploy
|
||||||
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 }}
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
global:
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
mode: ${{ matrix.mode }}
|
waitTimes: 2000
|
||||||
nacos:
|
velaAppDescription: nacos-${{ env.GITHUB_WORKFLOW }}-${{ github.run_id }}@${{ matrix.version }}
|
||||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
repoName: nacos
|
||||||
image:
|
helm:
|
||||||
repository: ${{ env.DOCKER_REPO }}
|
chart: ./cicd/helm
|
||||||
tag: ${{ matrix.version }}
|
git:
|
||||||
storage:
|
branch: main
|
||||||
type: ${{ env.DATABASE }}
|
repoType: git
|
||||||
db:
|
retries: 3
|
||||||
port: 3306
|
url: https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git
|
||||||
username: nacos
|
values:
|
||||||
password: nacos
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
global:
|
||||||
service:
|
mode: ${{ matrix.mode }}
|
||||||
nodePort: ${{ env.NODE_PORT }}
|
nacos:
|
||||||
type: ClusterIP
|
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||||
e2e-test:
|
image:
|
||||||
|
repository: ${{ env.DOCKER_REPO_ACTUAL }}
|
||||||
|
tag: ${{ matrix.version }}
|
||||||
|
storage:
|
||||||
|
type: ${{ env.DATABASE }}
|
||||||
|
db:
|
||||||
|
port: 3306
|
||||||
|
username: nacos
|
||||||
|
password: nacos
|
||||||
|
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||||
|
service:
|
||||||
|
nodePort: ${{ env.NODE_PORT }}
|
||||||
|
type: ClusterIP
|
||||||
|
e2e-java-test:
|
||||||
if: ${{ success() }}
|
if: ${{ success() }}
|
||||||
name: E2E Test
|
name: Java e2e Test
|
||||||
needs: [list-version, deploy]
|
needs: [docker, deploy]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: e2e test
|
name: java e2e test
|
||||||
with:
|
with:
|
||||||
action: "test"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: test
|
||||||
test-version: "${{ matrix.version }}"
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
test-code-branch: "main"
|
API_VERSION: v1
|
||||||
test-code-path: "java/nacos-2X"
|
KIND: Pod
|
||||||
test-cmd: 'mvn clean test -B'
|
RESTART_POLICY: Never
|
||||||
job-id: ${{ strategy.job-index }}
|
ENV:
|
||||||
- name: Publish Test Report
|
WAIT_TIME: 900
|
||||||
uses: mikepenz/action-junit-report@v3
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
if: always() # always run even if the previous step fails
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
with:
|
BRANCH: main
|
||||||
report_paths: '**/test_report/TEST-*.xml'
|
CODE_PATH: java/nacos-2X
|
||||||
annotate_only: true
|
CMD: mvn clean test -B
|
||||||
include_passed: true
|
ALL_IP: null
|
||||||
detailed_summary: true
|
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
|
- uses: actions/upload-artifact@v3
|
||||||
if: always()
|
if: always()
|
||||||
name: Upload test log
|
name: Upload test log
|
||||||
with:
|
with:
|
||||||
name: testlog.txt ${{ matrix.mode }}
|
name: testlog-${{ matrix.mode }}-java.txt
|
||||||
path: testlog.txt
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
|
||||||
|
e2e-go-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: GO E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: go e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: golang
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/golang && go mod init nacos_go_test && go mod tidy
|
||||||
|
gotestsum --junitfile ./target/surefire-reports/TEST-report.xml ./nacosgotest
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-go.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-cpp-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Cpp E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: cpp e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: cpp
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/cpp && make install
|
||||||
|
echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc && source ~/.bashrc
|
||||||
|
cd /root/code/cpp/nacoscpptest
|
||||||
|
g++ nacos_test.cpp -o nacos_test -lgtest -lpthread -I/usr/local/include/nacos/ -L/usr/local/lib/ -lnacos-cli
|
||||||
|
chmod 777 nacos_test && ./nacos_test --gtest_output="xml:../target/surefire-reports/TEST-gtestresults.xml"
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-cpp.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-csharp-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Csharp E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: csharp e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: csharp
|
||||||
|
CMD: |
|
||||||
|
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
|
||||||
|
yum -y install dotnet-sdk-3.1 && yum -y install aspnetcore-runtime-7.0
|
||||||
|
cd /root/code/csharp/nacos-csharp-sdk-test && dotnet restore
|
||||||
|
dotnet test --logger:"junit;LogFilePath=../target/surefire-reports/TEST-result.xml"
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-csharp.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-nodejs-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Nodejs E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: nodejs e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: nodejs
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/nodejs/nacosnodejstest && npm install
|
||||||
|
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=../target/surefire-reports/TEST-report.xml
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-nodejs.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
e2e-python-test:
|
||||||
|
if: ${{ success() }}
|
||||||
|
name: Python E2E Test
|
||||||
|
needs: [docker, deploy]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
mode: ["cluster","standalone"]
|
||||||
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
|
steps:
|
||||||
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
|
name: python e2e test
|
||||||
|
with:
|
||||||
|
yamlString: |
|
||||||
|
action: test
|
||||||
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
API_VERSION: v1
|
||||||
|
KIND: Pod
|
||||||
|
RESTART_POLICY: Never
|
||||||
|
ENV:
|
||||||
|
WAIT_TIME: 900
|
||||||
|
REPO_NAME: ${{ env.TEST_REPO_NAME }}
|
||||||
|
CODE: https://github.com/${{ env.TEST_REPO_NAME }}
|
||||||
|
BRANCH: main
|
||||||
|
CODE_PATH: python
|
||||||
|
CMD: |
|
||||||
|
cd /root/code/python && pip3 install -r requirements.txt && source ~/.bashrc
|
||||||
|
cd nacospythontest && pytest --junitxml ../target/surefire-reports/TEST-report.xml test/*_test.py --log-cli-level=DEBUG
|
||||||
|
ALL_IP: null
|
||||||
|
CONTAINER:
|
||||||
|
IMAGE: cloudnativeofalibabacloud/test-runner:v0.0.4
|
||||||
|
RESOURCE_LIMITS:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
RESOURCE_REQUIRE:
|
||||||
|
cpu: 2
|
||||||
|
memory: 2Gi
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
name: Upload test log
|
||||||
|
with:
|
||||||
|
name: testlog-${{ matrix.mode }}-python.txt
|
||||||
|
path: testlog.txt
|
||||||
|
- name: add markdown
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
cat result.md >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
if: always()
|
if: always()
|
||||||
name: Clean
|
name: Clean
|
||||||
needs: [list-version, e2e-test]
|
needs: [docker, e2e-java-test, e2e-go-test, e2e-cpp-test, e2e-csharp-test, e2e-nodejs-test, e2e-python-test]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
mode: ["cluster","standalone"]
|
mode: ["cluster","standalone"]
|
||||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
version: ${{ fromJSON(needs.docker.outputs.version-json) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
- uses: apache/rocketmq-test-tool@java-dev
|
||||||
name: clean
|
name: clean
|
||||||
with:
|
with:
|
||||||
action: "clean"
|
yamlString: |
|
||||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
action: clean
|
||||||
test-version: "${{ matrix.version }}"
|
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||||
job-id: ${{ strategy.job-index }}
|
askConfig: ${{ secrets.ASK_CONFIG_VIRGINA }}
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
* [#175] Support deregistering instance automatically.
|
* [#175] Support deregistering instance automatically.
|
||||||
* [#176] Naming client query instance method should bypass local cache at client start.
|
* [#176] Naming client query instance method should bypass local cache at client start.
|
||||||
* [#177] Console supports registering new empty service and delete empty service.
|
* [#177] Console supports registering new empty service and delete empty service.
|
||||||
* [#181] NPE when adding a instance if no leader in the raft cluster.
|
* [#181] NPE when adding an instance if no leader in the raft cluster.
|
||||||
* [#193] Configure host domain name cause nacos server cluster is unavailable.
|
* [#193] Configure host domain name cause nacos server cluster is unavailable.
|
||||||
* [#209] Disable service and cluster level customization in client registerInstance method.
|
* [#209] Disable service and cluster level customization in client registerInstance method.
|
||||||
* [#214] Please support Java 11.
|
* [#214] Please support Java 11.
|
||||||
|
10
README.md
10
README.md
@ -121,19 +121,21 @@ Contributors are welcomed to join Nacos project. Please check [CONTRIBUTING](./C
|
|||||||
* commits-nacos@googlegroups.com: Commits notice, very high frequency.
|
* 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).
|
* Join us from DingDing(Group 1: 21708933(full), Group 2: 30438813(full), Group 3: 31222241(full), Group 4: 12810027056).
|
||||||
|
|
||||||
![Nacos](https://img.alicdn.com/imgextra/i1/O1CN01ULSVXu1DRbANwVC6r_!!6000000000213-2-tps-666-884.png)
|
|
||||||
|
<img src="https://img.alicdn.com/imgextra/i4/O1CN01MI7re41xTrZNdB7Yv_!!6000000006445-0-tps-974-1228.jpg" width="500">
|
||||||
|
|
||||||
## Enterprise Service
|
## 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.
|
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
|
https://cn.aliyun.com/product/aliware/mse?spm=nacos-website.topbar.0.0.0
|
||||||
|
|
||||||
![image](https://user-images.githubusercontent.com/17695352/128659442-65b030b8-c5f4-4bb7-baa2-e5b3ef0cbc15.png)
|
<img src="https://img.alicdn.com/imgextra/i3/O1CN01RTfN7q1KUzX4TcH08_!!6000000001168-2-tps-864-814.png" width="500">
|
||||||
|
|
||||||
|
|
||||||
## Download
|
## 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
|
## 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.
|
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.
|
||||||
|
@ -96,7 +96,7 @@ public class AddressServerGeneratorManager {
|
|||||||
/**
|
/**
|
||||||
* Generate response ips.
|
* Generate response ips.
|
||||||
*
|
*
|
||||||
* @param instanceList a instance set will generate string response to client.
|
* @param instanceList an instance set will generate string response to client.
|
||||||
* @return the result of response to client
|
* @return the result of response to client
|
||||||
*/
|
*/
|
||||||
public String generateResponseIps(List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList) {
|
public String generateResponseIps(List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList) {
|
||||||
@ -113,7 +113,7 @@ public class AddressServerGeneratorManager {
|
|||||||
/**
|
/**
|
||||||
* Generate nacos service name.
|
* Generate nacos service name.
|
||||||
*
|
*
|
||||||
* @param rawServiceName the raw service name will not contains the {@link Constants#DEFAULT_GROUP}.
|
* @param rawServiceName the raw service name will not contain the {@link Constants#DEFAULT_GROUP}.
|
||||||
* @return the nacos service name
|
* @return the nacos service name
|
||||||
*/
|
*/
|
||||||
public String generateNacosServiceName(String rawServiceName) {
|
public String generateNacosServiceName(String rawServiceName) {
|
||||||
|
@ -16,22 +16,26 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.address.config;
|
package com.alibaba.nacos.address.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos web security configuration.
|
* nacos web security configuration.
|
||||||
|
*
|
||||||
* @author onewe
|
* @author onewe
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@Order(99)
|
public class AddressServerSecurityConfiguration {
|
||||||
public class AddressServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
@Order(99)
|
||||||
http.authorizeHttpRequests(requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated())
|
public SecurityFilterChain addressServerSecurityFilterChain(HttpSecurity http) throws Exception {
|
||||||
.csrf().disable().httpBasic();
|
http.authorizeHttpRequests(
|
||||||
|
requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated()).csrf()
|
||||||
|
.disable().httpBasic();
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,55 +18,59 @@ package com.alibaba.nacos.address.component;
|
|||||||
|
|
||||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AddressServerGeneratorManagerTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class AddressServerGeneratorManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateProductName() {
|
void testGenerateProductName() {
|
||||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||||
final String blankName = manager.generateProductName("");
|
final String blankName = manager.generateProductName("");
|
||||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
|
||||||
|
|
||||||
final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
|
final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
|
||||||
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
|
||||||
|
|
||||||
final String testName = manager.generateProductName("test");
|
final String testName = manager.generateProductName("test");
|
||||||
Assert.assertEquals("nacos.as.test", testName);
|
assertEquals("nacos.as.test", testName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateInstancesByIps() {
|
void testGenerateInstancesByIps() {
|
||||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||||
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
|
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
|
||||||
Assert.assertNotNull(empty);
|
assertNotNull(empty);
|
||||||
Assert.assertTrue(empty.isEmpty());
|
assertTrue(empty.isEmpty());
|
||||||
|
|
||||||
String[] ipArray = new String[]{"192.168.3.1:8848", "192.168.3.2:8848", "192.168.3.3:8848"};
|
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",
|
final List<Instance> instanceList = manager.generateInstancesByIps("DEFAULT_GROUP@@nacos.as.test", "test", "test",
|
||||||
ipArray);
|
ipArray);
|
||||||
Assert.assertNotNull(instanceList);
|
assertNotNull(instanceList);
|
||||||
Assert.assertFalse(instanceList.isEmpty());
|
assertFalse(instanceList.isEmpty());
|
||||||
Assert.assertEquals(3, instanceList.size());
|
assertEquals(3, instanceList.size());
|
||||||
|
|
||||||
final Instance instance1 = instanceList.get(0);
|
final Instance instance1 = instanceList.get(0);
|
||||||
Assert.assertEquals("192.168.3.1", instance1.getIp());
|
assertEquals("192.168.3.1", instance1.getIp());
|
||||||
|
|
||||||
final Instance instance2 = instanceList.get(1);
|
final Instance instance2 = instanceList.get(1);
|
||||||
Assert.assertEquals("192.168.3.2", instance2.getIp());
|
assertEquals("192.168.3.2", instance2.getIp());
|
||||||
|
|
||||||
final Instance instance3 = instanceList.get(2);
|
final Instance instance3 = instanceList.get(2);
|
||||||
Assert.assertEquals("192.168.3.3", instance3.getIp());
|
assertEquals("192.168.3.3", instance3.getIp());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateResponseIps() {
|
void testGenerateResponseIps() {
|
||||||
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
|
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
|
||||||
Instance instance1 = new Instance();
|
Instance instance1 = new Instance();
|
||||||
instance1.setIp("192.168.3.1");
|
instance1.setIp("192.168.3.1");
|
||||||
@ -92,19 +96,19 @@ public class AddressServerGeneratorManagerTest {
|
|||||||
.append("192.168.3.1:8848").append('\n')
|
.append("192.168.3.1:8848").append('\n')
|
||||||
.append("192.168.3.2:8848").append('\n')
|
.append("192.168.3.2:8848").append('\n')
|
||||||
.append("192.168.3.3:8848").append('\n');
|
.append("192.168.3.3:8848").append('\n');
|
||||||
Assert.assertEquals(ret.toString(), ipListStr);
|
assertEquals(ret.toString(), ipListStr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateNacosServiceName() {
|
void testGenerateNacosServiceName() {
|
||||||
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
|
||||||
|
|
||||||
final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
|
final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
|
||||||
Assert.assertEquals("DEFAULT_GROUP@@test", containDefault);
|
assertEquals("DEFAULT_GROUP@@test", containDefault);
|
||||||
|
|
||||||
final String product = manager.generateNacosServiceName("product");
|
final String product = manager.generateNacosServiceName("product");
|
||||||
Assert.assertEquals("DEFAULT_GROUP@@product", product);
|
assertEquals("DEFAULT_GROUP@@product", product);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,38 +17,38 @@
|
|||||||
package com.alibaba.nacos.address.component;
|
package com.alibaba.nacos.address.component;
|
||||||
|
|
||||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class AddressServerManagerTests {
|
class AddressServerManagerTests {
|
||||||
|
|
||||||
private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();
|
private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRawProductName() {
|
void getRawProductName() {
|
||||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT, ADDRESS_SERVER_MANAGER.getRawProductName(""));
|
assertEquals(AddressServerConstants.DEFAULT_PRODUCT, ADDRESS_SERVER_MANAGER.getRawProductName(""));
|
||||||
assertEquals(AddressServerConstants.DEFAULT_PRODUCT,
|
assertEquals(AddressServerConstants.DEFAULT_PRODUCT,
|
||||||
ADDRESS_SERVER_MANAGER.getRawProductName(AddressServerConstants.DEFAULT_PRODUCT));
|
ADDRESS_SERVER_MANAGER.getRawProductName(AddressServerConstants.DEFAULT_PRODUCT));
|
||||||
assertEquals("otherProduct", ADDRESS_SERVER_MANAGER.getRawProductName("otherProduct"));
|
assertEquals("otherProduct", ADDRESS_SERVER_MANAGER.getRawProductName("otherProduct"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultClusterNameIfEmpty() {
|
void getDefaultClusterNameIfEmpty() {
|
||||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(""));
|
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(""));
|
||||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER,
|
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER,
|
||||||
ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(AddressServerConstants.DEFAULT_GET_CLUSTER));
|
ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(AddressServerConstants.DEFAULT_GET_CLUSTER));
|
||||||
assertEquals("otherServerList", ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty("otherServerList"));
|
assertEquals("otherServerList", ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty("otherServerList"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRawClusterName() {
|
void testGetRawClusterName() {
|
||||||
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
|
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
|
||||||
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
|
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSplitIps() {
|
void testSplitIps() {
|
||||||
final String[] emptyArr = ADDRESS_SERVER_MANAGER.splitIps("");
|
final String[] emptyArr = ADDRESS_SERVER_MANAGER.splitIps("");
|
||||||
assertEquals(0, emptyArr.length);
|
assertEquals(0, emptyArr.length);
|
||||||
final String[] one = ADDRESS_SERVER_MANAGER.splitIps("192.168.1.12:8848");
|
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.ServiceManager;
|
||||||
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
|
||||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
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.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class AddressServerClusterControllerTest {
|
class AddressServerClusterControllerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private InstanceOperator instanceOperator;
|
private InstanceOperator instanceOperator;
|
||||||
@ -53,9 +53,9 @@ public class AddressServerClusterControllerTest {
|
|||||||
private ClusterOperator clusterOperator;
|
private ClusterOperator clusterOperator;
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
mockMvc = MockMvcBuilders.standaloneSetup(
|
mockMvc = MockMvcBuilders.standaloneSetup(
|
||||||
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
|
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
|
||||||
new AddressServerManager(), new AddressServerGeneratorManager())).build();
|
new AddressServerManager(), new AddressServerGeneratorManager())).build();
|
||||||
@ -63,30 +63,30 @@ public class AddressServerClusterControllerTest {
|
|||||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||||
ServiceManager.getInstance().getSingleton(service);
|
ServiceManager.getInstance().getSingleton(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
Service service = Service
|
Service service = Service
|
||||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||||
ServiceManager.getInstance().removeSingleton(service);
|
ServiceManager.getInstance().removeSingleton(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostCluster() throws Exception {
|
void testPostCluster() throws Exception {
|
||||||
|
|
||||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
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());
|
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostClusterWithErrorIps() throws Exception {
|
void testPostClusterWithErrorIps() throws Exception {
|
||||||
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostClusterThrowException() throws Exception {
|
void testPostClusterThrowException() throws Exception {
|
||||||
|
|
||||||
Mockito.doThrow(new NacosException(500, "create service error")).when(clusterOperator)
|
Mockito.doThrow(new NacosException(500, "create service error")).when(clusterOperator)
|
||||||
.updateClusterMetadata(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
.updateClusterMetadata(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||||
@ -97,34 +97,34 @@ public class AddressServerClusterControllerTest {
|
|||||||
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());
|
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteCluster() throws Exception {
|
void testDeleteCluster() throws Exception {
|
||||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
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());
|
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteClusterCannotFindService() throws Exception {
|
void testDeleteClusterCannotFindService() throws Exception {
|
||||||
tearDown();
|
tearDown();
|
||||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
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());
|
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteClusterEmptyIps() throws Exception {
|
void testDeleteClusterEmptyIps() throws Exception {
|
||||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||||
.param("ips", "")).andExpect(status().isBadRequest());
|
.param("ips", "")).andExpect(status().isBadRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteClusterErrorIps() throws Exception {
|
void testDeleteClusterErrorIps() throws Exception {
|
||||||
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
|
||||||
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteClusterThrowException() throws Exception {
|
void testDeleteClusterThrowException() throws Exception {
|
||||||
Mockito.doThrow(new NacosException(500, "remove service error")).when(instanceOperator)
|
Mockito.doThrow(new NacosException(500, "remove service error")).when(instanceOperator)
|
||||||
.removeInstance(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
.removeInstance(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
|
||||||
Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + "nacos.as.default"),
|
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.NamingMetadataManager;
|
||||||
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata;
|
||||||
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
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.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ServerListControllerTest {
|
class ServerListControllerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private NamingMetadataManager metadataManager;
|
private NamingMetadataManager metadataManager;
|
||||||
@ -55,23 +55,23 @@ public class ServerListControllerTest {
|
|||||||
private Service service;
|
private Service service;
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
this.mockMvc = MockMvcBuilders.standaloneSetup(
|
this.mockMvc = MockMvcBuilders.standaloneSetup(
|
||||||
new ServerListController(new AddressServerGeneratorManager(), metadataManager, serviceStorage)).build();
|
new ServerListController(new AddressServerGeneratorManager(), metadataManager, serviceStorage)).build();
|
||||||
service = Service
|
service = Service
|
||||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||||
ServiceManager.getInstance().getSingleton(service);
|
ServiceManager.getInstance().getSingleton(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
ServiceManager.getInstance().removeSingleton(service);
|
ServiceManager.getInstance().removeSingleton(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCluster() throws Exception {
|
void testGetCluster() throws Exception {
|
||||||
|
|
||||||
final Service service = Service
|
final Service service = Service
|
||||||
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
|
||||||
@ -86,16 +86,16 @@ public class ServerListControllerTest {
|
|||||||
when(serviceStorage.getData(service)).thenReturn(serviceInfo);
|
when(serviceStorage.getData(service)).thenReturn(serviceInfo);
|
||||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isOk());
|
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClusterCannotFindService() throws Exception {
|
void testGetClusterCannotFindService() throws Exception {
|
||||||
tearDown();
|
tearDown();
|
||||||
mockMvc.perform(get("/default/serverList")).andExpect(status().isNotFound());
|
mockMvc.perform(get("/default/serverList")).andExpect(status().isNotFound());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClusterCannotFindCluster() throws Exception {
|
void testGetClusterCannotFindCluster() throws Exception {
|
||||||
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isNotFound());
|
mockMvc.perform(get("/nacos/serverList")).andExpect(status().isNotFound());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String ENDPOINT_PORT = "endpointPort";
|
public static final String ENDPOINT_PORT = "endpointPort";
|
||||||
|
|
||||||
|
public static final String ENDPOINT_CONTEXT_PATH = "endpointContextPath";
|
||||||
|
|
||||||
public static final String SERVER_NAME = "serverName";
|
public static final String SERVER_NAME = "serverName";
|
||||||
|
|
||||||
public static final String NAMESPACE = "namespace";
|
public static final String NAMESPACE = "namespace";
|
||||||
@ -59,6 +61,10 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String CONFIG_RETRY_TIME = "configRetryTime";
|
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 MAX_RETRY = "maxRetry";
|
||||||
|
|
||||||
public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||||
@ -69,6 +75,8 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
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_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||||
|
|
||||||
public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";
|
public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";
|
||||||
@ -77,6 +85,12 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String NAMING_ASYNC_QUERY_SUBSCRIBE_SERVICE = "namingAsyncQuerySubscribeService";
|
public static final String NAMING_ASYNC_QUERY_SUBSCRIBE_SERVICE = "namingAsyncQuerySubscribeService";
|
||||||
|
|
||||||
|
public static final String REDO_DELAY_TIME = "redoDelayTime";
|
||||||
|
|
||||||
|
public static final String REDO_DELAY_THREAD_COUNT = "redoDelayThreadCount";
|
||||||
|
|
||||||
|
public static final String SIGNATURE_REGION_ID = "signatureRegionId";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the key value of some variable value from the system property.
|
* Get the key value of some variable value from the system property.
|
||||||
*/
|
*/
|
||||||
@ -84,6 +98,8 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
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_NAMESPACE = "ALIBABA_ALIWARE_NAMESPACE";
|
||||||
|
|
||||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||||
|
@ -28,6 +28,7 @@ import java.io.Serializable;
|
|||||||
* @author liuzunfei
|
* @author liuzunfei
|
||||||
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class ClientAbilities implements Serializable {
|
public class ClientAbilities implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -3590789441404549261L;
|
private static final long serialVersionUID = -3590789441404549261L;
|
||||||
|
@ -29,6 +29,7 @@ import java.util.Objects;
|
|||||||
* @author liuzunfei
|
* @author liuzunfei
|
||||||
* @version $Id: ServerAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
* @version $Id: ServerAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class ServerAbilities implements Serializable {
|
public class ServerAbilities implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2120543002911304171L;
|
private static final long serialVersionUID = -2120543002911304171L;
|
||||||
|
@ -0,0 +1,185 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.ability.constant;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability key constant. It is used to constrain the ability key.<br/>
|
||||||
|
* <strong>Ensure that return value of {@link AbilityKey#getName()} is unique under one specify {@link AbilityMode}</strong>.
|
||||||
|
*
|
||||||
|
* @author Daydreamer
|
||||||
|
* @date 2022/8/31 12:27
|
||||||
|
**/
|
||||||
|
public enum AbilityKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server support register or deregister persistent instance by grpc.
|
||||||
|
*/
|
||||||
|
SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC("supportPersistentInstanceByGrpc",
|
||||||
|
"support persistent instance by grpc", AbilityMode.SERVER),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Test temporarily.
|
||||||
|
*/
|
||||||
|
SERVER_TEST_1("test_1", "just for junit test", AbilityMode.SERVER),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Test temporarily.
|
||||||
|
*/
|
||||||
|
SERVER_TEST_2("test_2", "just for junit test", AbilityMode.SERVER),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Test temporarily.
|
||||||
|
*/
|
||||||
|
SDK_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.SDK_CLIENT),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Test temporarily.
|
||||||
|
*/
|
||||||
|
CLUSTER_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.CLUSTER_CLIENT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the name of a certain ability.
|
||||||
|
*/
|
||||||
|
private final String keyName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* description or comment about this ability.
|
||||||
|
*/
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ability mode, which endpoint hold this ability.
|
||||||
|
*/
|
||||||
|
private final AbilityMode mode;
|
||||||
|
|
||||||
|
AbilityKey(String keyName, String description, AbilityMode mode) {
|
||||||
|
this.keyName = keyName;
|
||||||
|
this.description = description;
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbilityMode getMode() {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All key set.
|
||||||
|
*/
|
||||||
|
private static final Map<AbilityMode, Map<String, AbilityKey>> ALL_ABILITIES = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all keys.
|
||||||
|
*
|
||||||
|
* @return all keys
|
||||||
|
*/
|
||||||
|
public static Collection<AbilityKey> getAllValues(AbilityMode mode) {
|
||||||
|
return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all names.
|
||||||
|
*
|
||||||
|
* @return all names
|
||||||
|
*/
|
||||||
|
public static Collection<String> getAllNames(AbilityMode mode) {
|
||||||
|
return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether contains this name.
|
||||||
|
*
|
||||||
|
* @param name key name
|
||||||
|
* @return whether contains
|
||||||
|
*/
|
||||||
|
public static boolean isLegalKey(AbilityMode mode, String name) {
|
||||||
|
return ALL_ABILITIES.get(mode).containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the string key to enum.
|
||||||
|
*
|
||||||
|
* @param abilities map
|
||||||
|
* @return enum map
|
||||||
|
*/
|
||||||
|
public static Map<AbilityKey, Boolean> mapEnum(AbilityMode mode, Map<String, Boolean> abilities) {
|
||||||
|
if (abilities == null || abilities.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
return abilities.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(entry -> isLegalKey(mode, entry.getKey()))
|
||||||
|
.collect(Collectors.toMap((entry) -> getEnum(mode, entry.getKey()), Map.Entry::getValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* Map the string key to enum
|
||||||
|
*
|
||||||
|
* @param abilities map
|
||||||
|
* @return enum map
|
||||||
|
*/
|
||||||
|
public static Map<String, Boolean> mapStr(Map<AbilityKey, Boolean> abilities) {
|
||||||
|
if (abilities == null || abilities.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
return abilities.entrySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap((entry) -> entry.getKey().getName(), Map.Entry::getValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* getter to obtain enum
|
||||||
|
*
|
||||||
|
* @param key string key
|
||||||
|
* @return enum
|
||||||
|
*/
|
||||||
|
public static AbilityKey getEnum(AbilityMode mode, String key) {
|
||||||
|
return ALL_ABILITIES.get(mode).get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
// check for developer
|
||||||
|
// ensure that name filed is unique under a AbilityMode
|
||||||
|
try {
|
||||||
|
for (AbilityKey value : AbilityKey.values()) {
|
||||||
|
AbilityMode mode = value.getMode();
|
||||||
|
Map<String, AbilityKey> map = ALL_ABILITIES.getOrDefault(mode, new HashMap<>());
|
||||||
|
AbilityKey previous = map.putIfAbsent(value.getName(), value);
|
||||||
|
if (previous != null) {
|
||||||
|
throw new IllegalStateException("Duplicate key name field " + value + " and " + previous + " under mode: " + mode);
|
||||||
|
}
|
||||||
|
ALL_ABILITIES.put(mode, map);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// for developer checking
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.ability.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ability mode.
|
||||||
|
*
|
||||||
|
* @author Daydreamer
|
||||||
|
* @date 2023/9/25 12:32
|
||||||
|
**/
|
||||||
|
public enum AbilityMode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for server ability.
|
||||||
|
*/
|
||||||
|
SERVER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for sdk client.
|
||||||
|
*/
|
||||||
|
SDK_CLIENT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for cluster client.
|
||||||
|
*/
|
||||||
|
CLUSTER_CLIENT;
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.ability.constant;
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* @author Daydreamer
|
||||||
|
* @description It is used to know a certain ability whether supporting.
|
||||||
|
* @date 2022/8/31 12:27
|
||||||
|
**/
|
||||||
|
public enum AbilityStatus {
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* Support a certain ability
|
||||||
|
*/
|
||||||
|
SUPPORTED,
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* Not support a certain ability
|
||||||
|
*/
|
||||||
|
NOT_SUPPORTED,
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* Cannot find ability table, unknown
|
||||||
|
*/
|
||||||
|
UNKNOWN
|
||||||
|
}
|
@ -21,6 +21,7 @@ package com.alibaba.nacos.api.ability.initializer;
|
|||||||
*
|
*
|
||||||
* @author xiweng.yy
|
* @author xiweng.yy
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface AbilityInitializer<A> {
|
public interface AbilityInitializer<A> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.ability.initializer;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityMode;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nacos ability post processor, load by spi.
|
||||||
|
*
|
||||||
|
* @author Daydreamer-ia
|
||||||
|
*/
|
||||||
|
public interface AbilityPostProcessor {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process before loading by <code>Ability Controller </code>.
|
||||||
|
*
|
||||||
|
* @param mode mode: sdk client, server or cluster client
|
||||||
|
* @param abilities abilities
|
||||||
|
*/
|
||||||
|
void process(AbilityMode mode, Map<AbilityKey, Boolean> abilities);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.ability.register;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* @author Daydreamer
|
||||||
|
* @description Operation for bit table.
|
||||||
|
* @date 2022/7/12 19:23
|
||||||
|
**/
|
||||||
|
public abstract class AbstractAbilityRegistry {
|
||||||
|
|
||||||
|
protected final Map<AbilityKey, Boolean> supportedAbilities = new HashMap<>();
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* get static ability current server supports
|
||||||
|
*
|
||||||
|
* @return static ability
|
||||||
|
*/
|
||||||
|
public Map<AbilityKey, Boolean> getSupportedAbilities() {
|
||||||
|
return Collections.unmodifiableMap(supportedAbilities);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.nacos.api.ability.register.impl;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is used to register cluster client abilities.
|
||||||
|
*
|
||||||
|
* @author Daydreamer
|
||||||
|
**/
|
||||||
|
public class ClusterClientAbilities extends AbstractAbilityRegistry {
|
||||||
|
|
||||||
|
private static final ClusterClientAbilities INSTANCE = new ClusterClientAbilities();
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* example:
|
||||||
|
* There is a function named "compression".
|
||||||
|
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||||
|
*
|
||||||
|
* You can add a new public field in <p>AbilityKey</p> like:
|
||||||
|
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||||
|
*
|
||||||
|
* And then you need to declare whether turn on in the ability table, you can:
|
||||||
|
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// put ability here, which you want current client supports
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get static ability current cluster client supports.
|
||||||
|
*
|
||||||
|
* @return static ability
|
||||||
|
*/
|
||||||
|
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||||
|
return INSTANCE.getSupportedAbilities();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.ability.register.impl;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is used to register client abilities.
|
||||||
|
*
|
||||||
|
* @author Daydreamer
|
||||||
|
* @date 2022/8/31 12:32
|
||||||
|
**/
|
||||||
|
public class SdkClientAbilities extends AbstractAbilityRegistry {
|
||||||
|
|
||||||
|
private static final SdkClientAbilities INSTANCE = new SdkClientAbilities();
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* example:
|
||||||
|
* There is a function named "compression".
|
||||||
|
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||||
|
*
|
||||||
|
* You can add a new public field in <p>AbilityKey</p> like:
|
||||||
|
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||||
|
*
|
||||||
|
* And then you need to declare whether turn on in the ability table, you can:
|
||||||
|
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// put ability here, which you want current client supports
|
||||||
|
}
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* get static ability current server supports
|
||||||
|
*
|
||||||
|
* @return static ability
|
||||||
|
*/
|
||||||
|
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||||
|
return INSTANCE.getSupportedAbilities();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.ability.register.impl;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is used to register server abilities.
|
||||||
|
*
|
||||||
|
* @author Daydreamer
|
||||||
|
* @date 2022/8/31 12:32
|
||||||
|
**/
|
||||||
|
public class ServerAbilities extends AbstractAbilityRegistry {
|
||||||
|
|
||||||
|
private static final ServerAbilities INSTANCE = new ServerAbilities();
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* example:
|
||||||
|
* There is a function named "compression".
|
||||||
|
* The key is from <p>AbilityKey</p>, the value is whether turn on.
|
||||||
|
*
|
||||||
|
* You can add a new public field in <p>AbilityKey</p> like:
|
||||||
|
* <code>DATA_COMPRESSION("compression", "description about this ability")</code>
|
||||||
|
*
|
||||||
|
* And then you need to declare whether turn on in the ability table, you can:
|
||||||
|
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// put ability here, which you want current server supports
|
||||||
|
supportedAbilities.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**.
|
||||||
|
* get static ability current server supports
|
||||||
|
*
|
||||||
|
* @return static ability
|
||||||
|
*/
|
||||||
|
public static Map<AbilityKey, Boolean> getStaticAbilities() {
|
||||||
|
return INSTANCE.getSupportedAbilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -138,7 +138,7 @@ public @interface NacosProperties {
|
|||||||
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";
|
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The placeholder of endpoint, the value is ${nacos.context-path:}".
|
* The placeholder of endpoint, the value is ${nacos.context-path:}.
|
||||||
*/
|
*/
|
||||||
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";
|
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String APPNAME = "AppName";
|
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 UNKNOWN_APP = "UnknownApp";
|
||||||
|
|
||||||
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
|
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
|
||||||
@ -86,9 +88,9 @@ public class Constants {
|
|||||||
public static final String USERNAME = "username";
|
public static final String USERNAME = "username";
|
||||||
|
|
||||||
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
|
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
|
||||||
|
|
||||||
public static final Integer SDK_GRPC_PORT_DEFAULT_OFFSET = 1000;
|
public static final Integer SDK_GRPC_PORT_DEFAULT_OFFSET = 1000;
|
||||||
|
|
||||||
public static final Integer CLUSTER_GRPC_PORT_DEFAULT_OFFSET = 1001;
|
public static final Integer CLUSTER_GRPC_PORT_DEFAULT_OFFSET = 1001;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,13 +218,38 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String CLUSTER_NAME_PATTERN_STRING = "^[0-9a-zA-Z-]+$";
|
public static final String CLUSTER_NAME_PATTERN_STRING = "^[0-9a-zA-Z-]+$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* millisecond.
|
||||||
|
*/
|
||||||
|
public static final long DEFAULT_REDO_DELAY_TIME = 3000L;
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constants in config directory.
|
* The constants in config directory.
|
||||||
*/
|
*/
|
||||||
public static class Config {
|
public static class Config {
|
||||||
|
|
||||||
public static final String CONFIG_MODULE = "config";
|
public static final String CONFIG_MODULE = "config";
|
||||||
|
|
||||||
public static final String NOTIFY_HEADER = "notify";
|
public static final String NOTIFY_HEADER = "notify";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,9 +257,9 @@ public class Constants {
|
|||||||
* The constants in naming directory.
|
* The constants in naming directory.
|
||||||
*/
|
*/
|
||||||
public static class Naming {
|
public static class Naming {
|
||||||
|
|
||||||
public static final String NAMING_MODULE = "naming";
|
public static final String NAMING_MODULE = "naming";
|
||||||
|
|
||||||
public static final String CMDB_CONTEXT_TYPE = "CMDB";
|
public static final String CMDB_CONTEXT_TYPE = "CMDB";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +267,7 @@ public class Constants {
|
|||||||
* The constants in remote directory.
|
* The constants in remote directory.
|
||||||
*/
|
*/
|
||||||
public static class Remote {
|
public static class Remote {
|
||||||
|
|
||||||
public static final String INTERNAL_MODULE = "internal";
|
public static final String INTERNAL_MODULE = "internal";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,9 +279,9 @@ public class Constants {
|
|||||||
public static final int SERIALIZE_ERROR_CODE = 100;
|
public static final int SERIALIZE_ERROR_CODE = 100;
|
||||||
|
|
||||||
public static final int DESERIALIZE_ERROR_CODE = 101;
|
public static final int DESERIALIZE_ERROR_CODE = 101;
|
||||||
|
|
||||||
public static final int FIND_DATASOURCE_ERROR_CODE = 102;
|
public static final int FIND_DATASOURCE_ERROR_CODE = 102;
|
||||||
|
|
||||||
public static final int FIND_TABLE_ERROR_CODE = 103;
|
public static final int FIND_TABLE_ERROR_CODE = 103;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ public enum ConfigType {
|
|||||||
*/
|
*/
|
||||||
YAML("yaml"),
|
YAML("yaml"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* config type is "toml".
|
||||||
|
*/
|
||||||
|
TOML("toml"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not a real type.
|
* not a real type.
|
||||||
*/
|
*/
|
||||||
|
@ -181,7 +181,7 @@ public class NacosException extends Exception {
|
|||||||
public static final int RESOURCE_NOT_FOUND = -404;
|
public static final int RESOURCE_NOT_FOUND = -404;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http client error code, ome exceptions that occurred when the use the Nacos RestTemplate and Nacos
|
* http client error code, ome exceptions that occurred when there use the Nacos RestTemplate and Nacos
|
||||||
* AsyncRestTemplate.
|
* AsyncRestTemplate.
|
||||||
*/
|
*/
|
||||||
public static final int HTTP_CLIENT_ERROR_CODE = -500;
|
public static final int HTTP_CLIENT_ERROR_CODE = -500;
|
||||||
|
@ -260,7 +260,7 @@ private static final long serialVersionUID = 0L;
|
|||||||
if (key == null) { throw new NullPointerException(); }
|
if (key == null) { throw new NullPointerException(); }
|
||||||
java.util.Map<String, String> map =
|
java.util.Map<String, String> map =
|
||||||
internalGetHeaders().getMap();
|
internalGetHeaders().getMap();
|
||||||
return map.containsKey(key) ? map.get(key) : defaultValue;
|
return map.getOrDefault(key, defaultValue);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* <code>map<string, string> headers = 7;</code>
|
* <code>map<string, string> headers = 7;</code>
|
||||||
@ -797,7 +797,7 @@ private static final long serialVersionUID = 0L;
|
|||||||
}
|
}
|
||||||
private com.google.protobuf.MapField<String, String>
|
private com.google.protobuf.MapField<String, String>
|
||||||
internalGetMutableHeaders() {
|
internalGetMutableHeaders() {
|
||||||
onChanged();;
|
onChanged();
|
||||||
if (headers_ == null) {
|
if (headers_ == null) {
|
||||||
headers_ = com.google.protobuf.MapField.newMapField(
|
headers_ = com.google.protobuf.MapField.newMapField(
|
||||||
HeadersDefaultEntryHolder.defaultEntry);
|
HeadersDefaultEntryHolder.defaultEntry);
|
||||||
|
@ -17,21 +17,14 @@
|
|||||||
package com.alibaba.nacos.api.grpc.auto;
|
package com.alibaba.nacos.api.grpc.auto;
|
||||||
|
|
||||||
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
||||||
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
|
|
||||||
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
|
|
||||||
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
|
|
||||||
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
|
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
|
||||||
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
|
|
||||||
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
|
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
|
||||||
import static io.grpc.stub.ClientCalls.futureUnaryCall;
|
import static io.grpc.stub.ClientCalls.futureUnaryCall;
|
||||||
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
|
|
||||||
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
|
|
||||||
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
|
|
||||||
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
|
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
|
||||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
|
|
||||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@javax.annotation.Generated(
|
@javax.annotation.Generated(
|
||||||
value = "by gRPC proto compiler (version 1.14.0)",
|
value = "by gRPC proto compiler (version 1.14.0)",
|
||||||
|
@ -178,7 +178,7 @@ public enum ErrorCode {
|
|||||||
/**
|
/**
|
||||||
* node down failure.
|
* node down failure.
|
||||||
*/
|
*/
|
||||||
NODE_DOWN_FAILURE(23001, "node down failure"),
|
NODE_DOWN_FAILURE(23002, "node down failure"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server error.
|
* server error.
|
||||||
|
@ -21,7 +21,7 @@ import com.alibaba.nacos.api.common.ResponseCode;
|
|||||||
/**
|
/**
|
||||||
* Business response code of naming module
|
* Business response code of naming module
|
||||||
*
|
*
|
||||||
* <p>Every code stays between 20001 to 29999.
|
* <p>Every code stays between 20001 and 29999.
|
||||||
*
|
*
|
||||||
* @author nkorange
|
* @author nkorange
|
||||||
* @author 1.2.0
|
* @author 1.2.0
|
||||||
|
@ -34,7 +34,7 @@ import java.util.List;
|
|||||||
public interface NamingService {
|
public interface NamingService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service.
|
* register an instance to service.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param ip instance ip
|
* @param ip instance ip
|
||||||
@ -44,7 +44,7 @@ public interface NamingService {
|
|||||||
void registerInstance(String serviceName, String ip, int port) throws NacosException;
|
void registerInstance(String serviceName, String ip, int port) throws NacosException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service.
|
* register an instance to service.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param groupName group of service
|
* @param groupName group of service
|
||||||
@ -55,7 +55,7 @@ public interface NamingService {
|
|||||||
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service with specified cluster name.
|
* register an instance to service with specified cluster name.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param ip instance ip
|
* @param ip instance ip
|
||||||
@ -66,7 +66,7 @@ public interface NamingService {
|
|||||||
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service with specified cluster name.
|
* register an instance to service with specified cluster name.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param groupName group of service
|
* @param groupName group of service
|
||||||
@ -79,7 +79,7 @@ public interface NamingService {
|
|||||||
throws NacosException;
|
throws NacosException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service with specified instance properties.
|
* register an instance to service with specified instance properties.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param instance instance to register
|
* @param instance instance to register
|
||||||
@ -88,7 +88,7 @@ public interface NamingService {
|
|||||||
void registerInstance(String serviceName, Instance instance) throws NacosException;
|
void registerInstance(String serviceName, Instance instance) throws NacosException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a instance to service with specified instance properties.
|
* register an instance to service with specified instance properties.
|
||||||
*
|
*
|
||||||
* @param serviceName name of service
|
* @param serviceName name of service
|
||||||
* @param groupName group of service
|
* @param groupName group of service
|
||||||
|
@ -188,18 +188,14 @@ public class ServiceInfo {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Instance> validHosts = new ArrayList<>();
|
boolean existValidHosts = false;
|
||||||
for (Instance host : hosts) {
|
for (Instance host : hosts) {
|
||||||
if (!host.isHealthy()) {
|
if (host.isHealthy() && host.getWeight() > 0) {
|
||||||
continue;
|
existValidHosts = true;
|
||||||
}
|
break;
|
||||||
|
|
||||||
for (int i = 0; i < host.getWeight(); i++) {
|
|
||||||
validHosts.add(host);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//No valid hosts, return false.
|
return existValidHosts;
|
||||||
return !validHosts.isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ -69,7 +69,7 @@ public class HealthCheckerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize and create a instance of health checker.
|
* Deserialize and create an instance of health checker.
|
||||||
*
|
*
|
||||||
* @param jsonString json string of health checker
|
* @param jsonString json string of health checker
|
||||||
* @return new instance
|
* @return new instance
|
||||||
@ -83,7 +83,7 @@ public class HealthCheckerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize a instance of health checker to json.
|
* Serialize an instance of health checker to json.
|
||||||
*
|
*
|
||||||
* @param healthChecker health checker instance
|
* @param healthChecker health checker instance
|
||||||
* @return son string after serializing
|
* @return son string after serializing
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2018 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.remote.request;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nacos persistent instances request.
|
||||||
|
*
|
||||||
|
* @author blake.qiu
|
||||||
|
*/
|
||||||
|
public class PersistentInstanceRequest extends AbstractNamingRequest {
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private Instance instance;
|
||||||
|
|
||||||
|
public PersistentInstanceRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PersistentInstanceRequest(String namespace, String serviceName, String groupName, String type, Instance instance) {
|
||||||
|
super(namespace, serviceName, groupName);
|
||||||
|
this.type = type;
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instance getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstance(Instance instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
}
|
@ -16,17 +16,27 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.spi.generator;
|
package com.alibaba.nacos.api.naming.spi.generator;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generator SPI for Instance Id.
|
* Generator SPI for Instance Id.
|
||||||
*
|
*
|
||||||
* @author xiweng.yy
|
* @author xiweng.yy
|
||||||
*/
|
*/
|
||||||
public interface IdGenerator {
|
public interface InstanceIdGenerator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate instance id.
|
* Generate instance id.
|
||||||
*
|
*
|
||||||
|
* @param instance instance
|
||||||
* @return instance id
|
* @return instance id
|
||||||
*/
|
*/
|
||||||
String generateInstanceId();
|
String generateInstanceId(Instance instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generator type.
|
||||||
|
*
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
String type();
|
||||||
}
|
}
|
@ -87,6 +87,16 @@ public class NamingUtils {
|
|||||||
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[0];
|
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.
|
* check combineServiceName format. the serviceName can't be blank.
|
||||||
* <pre>
|
* <pre>
|
||||||
@ -138,6 +148,10 @@ public class NamingUtils {
|
|||||||
* @throws NacosException if check failed, throw exception
|
* @throws NacosException if check failed, throw exception
|
||||||
*/
|
*/
|
||||||
public static void checkInstanceIsLegal(Instance instance) throws NacosException {
|
public static void checkInstanceIsLegal(Instance instance) throws NacosException {
|
||||||
|
if (null == instance) {
|
||||||
|
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,
|
||||||
|
"Instance can not be null.");
|
||||||
|
}
|
||||||
if (instance.getInstanceHeartBeatTimeOut() < instance.getInstanceHeartBeatInterval()
|
if (instance.getInstanceHeartBeatTimeOut() < instance.getInstanceHeartBeatInterval()
|
||||||
|| instance.getIpDeleteTimeout() < instance.getInstanceHeartBeatInterval()) {
|
|| instance.getIpDeleteTimeout() < instance.getInstanceHeartBeatInterval()) {
|
||||||
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,
|
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,
|
||||||
|
@ -38,4 +38,6 @@ public class RemoteConstants {
|
|||||||
public static final String LABEL_MODULE_CONFIG = "config";
|
public static final String LABEL_MODULE_CONFIG = "config";
|
||||||
|
|
||||||
public static final String LABEL_MODULE_NAMING = "naming";
|
public static final String LABEL_MODULE_NAMING = "naming";
|
||||||
|
|
||||||
|
public static final String MONITOR_LABEL_NONE = "none";
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,15 @@ public class RpcScheduledExecutor extends ScheduledThreadPoolExecutor {
|
|||||||
public static final RpcScheduledExecutor TIMEOUT_SCHEDULER = new RpcScheduledExecutor(1,
|
public static final RpcScheduledExecutor TIMEOUT_SCHEDULER = new RpcScheduledExecutor(1,
|
||||||
"com.alibaba.nacos.remote.TimerScheduler");
|
"com.alibaba.nacos.remote.TimerScheduler");
|
||||||
|
|
||||||
|
public static final RpcScheduledExecutor CONTROL_SCHEDULER = new RpcScheduledExecutor(1,
|
||||||
|
"com.alibaba.nacos.control.DelayScheduler");
|
||||||
|
|
||||||
public static final RpcScheduledExecutor COMMON_SERVER_EXECUTOR = new RpcScheduledExecutor(1,
|
public static final RpcScheduledExecutor COMMON_SERVER_EXECUTOR = new RpcScheduledExecutor(1,
|
||||||
"com.alibaba.nacos.remote.ServerCommonScheduler");
|
"com.alibaba.nacos.remote.ServerCommonScheduler");
|
||||||
|
|
||||||
public RpcScheduledExecutor(int corePoolSize, final String threadName) {
|
public RpcScheduledExecutor(int corePoolSize, final String threadName) {
|
||||||
super(corePoolSize, new ThreadFactory() {
|
super(corePoolSize, new ThreadFactory() {
|
||||||
private AtomicLong index = new AtomicLong();
|
private final AtomicLong index = new AtomicLong();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
|
@ -30,11 +30,31 @@ public class ConnectResetRequest extends ServerRequest {
|
|||||||
|
|
||||||
String serverPort;
|
String serverPort;
|
||||||
|
|
||||||
|
String connectionId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModule() {
|
public String getModule() {
|
||||||
return INTERNAL_MODULE;
|
return INTERNAL_MODULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter method for property <tt>connectionId</tt>.
|
||||||
|
*
|
||||||
|
* @return property value of connectionId
|
||||||
|
*/
|
||||||
|
public String getConnectionId() {
|
||||||
|
return connectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter method for property <tt>connectionId</tt>.
|
||||||
|
*
|
||||||
|
* @param connectionId value to be assigned to property connectionId
|
||||||
|
*/
|
||||||
|
public void setConnectionId(String connectionId) {
|
||||||
|
this.connectionId = connectionId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter method for property <tt>serverIp</tt>.
|
* Getter method for property <tt>serverIp</tt>.
|
||||||
*
|
*
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.ability.ClientAbilities;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -31,12 +29,12 @@ public class ConnectionSetupRequest extends InternalRequest {
|
|||||||
|
|
||||||
private String clientVersion;
|
private String clientVersion;
|
||||||
|
|
||||||
private ClientAbilities abilities;
|
|
||||||
|
|
||||||
private String tenant;
|
private String tenant;
|
||||||
|
|
||||||
private Map<String, String> labels = new HashMap<>();
|
private Map<String, String> labels = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<String, Boolean> abilityTable;
|
||||||
|
|
||||||
public ConnectionSetupRequest() {
|
public ConnectionSetupRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,11 +62,11 @@ public class ConnectionSetupRequest extends InternalRequest {
|
|||||||
this.tenant = tenant;
|
this.tenant = tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientAbilities getAbilities() {
|
public Map<String, Boolean> getAbilityTable() {
|
||||||
return abilities;
|
return abilityTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbilities(ClientAbilities abilities) {
|
public void setAbilityTable(Map<String, Boolean> abilityTable) {
|
||||||
this.abilities = abilities;
|
this.abilityTable = abilityTable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityStatus;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -34,7 +37,25 @@ public class RequestMeta {
|
|||||||
private String clientVersion = "";
|
private String clientVersion = "";
|
||||||
|
|
||||||
private Map<String, String> labels = new HashMap<>();
|
private Map<String, String> labels = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<String, Boolean> abilityTable;
|
||||||
|
|
||||||
|
public AbilityStatus getConnectionAbility(AbilityKey abilityKey) {
|
||||||
|
if (abilityTable == null || !abilityTable.containsKey(abilityKey.getName())) {
|
||||||
|
return AbilityStatus.UNKNOWN;
|
||||||
|
}
|
||||||
|
return abilityTable.get(abilityKey.getName()) ? AbilityStatus.SUPPORTED : AbilityStatus.NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter method for property <tt>abilityTable</tt>.
|
||||||
|
*
|
||||||
|
* @param abilityTable property value of clientVersion
|
||||||
|
*/
|
||||||
|
public void setAbilityTable(Map<String, Boolean> abilityTable) {
|
||||||
|
this.abilityTable = abilityTable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter method for property <tt>clientVersion</tt>.
|
* Getter method for property <tt>clientVersion</tt>.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2022 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.remote.request;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.api.common.Constants.Remote.INTERNAL_MODULE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server tells the client that the connection is established.
|
||||||
|
*
|
||||||
|
* @author Daydreamer.
|
||||||
|
* @date 2022/7/12 19:21
|
||||||
|
**/
|
||||||
|
public class SetupAckRequest extends ServerRequest {
|
||||||
|
|
||||||
|
private Map<String, Boolean> abilityTable;
|
||||||
|
|
||||||
|
public SetupAckRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetupAckRequest(Map<String, Boolean> abilityTable) {
|
||||||
|
this.abilityTable = abilityTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Boolean> getAbilityTable() {
|
||||||
|
return abilityTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAbilityTable(Map<String, Boolean> abilityTable) {
|
||||||
|
this.abilityTable = abilityTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModule() {
|
||||||
|
return INTERNAL_MODULE;
|
||||||
|
}
|
||||||
|
}
|
@ -57,6 +57,7 @@ public class ErrorResponse extends Response {
|
|||||||
}
|
}
|
||||||
ErrorResponse response = new ErrorResponse();
|
ErrorResponse response = new ErrorResponse();
|
||||||
response.setErrorInfo(errorCode, exception.getMessage());
|
response.setErrorInfo(errorCode, exception.getMessage());
|
||||||
|
response.setResultCode(errorCode);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,15 @@ public class ServerCheckResponse extends Response {
|
|||||||
|
|
||||||
private String connectionId;
|
private String connectionId;
|
||||||
|
|
||||||
|
private boolean supportAbilityNegotiation;
|
||||||
|
|
||||||
public ServerCheckResponse() {
|
public ServerCheckResponse() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerCheckResponse(String connectionId) {
|
public ServerCheckResponse(String connectionId, boolean supportAbilityNegotiation) {
|
||||||
this.connectionId = connectionId;
|
this.connectionId = connectionId;
|
||||||
|
this.supportAbilityNegotiation = supportAbilityNegotiation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConnectionId() {
|
public String getConnectionId() {
|
||||||
@ -41,4 +44,12 @@ public class ServerCheckResponse extends Response {
|
|||||||
public void setConnectionId(String connectionId) {
|
public void setConnectionId(String connectionId) {
|
||||||
this.connectionId = connectionId;
|
this.connectionId = connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSupportAbilityNegotiation() {
|
||||||
|
return supportAbilityNegotiation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportAbilityNegotiation(boolean supportAbilityNegotiation) {
|
||||||
|
this.supportAbilityNegotiation = supportAbilityNegotiation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,19 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.nacos.common.log;
|
package com.alibaba.nacos.api.remote.response;
|
||||||
|
|
||||||
/**
|
/**.
|
||||||
* nacos logback properties.
|
* @author Daydreamer
|
||||||
* @author hujun
|
* @description Server tells the client that the connection is established
|
||||||
*/
|
* @date 2022/7/12 19:21
|
||||||
public interface NacosLogbackProperties {
|
**/
|
||||||
/**
|
public class SetupAckResponse extends Response {
|
||||||
* get value.
|
|
||||||
*
|
|
||||||
* @param source source
|
|
||||||
* @param defaultValue defaultValue
|
|
||||||
* @return value
|
|
||||||
*/
|
|
||||||
String getValue(String source, String defaultValue);
|
|
||||||
}
|
}
|
@ -64,7 +64,7 @@ public interface Selector<R, C, E> extends Serializable {
|
|||||||
String getType();
|
String getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the select context which usede by {@link #select(Object)}.
|
* Get the select context which used by {@link #select(Object)}.
|
||||||
*
|
*
|
||||||
* @return selector context type.
|
* @return selector context type.
|
||||||
*/
|
*/
|
||||||
|
@ -22,6 +22,8 @@ com.alibaba.nacos.api.remote.request.PushAckRequest
|
|||||||
com.alibaba.nacos.api.remote.request.ServerCheckRequest
|
com.alibaba.nacos.api.remote.request.ServerCheckRequest
|
||||||
com.alibaba.nacos.api.remote.request.ServerLoaderInfoRequest
|
com.alibaba.nacos.api.remote.request.ServerLoaderInfoRequest
|
||||||
com.alibaba.nacos.api.remote.request.ServerReloadRequest
|
com.alibaba.nacos.api.remote.request.ServerReloadRequest
|
||||||
|
com.alibaba.nacos.api.remote.request.SetupAckRequest
|
||||||
|
com.alibaba.nacos.api.remote.response.SetupAckResponse
|
||||||
com.alibaba.nacos.api.remote.response.ClientDetectionResponse
|
com.alibaba.nacos.api.remote.response.ClientDetectionResponse
|
||||||
com.alibaba.nacos.api.remote.response.ConnectResetResponse
|
com.alibaba.nacos.api.remote.response.ConnectResetResponse
|
||||||
com.alibaba.nacos.api.remote.response.ErrorResponse
|
com.alibaba.nacos.api.remote.response.ErrorResponse
|
||||||
@ -45,6 +47,7 @@ com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncReque
|
|||||||
com.alibaba.nacos.api.config.remote.response.cluster.ConfigChangeClusterSyncResponse
|
com.alibaba.nacos.api.config.remote.response.cluster.ConfigChangeClusterSyncResponse
|
||||||
com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest
|
com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest
|
||||||
com.alibaba.nacos.api.naming.remote.request.InstanceRequest
|
com.alibaba.nacos.api.naming.remote.request.InstanceRequest
|
||||||
|
com.alibaba.nacos.api.naming.remote.request.PersistentInstanceRequest
|
||||||
com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest
|
com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest
|
||||||
com.alibaba.nacos.api.naming.remote.request.ServiceListRequest
|
com.alibaba.nacos.api.naming.remote.request.ServiceListRequest
|
||||||
com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest
|
com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest
|
||||||
|
@ -20,25 +20,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientAbilitiesTest {
|
class ClientAbilitiesTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ClientAbilities abilities = new ClientAbilities();
|
ClientAbilities abilities = new ClientAbilities();
|
||||||
String json = mapper.writeValueAsString(abilities);
|
String json = mapper.writeValueAsString(abilities);
|
||||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||||
@ -47,7 +47,7 @@ public class ClientAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||||
+ "\"supportRemoteMetric\":false}}";
|
+ "\"supportRemoteMetric\":false}}";
|
||||||
|
@ -20,35 +20,35 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerAbilitiesTest {
|
class ServerAbilitiesTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
private ServerAbilities serverAbilities;
|
private ServerAbilities serverAbilities;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
static void setUpBeforeClass() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
serverAbilities = new ServerAbilities();
|
serverAbilities = new ServerAbilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
serverAbilities = new ServerAbilities();
|
serverAbilities = new ServerAbilities();
|
||||||
String json = mapper.writeValueAsString(serverAbilities);
|
String json = mapper.writeValueAsString(serverAbilities);
|
||||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||||
@ -57,7 +57,7 @@ public class ServerAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||||
+ "\"supportRemoteMetric\":false}}";
|
+ "\"supportRemoteMetric\":false}}";
|
||||||
@ -68,10 +68,10 @@ public class ServerAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCode() {
|
void testEqualsAndHashCode() {
|
||||||
assertEquals(serverAbilities, serverAbilities);
|
assertEquals(serverAbilities, serverAbilities);
|
||||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||||
assertNotEquals(serverAbilities, null);
|
assertNotEquals(null, serverAbilities);
|
||||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||||
ServerAbilities test = new ServerAbilities();
|
ServerAbilities test = new ServerAbilities();
|
||||||
assertEquals(serverAbilities, test);
|
assertEquals(serverAbilities, test);
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.ability.register.impl;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class ClusterClientAbilitiesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetStaticAbilities() {
|
||||||
|
// TODO add the cluster client abilities.
|
||||||
|
assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.ability.register.impl;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class SdkClientAbilitiesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetStaticAbilities() {
|
||||||
|
// TODO add the sdk client abilities.
|
||||||
|
assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.ability.register.impl;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class ServerAbilitiesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetStaticAbilities() {
|
||||||
|
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSupportPersistentInstanceByGrpcAbilities() {
|
||||||
|
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||||
|
}
|
||||||
|
}
|
@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.annotation;
|
package com.alibaba.nacos.api.annotation;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
||||||
@ -28,23 +27,24 @@ import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOL
|
|||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_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 com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NacosPropertiesTest {
|
class NacosPropertiesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlaceholders() {
|
void testPlaceholders() {
|
||||||
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolvePlaceholders() {
|
void testResolvePlaceholders() {
|
||||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
||||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
||||||
|
|
||||||
@ -75,11 +75,11 @@ public class NacosPropertiesTest {
|
|||||||
MockEnvironment environment = new MockEnvironment();
|
MockEnvironment environment = new MockEnvironment();
|
||||||
environment.setProperty(propertyName, propertyValue);
|
environment.setProperty(propertyName, propertyValue);
|
||||||
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
||||||
Assert.assertEquals(expectValue, resolvedValue);
|
assertEquals(expectValue, resolvedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSort() {
|
void testSort() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EntityEventTest {
|
class EntityEventTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
EntityEvent entity = new EntityEvent();
|
EntityEvent entity = new EntityEvent();
|
||||||
entity.setEntityName("test-entity");
|
entity.setEntityName("test-entity");
|
||||||
entity.setEntityType("CMDB");
|
entity.setEntityType("CMDB");
|
||||||
@ -50,7 +50,7 @@ public class EntityEventTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
||||||
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
||||||
assertEquals("test-entity", entity.getEntityName());
|
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.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EntityTest {
|
class EntityTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
Entity entity = new Entity();
|
Entity entity = new Entity();
|
||||||
entity.setName("test-entity");
|
entity.setName("test-entity");
|
||||||
entity.setType(PreservedEntityTypes.ip.name());
|
entity.setType(PreservedEntityTypes.ip.name());
|
||||||
@ -51,7 +51,7 @@ public class EntityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
||||||
Entity entity = mapper.readValue(json, Entity.class);
|
Entity entity = mapper.readValue(json, Entity.class);
|
||||||
assertEquals("test-entity", entity.getName());
|
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.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class LabelTest {
|
class LabelTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
Label label = new Label();
|
Label label = new Label();
|
||||||
label.setName("test-label");
|
label.setName("test-label");
|
||||||
label.setDescription("CMDB description");
|
label.setDescription("CMDB description");
|
||||||
@ -52,7 +52,7 @@ public class LabelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
||||||
Label label = mapper.readValue(json, Label.class);
|
Label label = mapper.readValue(json, Label.class);
|
||||||
assertEquals("test-label", label.getName());
|
assertEquals("test-label", label.getName());
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ConfigChangeEventTest {
|
class ConfigChangeEventTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
void testConstructor() {
|
||||||
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
||||||
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
||||||
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ConfigChangeItemTest {
|
class ConfigChangeItemTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetNewValue() {
|
void testSetNewValue() {
|
||||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||||
item.setType(PropertyChangeType.ADDED);
|
item.setType(PropertyChangeType.ADDED);
|
||||||
assertEquals("testKey", item.getKey());
|
assertEquals("testKey", item.getKey());
|
||||||
@ -46,7 +46,7 @@ public class ConfigChangeItemTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||||
item.setType(PropertyChangeType.ADDED);
|
item.setType(PropertyChangeType.ADDED);
|
||||||
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigTypeTest {
|
class ConfigTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isValidType() {
|
void isValidType() {
|
||||||
assertTrue(ConfigType.isValidType("xml"));
|
assertTrue(ConfigType.isValidType("xml"));
|
||||||
assertTrue(ConfigType.isValidType("properties"));
|
assertTrue(ConfigType.isValidType("properties"));
|
||||||
assertTrue(ConfigType.isValidType("json"));
|
assertTrue(ConfigType.isValidType("json"));
|
||||||
@ -38,7 +38,7 @@ public class ConfigTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDefaultType() {
|
void testGetDefaultType() {
|
||||||
assertEquals("text", ConfigType.getDefaultType().getType());
|
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.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientRemoteAbilityTest {
|
class ClientRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(abilities);
|
String json = mapper.writeValueAsString(abilities);
|
||||||
assertEquals("{\"supportRemoteConnection\":false}", json);
|
assertEquals("{\"supportRemoteConnection\":false}", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true}";
|
String json = "{\"supportRemoteConnection\":true}";
|
||||||
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
|
@ -16,21 +16,20 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.ability;
|
package com.alibaba.nacos.api.config.ability;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
|
|
||||||
public class ServerConfigAbilityTest {
|
class ServerConfigAbilityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
ServerConfigAbility ability = new ServerConfigAbility();
|
ServerConfigAbility ability = new ServerConfigAbility();
|
||||||
ability.setSupportRemoteMetrics(true);
|
ability.setSupportRemoteMetrics(true);
|
||||||
assertEquals(ability, ability);
|
assertEquals(ability, ability);
|
||||||
assertFalse(ability.equals(null));
|
assertNotEquals(null, ability);
|
||||||
assertFalse(ability.equals(new ClientConfigAbility()));
|
assertNotEquals(ability, new ClientConfigAbility());
|
||||||
ServerConfigAbility newOne = new ServerConfigAbility();
|
ServerConfigAbility newOne = new ServerConfigAbility();
|
||||||
assertNotEquals(ability, newOne);
|
assertNotEquals(ability, newOne);
|
||||||
newOne.setSupportRemoteMetrics(true);
|
newOne.setSupportRemoteMetrics(true);
|
||||||
|
@ -21,42 +21,45 @@ import com.alibaba.nacos.api.remote.ability.ServerRemoteAbility;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerRemoteAbilityTest {
|
class ServerRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
private ServerRemoteAbility serverAbilities;
|
private ServerRemoteAbility serverAbilities;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
static void setUpBeforeClass() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(serverAbilities);
|
String json = mapper.writeValueAsString(serverAbilities);
|
||||||
assertEquals("{\"supportRemoteConnection\":false,\"grpcReportEnabled\":true}", json);
|
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
||||||
|
assertTrue(json.contains("\"grpcReportEnabled\":true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
||||||
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
@ -64,10 +67,10 @@ public class ServerRemoteAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCode() {
|
void testEqualsAndHashCode() {
|
||||||
assertEquals(serverAbilities, serverAbilities);
|
assertEquals(serverAbilities, serverAbilities);
|
||||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||||
assertNotEquals(serverAbilities, null);
|
assertNotEquals(null, serverAbilities);
|
||||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||||
ServerRemoteAbility test = new ServerRemoteAbility();
|
ServerRemoteAbility test = new ServerRemoteAbility();
|
||||||
assertEquals(serverAbilities, test);
|
assertEquals(serverAbilities, test);
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.listener;
|
package com.alibaba.nacos.api.config.listener;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class AbstractListenerTest {
|
class AbstractListenerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetExecutor() {
|
void testGetExecutor() {
|
||||||
// Default listener executor is null.
|
// Default listener executor is null.
|
||||||
assertNull(new AbstractListener() {
|
assertNull(new AbstractListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,28 +16,28 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.listener;
|
package com.alibaba.nacos.api.config.listener;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class AbstractSharedListenerTest {
|
class AbstractSharedListenerTest {
|
||||||
|
|
||||||
private static final String CONFIG_CONTENT = "test";
|
private static final String CONFIG_CONTENT = "test";
|
||||||
|
|
||||||
private static Map<String, String> receivedMap;
|
private static Map<String, String> receivedMap;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
receivedMap = new HashMap<>();
|
receivedMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFillContext() {
|
void testFillContext() {
|
||||||
assertEquals(0, receivedMap.size());
|
assertEquals(0, receivedMap.size());
|
||||||
MockShardListener listener = new MockShardListener();
|
MockShardListener listener = new MockShardListener();
|
||||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||||
@ -52,7 +52,7 @@ public class AbstractSharedListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExecutor() {
|
void getExecutor() {
|
||||||
// Default listener executor is null.
|
// Default listener executor is null.
|
||||||
assertNull(new MockShardListener().getExecutor());
|
assertNull(new MockShardListener().getExecutor());
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@ import com.alibaba.nacos.api.remote.request.Request;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -29,8 +30,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public abstract class BasedConfigRequestTest {
|
public abstract class BasedConfigRequestTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
|
||||||
|
|
||||||
protected static final String DATA_ID = "test_data";
|
protected static final String DATA_ID = "test_data";
|
||||||
|
|
||||||
protected static final String GROUP = "group";
|
protected static final String GROUP = "group";
|
||||||
@ -51,15 +50,18 @@ public abstract class BasedConfigRequestTest {
|
|||||||
|
|
||||||
protected static final String CONTENT = "content";
|
protected static final String CONTENT = "content";
|
||||||
|
|
||||||
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void testSerialize() throws JsonProcessingException;
|
public abstract void testSerialize() throws JsonProcessingException;
|
||||||
|
@ -18,18 +18,17 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Objects;
|
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.CACHE_DATA;
|
||||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
@ -57,35 +56,36 @@ public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
||||||
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
||||||
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
||||||
assertEquals(actual.getMetricsKeys().size(), 2);
|
assertEquals(2, actual.getMetricsKeys().size());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsKeysEquals() {
|
void testMetricsKeysEquals() {
|
||||||
String dataKey = String.join("+", KEY);
|
String dataKey = String.join("+", KEY);
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||||
assertEquals(key, key);
|
assertEquals(key, key);
|
||||||
assertFalse(key.equals(null));
|
assertNotEquals(null, key);
|
||||||
assertFalse(key.equals(new ClientConfigMetricRequest()));
|
assertNotEquals(key, new ClientConfigMetricRequest());
|
||||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey
|
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA,
|
||||||
.build(SNAPSHOT_DATA, dataKey);
|
dataKey);
|
||||||
assertNotEquals(key, newOne);
|
assertNotEquals(key, newOne);
|
||||||
newOne.setType(CACHE_DATA);
|
newOne.setType(CACHE_DATA);
|
||||||
assertEquals(key, newOne);
|
assertEquals(key, newOne);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsHashCode() {
|
void testMetricsHashCode() {
|
||||||
String dataKey = String.join("+", KEY);
|
String dataKey = String.join("+", KEY);
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||||
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsToString() {
|
void testMetricsToString() {
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY));
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA,
|
||||||
|
String.join("+", KEY));
|
||||||
assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString());
|
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.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
@ -35,7 +35,7 @@ public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = mapper.writeValueAsString(configBatchListenRequest);
|
String json = mapper.writeValueAsString(configBatchListenRequest);
|
||||||
assertTrue(json.contains("\"listen\":" + "true"));
|
assertTrue(json.contains("\"listen\":" + "true"));
|
||||||
assertTrue(json.contains(
|
assertTrue(json.contains(
|
||||||
"\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
|
"\"configListenContexts\":[{\"dataId\":\"test_data\",\"group\":\"group\",\"md5\":\"test_MD5\",\"tenant\":\"test_tenant\"}]"));
|
||||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||||
}
|
}
|
||||||
@ -47,14 +47,14 @@ public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
||||||
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
||||||
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
||||||
assertEquals(actual.isListen(), true);
|
assertEquals(true, actual.isListen());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
assertEquals(actual.getConfigListenContexts().size(), 1);
|
assertEquals(1, actual.getConfigListenContexts().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConfigListenContextToString() {
|
void testConfigListenContextToString() {
|
||||||
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
||||||
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
||||||
assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}",
|
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.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
||||||
configChangeNotifyRequest.putAllHeader(HEADERS);
|
configChangeNotifyRequest.putAllHeader(HEADERS);
|
||||||
requestId = injectRequestUuId(configChangeNotifyRequest);
|
requestId = injectRequestUuId(configChangeNotifyRequest);
|
||||||
@ -54,10 +54,10 @@ public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
||||||
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
||||||
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,24 +18,24 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigPublishRequest configPublishRequest;
|
|
||||||
|
|
||||||
private static final String TAG_PARAM = "tag";
|
private static final String TAG_PARAM = "tag";
|
||||||
|
|
||||||
private static final String APP_NAME_PARAM = "appName";
|
private static final String APP_NAME_PARAM = "appName";
|
||||||
|
|
||||||
|
ConfigPublishRequest configPublishRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
||||||
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
||||||
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
||||||
@ -64,13 +64,13 @@ public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
||||||
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
||||||
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getContent(), CONTENT);
|
assertEquals(CONTENT, actual.getContent());
|
||||||
assertEquals(actual.getCasMd5(), MD5);
|
assertEquals(MD5, actual.getCasMd5());
|
||||||
assertEquals(actual.getAdditionParam(TAG_PARAM), TAG_PARAM);
|
assertEquals(TAG_PARAM, actual.getAdditionParam(TAG_PARAM));
|
||||||
assertEquals(actual.getAdditionParam(APP_NAME_PARAM), APP_NAME_PARAM);
|
assertEquals(APP_NAME_PARAM, actual.getAdditionParam(APP_NAME_PARAM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigQueryRequest configQueryRequest;
|
ConfigQueryRequest configQueryRequest;
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
||||||
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
||||||
configQueryRequest.putAllHeader(headers);
|
configQueryRequest.putAllHeader(headers);
|
||||||
@ -45,7 +45,7 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotify() {
|
void testIsNotify() {
|
||||||
assertTrue(configQueryRequest.isNotify());
|
assertTrue(configQueryRequest.isNotify());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
||||||
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
||||||
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getTag(), TAG);
|
assertEquals(TAG, actual.getTag());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigRemoveRequest configRemoveRequest;
|
ConfigRemoveRequest configRemoveRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
||||||
requestId = injectRequestUuId(configRemoveRequest);
|
requestId = injectRequestUuId(configRemoveRequest);
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
||||||
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
||||||
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getTag(), TAG);
|
assertEquals(TAG, actual.getTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,20 @@ package com.alibaba.nacos.api.config.remote.request.cluster;
|
|||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
||||||
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
||||||
configChangeClusterSyncRequest.setGroup(GROUP);
|
configChangeClusterSyncRequest.setGroup(GROUP);
|
||||||
@ -40,6 +40,7 @@ public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
|||||||
configChangeClusterSyncRequest.setTag(TAG);
|
configChangeClusterSyncRequest.setTag(TAG);
|
||||||
configChangeClusterSyncRequest.setBeta(Boolean.TRUE);
|
configChangeClusterSyncRequest.setBeta(Boolean.TRUE);
|
||||||
configChangeClusterSyncRequest.setLastModified(0L);
|
configChangeClusterSyncRequest.setLastModified(0L);
|
||||||
|
configChangeClusterSyncRequest.setBatch(false);
|
||||||
configChangeClusterSyncRequest.putAllHeader(HEADERS);
|
configChangeClusterSyncRequest.putAllHeader(HEADERS);
|
||||||
requestId = injectRequestUuId(configChangeClusterSyncRequest);
|
requestId = injectRequestUuId(configChangeClusterSyncRequest);
|
||||||
}
|
}
|
||||||
@ -63,15 +64,16 @@ public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
|||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
public void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
String json =
|
||||||
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
"{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
||||||
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
||||||
|
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
||||||
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getLastModified(), 0L);
|
assertEquals(0L, actual.getLastModified());
|
||||||
assertTrue(actual.isBeta());
|
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.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
|||||||
|
|
||||||
Map<String, Object> metric = new HashMap<>(16);
|
Map<String, Object> metric = new HashMap<>(16);
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
metric.put("m1", "v1");
|
metric.put("m1", "v1");
|
||||||
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
||||||
clientConfigMetricResponse.setMetrics(metric);
|
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.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
||||||
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
||||||
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
||||||
@ -44,14 +44,14 @@ public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest
|
|||||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||||
assertTrue(json.contains("\"errorCode\":0"));
|
assertTrue(json.contains("\"errorCode\":0"));
|
||||||
assertTrue(json.contains(
|
assertTrue(json.contains(
|
||||||
"\"changedConfigs\":[{\"group\":\"group\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
|
"\"changedConfigs\":[{\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\"}]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse
|
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse.buildFailResponse(
|
||||||
.buildFailResponse("Fail");
|
"Fail");
|
||||||
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
||||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||||
assertTrue(json.contains("\"errorCode\":0"));
|
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.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
||||||
requestId = injectResponseUuId(configChangeNotifyResponse);
|
requestId = injectResponseUuId(configChangeNotifyResponse);
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
|||||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||||
assertTrue(json.contains("\"errorCode\":0"));
|
assertTrue(json.contains("\"errorCode\":0"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigPublishResponse configPublishResponse;
|
ConfigPublishResponse configPublishResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
||||||
requestId = injectResponseUuId(configPublishResponse);
|
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.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigQueryResponse configQueryResponse;
|
ConfigQueryResponse configQueryResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
||||||
configQueryResponse.setContentType("text");
|
configQueryResponse.setContentType("text");
|
||||||
configQueryResponse.setEncryptedDataKey("encryptedKey");
|
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.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigRemoveResponse configRemoveResponse;
|
ConfigRemoveResponse configRemoveResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
||||||
requestId = injectResponseUuId(configRemoveResponse);
|
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.config.remote.response.BasedConfigResponseTest;
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
||||||
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
package com.alibaba.nacos.api.exception;
|
package com.alibaba.nacos.api.exception;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NacosExceptionTest {
|
class NacosExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosException exception = new NacosException();
|
NacosException exception = new NacosException();
|
||||||
assertEquals(0, exception.getErrCode());
|
assertEquals(0, exception.getErrCode());
|
||||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||||
@ -35,7 +35,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrMsg() {
|
void testConstructorWithErrMsg() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
assertEquals("test", exception.getErrMsg());
|
assertEquals("test", exception.getErrMsg());
|
||||||
@ -43,7 +43,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
assertEquals("cause test", exception.getErrMsg());
|
assertEquals("cause test", exception.getErrMsg());
|
||||||
@ -51,7 +51,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithMultiCauses() {
|
void testConstructorWithMultiCauses() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
||||||
new RuntimeException("cause test", new RuntimeException("multi")));
|
new RuntimeException("cause test", new RuntimeException("multi")));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
@ -60,7 +60,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithFull() {
|
void testConstructorWithFull() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
||||||
new RuntimeException("cause test"));
|
new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
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.common.Constants;
|
||||||
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NacosApiExceptionTest {
|
class NacosApiExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosApiException exception = new NacosApiException();
|
NacosApiException exception = new NacosApiException();
|
||||||
assertEquals(0, exception.getErrCode());
|
assertEquals(0, exception.getErrCode());
|
||||||
assertEquals(0, exception.getDetailErrCode());
|
assertEquals(0, exception.getDetailErrCode());
|
||||||
@ -34,7 +34,7 @@ public class NacosApiExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithoutCause() {
|
void testConstructorWithoutCause() {
|
||||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
||||||
assertEquals(500, exception.getErrCode());
|
assertEquals(500, exception.getErrCode());
|
||||||
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
||||||
@ -43,7 +43,7 @@ public class NacosApiExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
||||||
new RuntimeException("cause test"), "test");
|
new RuntimeException("cause test"), "test");
|
||||||
assertEquals(500, exception.getErrCode());
|
assertEquals(500, exception.getErrCode());
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.exception.runtime;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosDeserializationExceptionTest {
|
class NacosDeserializationExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException();
|
NacosDeserializationException exception = new NacosDeserializationException();
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -36,7 +36,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetClass() {
|
void testConstructorWithTargetClass() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(
|
NacosDeserializationException exception = new NacosDeserializationException(
|
||||||
NacosDeserializationExceptionTest.class);
|
NacosDeserializationExceptionTest.class);
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -46,7 +46,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetType() {
|
void testConstructorWithTargetType() {
|
||||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(type);
|
NacosDeserializationException exception = new NacosDeserializationException(type);
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -57,7 +57,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
||||||
@ -65,7 +65,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetClassAndCause() {
|
void testConstructorWithTargetClassAndCause() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(
|
NacosDeserializationException exception = new NacosDeserializationException(
|
||||||
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -75,7 +75,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetTypeAndCause() {
|
void testConstructorWithTargetTypeAndCause() {
|
||||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosLoadExceptionTest {
|
class NacosLoadExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
void testConstructor() {
|
||||||
NacosLoadException exception = new NacosLoadException("test");
|
NacosLoadException exception = new NacosLoadException("test");
|
||||||
assertEquals("test", exception.getMessage());
|
assertEquals("test", exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NacosRuntimeExceptionTest {
|
class NacosRuntimeExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCode() {
|
void testConstructorWithErrorCode() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -34,7 +34,7 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCodeAndMsg() {
|
void testConstructorWithErrorCodeAndMsg() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||||
@ -42,7 +42,7 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCodeAndCause() {
|
void testConstructorWithErrorCodeAndCause() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||||
new RuntimeException("test"));
|
new RuntimeException("test"));
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
@ -51,9 +51,9 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithFull() {
|
void testConstructorWithFull() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test",
|
||||||
"test", new RuntimeException("cause test"));
|
new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||||
assertTrue(exception.getCause() instanceof RuntimeException);
|
assertTrue(exception.getCause() instanceof RuntimeException);
|
||||||
|
@ -17,15 +17,15 @@
|
|||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosSerializationExceptionTest {
|
class NacosSerializationExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosSerializationException exception = new NacosSerializationException();
|
NacosSerializationException exception = new NacosSerializationException();
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -33,7 +33,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithSerializedClass() {
|
void testConstructorWithSerializedClass() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
||||||
@ -42,7 +42,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
||||||
@ -50,7 +50,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithSerializedClassAndCause() {
|
void testConstructorWithSerializedClassAndCause() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
||||||
new RuntimeException("test"));
|
new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 1999-2021 Alibaba Group Holding Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.nacos.api.model.v2;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ErrorCodeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCodeNotSame() {
|
||||||
|
Class<ErrorCode> errorCodeClass = ErrorCode.class;
|
||||||
|
|
||||||
|
ErrorCode[] errorCodes = errorCodeClass.getEnumConstants();
|
||||||
|
Set<Integer> codeSet = new HashSet<Integer>(errorCodes.length);
|
||||||
|
|
||||||
|
for (ErrorCode errorCode : errorCodes) {
|
||||||
|
codeSet.add(errorCode.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(errorCodes.length, codeSet.size());
|
||||||
|
}
|
||||||
|
}
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.model.v2;
|
package com.alibaba.nacos.api.model.v2;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ResultTest {
|
class ResultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessEmptyResult() {
|
void testSuccessEmptyResult() {
|
||||||
Result<String> result = Result.success();
|
Result<String> result = Result.success();
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||||
@ -32,7 +32,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessWithData() {
|
void testSuccessWithData() {
|
||||||
Result<String> result = Result.success("test");
|
Result<String> result = Result.success("test");
|
||||||
assertEquals("test", result.getData());
|
assertEquals("test", result.getData());
|
||||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||||
@ -40,7 +40,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureMessageResult() {
|
void testFailureMessageResult() {
|
||||||
Result<String> result = Result.failure("test");
|
Result<String> result = Result.failure("test");
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
||||||
@ -48,7 +48,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureWithoutData() {
|
void testFailureWithoutData() {
|
||||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
|
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||||
@ -56,7 +56,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureWithData() {
|
void testFailureWithData() {
|
||||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
|
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
|
||||||
assertEquals("error", result.getData());
|
assertEquals("error", result.getData());
|
||||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||||
@ -64,7 +64,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
Result<String> result = Result.success("test");
|
Result<String> result = Result.success("test");
|
||||||
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
|
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.ability;
|
package com.alibaba.nacos.api.naming.ability;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientNamingAbilityTest {
|
class ClientNamingAbilityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAndSet() {
|
void testGetAndSet() {
|
||||||
ClientNamingAbility ability = new ClientNamingAbility();
|
ClientNamingAbility ability = new ClientNamingAbility();
|
||||||
assertFalse(ability.isSupportDeltaPush());
|
assertFalse(ability.isSupportDeltaPush());
|
||||||
assertFalse(ability.isSupportRemoteMetric());
|
assertFalse(ability.isSupportRemoteMetric());
|
||||||
|
@ -20,34 +20,33 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class ServerNamingAbilityTest {
|
class ServerNamingAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper jacksonMapper;
|
private static ObjectMapper jacksonMapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws Exception {
|
static void setUpClass() throws Exception {
|
||||||
jacksonMapper = new ObjectMapper();
|
jacksonMapper = new ObjectMapper();
|
||||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||||
String nonExistItemJson = "{\"exampleAbility\":false}";
|
String nonExistItemJson = "{\"exampleAbility\":false}";
|
||||||
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
||||||
assertFalse(actual.isSupportJraft());
|
assertFalse(actual.isSupportJraft());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() throws JsonProcessingException {
|
void testEquals() throws JsonProcessingException {
|
||||||
ServerNamingAbility expected = new ServerNamingAbility();
|
ServerNamingAbility expected = new ServerNamingAbility();
|
||||||
expected.setSupportJraft(true);
|
expected.setSupportJraft(true);
|
||||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||||
@ -60,19 +59,19 @@ public class ServerNamingAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsForOneObject() {
|
void testEqualsForOneObject() {
|
||||||
ServerNamingAbility ability = new ServerNamingAbility();
|
ServerNamingAbility ability = new ServerNamingAbility();
|
||||||
assertTrue(ability.equals(ability));
|
assertEquals(ability, ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsForOtherAbility() {
|
void testEqualsForOtherAbility() {
|
||||||
ServerNamingAbility ability = new ServerNamingAbility();
|
ServerNamingAbility ability = new ServerNamingAbility();
|
||||||
assertFalse(ability.equals(new ClientNamingAbility()));
|
assertNotEquals(ability, new ClientNamingAbility());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCode() throws JsonProcessingException {
|
void testHashCode() throws JsonProcessingException {
|
||||||
ServerNamingAbility expected = new ServerNamingAbility();
|
ServerNamingAbility expected = new ServerNamingAbility();
|
||||||
expected.setSupportJraft(true);
|
expected.setSupportJraft(true);
|
||||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||||
|
@ -16,26 +16,26 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.listener;
|
package com.alibaba.nacos.api.naming.listener;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NamingEventTest {
|
class NamingEventTest {
|
||||||
|
|
||||||
private MockNamingEventListener eventListener;
|
private MockNamingEventListener eventListener;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
eventListener = new MockNamingEventListener();
|
eventListener = new MockNamingEventListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamingEventWithSimpleConstructor() {
|
void testNamingEventWithSimpleConstructor() {
|
||||||
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
||||||
assertEquals("serviceName", event.getServiceName());
|
assertEquals("serviceName", event.getServiceName());
|
||||||
assertNull(event.getGroupName());
|
assertNull(event.getGroupName());
|
||||||
@ -49,7 +49,7 @@ public class NamingEventTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamingEventWithFullConstructor() {
|
void testNamingEventWithFullConstructor() {
|
||||||
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
|
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
|
||||||
assertEquals("serviceName", event.getServiceName());
|
assertEquals("serviceName", event.getServiceName());
|
||||||
assertEquals("group", event.getGroupName());
|
assertEquals("group", event.getGroupName());
|
||||||
|
@ -22,29 +22,29 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClusterTest {
|
class ClusterTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Cluster actual = new Cluster();
|
Cluster actual = new Cluster();
|
||||||
assertNull(actual.getName());
|
assertNull(actual.getName());
|
||||||
assertNull(actual.getServiceName());
|
assertNull(actual.getServiceName());
|
||||||
@ -72,7 +72,7 @@ public class ClusterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonSerialize() throws JsonProcessingException {
|
void testJsonSerialize() throws JsonProcessingException {
|
||||||
Cluster actual = new Cluster("cluster");
|
Cluster actual = new Cluster("cluster");
|
||||||
actual.setServiceName("group@@service");
|
actual.setServiceName("group@@service");
|
||||||
actual.setHealthChecker(new Http());
|
actual.setHealthChecker(new Http());
|
||||||
@ -91,7 +91,7 @@ public class ClusterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonDeserialize() throws JsonProcessingException {
|
void testJsonDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
|
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
|
||||||
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
|
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
|
||||||
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
|
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
|
||||||
|
@ -22,30 +22,31 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceTest {
|
class InstanceTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertNull(instance.getInstanceId());
|
assertNull(instance.getInstanceId());
|
||||||
assertNull(instance.getIp());
|
assertNull(instance.getIp());
|
||||||
@ -62,7 +63,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonSerialize() throws JsonProcessingException {
|
void testJsonSerialize() throws JsonProcessingException {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
setInstance(instance);
|
setInstance(instance);
|
||||||
String actual = mapper.writeValueAsString(instance);
|
String actual = mapper.writeValueAsString(instance);
|
||||||
@ -82,7 +83,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonDeserialize() throws JsonProcessingException {
|
void testJsonDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
|
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
|
||||||
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
|
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
|
||||||
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
|
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
|
||||||
@ -92,21 +93,21 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckClusterNameFormat() {
|
void testCheckClusterNameFormat() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setClusterName("demo");
|
instance.setClusterName("demo");
|
||||||
assertEquals("demo", instance.getClusterName());
|
assertEquals("demo", instance.getClusterName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToInetAddr() {
|
void testToInetAddr() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
setInstance(instance);
|
setInstance(instance);
|
||||||
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsMetadata() {
|
void testContainsMetadata() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertFalse(instance.containsMetadata("a"));
|
assertFalse(instance.containsMetadata("a"));
|
||||||
instance.setMetadata(null);
|
instance.setMetadata(null);
|
||||||
@ -116,7 +117,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstanceIdGenerator() {
|
void testGetInstanceIdGenerator() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
||||||
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
||||||
@ -124,19 +125,19 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
Instance actual = new Instance();
|
Instance actual = new Instance();
|
||||||
setInstance(actual);
|
setInstance(actual);
|
||||||
actual.setMetadata(new HashMap<>());
|
actual.setMetadata(new HashMap<>());
|
||||||
actual.addMetadata("a", "b");
|
actual.addMetadata("a", "b");
|
||||||
assertFalse(actual.equals(new Object()));
|
assertNotEquals(actual, new Object());
|
||||||
Instance expected = new Instance();
|
Instance expected = new Instance();
|
||||||
setInstance(expected);
|
setInstance(expected);
|
||||||
expected.setMetadata(new HashMap<>());
|
expected.setMetadata(new HashMap<>());
|
||||||
expected.addMetadata("a", "b");
|
expected.addMetadata("a", "b");
|
||||||
assertTrue(actual.equals(expected));
|
assertEquals(actual, expected);
|
||||||
expected.addMetadata("a", "c");
|
expected.addMetadata("a", "c");
|
||||||
assertFalse(actual.equals(expected));
|
assertNotEquals(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInstance(Instance instance) {
|
private void setInstance(Instance instance) {
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.pojo;
|
package com.alibaba.nacos.api.naming.pojo;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ListViewTest {
|
class ListViewTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
List<String> data = new LinkedList<>();
|
List<String> data = new LinkedList<>();
|
||||||
data.add("1");
|
data.add("1");
|
||||||
data.add("2");
|
data.add("2");
|
||||||
@ -41,7 +41,7 @@ public class ListViewTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
ListView<String> listView = new ListView<>();
|
ListView<String> listView = new ListView<>();
|
||||||
assertEquals(0, listView.getCount());
|
assertEquals(0, listView.getCount());
|
||||||
assertNull(listView.getData());
|
assertNull(listView.getData());
|
||||||
|
@ -20,8 +20,8 @@ import com.alibaba.nacos.api.utils.StringUtils;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -30,25 +30,26 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceInfoTest {
|
class ServiceInfoTest {
|
||||||
|
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper mapper;
|
||||||
|
|
||||||
private ServiceInfo serviceInfo;
|
private ServiceInfo serviceInfo;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
String actual = mapper.writeValueAsString(serviceInfo);
|
String actual = mapper.writeValueAsString(serviceInfo);
|
||||||
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
||||||
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
||||||
@ -64,7 +65,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
|
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
|
||||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
||||||
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
||||||
@ -82,14 +83,14 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetKey() {
|
void testGetKey() {
|
||||||
String key = serviceInfo.getKey();
|
String key = serviceInfo.getKey();
|
||||||
assertEquals("G@@testName@@testClusters", key);
|
assertEquals("G@@testName@@testClusters", key);
|
||||||
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetKeyEncode() {
|
void testGetKeyEncode() {
|
||||||
String key = serviceInfo.getKeyEncoded();
|
String key = serviceInfo.getKeyEncoded();
|
||||||
String encodeName = null;
|
String encodeName = null;
|
||||||
try {
|
try {
|
||||||
@ -101,7 +102,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceInfoConstructor() {
|
void testServiceInfoConstructor() {
|
||||||
String key1 = "group@@name";
|
String key1 = "group@@name";
|
||||||
String key2 = "group@@name@@c2";
|
String key2 = "group@@name@@c2";
|
||||||
ServiceInfo s1 = new ServiceInfo(key1);
|
ServiceInfo s1 = new ServiceInfo(key1);
|
||||||
@ -110,32 +111,34 @@ public class ServiceInfoTest {
|
|||||||
assertEquals(key2, s2.getKey());
|
assertEquals(key2, s2.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testServiceInfoConstructorWithError() {
|
void testServiceInfoConstructorWithError() {
|
||||||
String key1 = "name";
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
ServiceInfo s1 = new ServiceInfo(key1);
|
String key1 = "name";
|
||||||
|
ServiceInfo s1 = new ServiceInfo(key1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForAllIps() {
|
void testValidateForAllIps() {
|
||||||
serviceInfo.setAllIPs(true);
|
serviceInfo.setAllIPs(true);
|
||||||
assertTrue(serviceInfo.validate());
|
assertTrue(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForNullHosts() {
|
void testValidateForNullHosts() {
|
||||||
serviceInfo.setHosts(null);
|
serviceInfo.setHosts(null);
|
||||||
assertFalse(serviceInfo.validate());
|
assertFalse(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForEmptyHosts() {
|
void testValidateForEmptyHosts() {
|
||||||
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
||||||
assertFalse(serviceInfo.validate());
|
assertFalse(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForUnhealthyHosts() {
|
void testValidateForUnhealthyHosts() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setHealthy(false);
|
instance.setHealthy(false);
|
||||||
serviceInfo.addHost(instance);
|
serviceInfo.addHost(instance);
|
||||||
@ -143,7 +146,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForBothUnhealthyAndHealthyHosts() {
|
void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||||
List<Instance> instanceList = new LinkedList<>();
|
List<Instance> instanceList = new LinkedList<>();
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instanceList.add(instance);
|
instanceList.add(instance);
|
||||||
@ -155,7 +158,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFromKey() {
|
void testFromKey() {
|
||||||
String key1 = "group@@name";
|
String key1 = "group@@name";
|
||||||
String key2 = "group@@name@@c2";
|
String key2 = "group@@name@@c2";
|
||||||
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
||||||
@ -165,7 +168,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() throws JsonProcessingException {
|
void testSetAndGet() throws JsonProcessingException {
|
||||||
serviceInfo.setReachProtectionThreshold(true);
|
serviceInfo.setReachProtectionThreshold(true);
|
||||||
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
|
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
|
||||||
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
|
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.pojo;
|
package com.alibaba.nacos.api.naming.pojo;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceTest {
|
class ServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Service service = new Service();
|
Service service = new Service();
|
||||||
assertNull(service.getName());
|
assertNull(service.getName());
|
||||||
assertNull(service.getAppName());
|
assertNull(service.getAppName());
|
||||||
@ -51,12 +51,13 @@ public class ServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
Service service = new Service("service");
|
Service service = new Service("service");
|
||||||
service.setGroupName("group");
|
service.setGroupName("group");
|
||||||
service.setAppName("app");
|
service.setAppName("app");
|
||||||
service.setProtectThreshold(1.0f);
|
service.setProtectThreshold(1.0f);
|
||||||
service.setMetadata(Collections.singletonMap("a", "b"));
|
service.setMetadata(Collections.singletonMap("a", "b"));
|
||||||
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", service.toString());
|
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}",
|
||||||
|
service.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,18 +17,18 @@
|
|||||||
package com.alibaba.nacos.api.naming.pojo.builder;
|
package com.alibaba.nacos.api.naming.pojo.builder;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceBuilderTest {
|
class InstanceBuilderTest {
|
||||||
|
|
||||||
private static final String SERVICE_NAME = "testService";
|
private static final String SERVICE_NAME = "testService";
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class InstanceBuilderTest {
|
|||||||
private static final String META_VALUE = "value";
|
private static final String META_VALUE = "value";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildFullInstance() {
|
void testBuildFullInstance() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
|
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
|
||||||
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
|
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
|
||||||
@ -72,7 +72,7 @@ public class InstanceBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildInstanceWithoutNewMetadata() {
|
void testBuildInstanceWithoutNewMetadata() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Map<String, String> metadata = new HashMap<>();
|
Map<String, String> metadata = new HashMap<>();
|
||||||
metadata.put("test", "test");
|
metadata.put("test", "test");
|
||||||
@ -90,7 +90,7 @@ public class InstanceBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildEmptyInstance() {
|
void testBuildEmptyInstance() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Instance actual = builder.build();
|
Instance actual = builder.build();
|
||||||
assertNull(actual.getServiceName());
|
assertNull(actual.getServiceName());
|
||||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class AbstractHealthCheckerTest {
|
class AbstractHealthCheckerTest {
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
TestChecker testChecker = new TestChecker();
|
TestChecker testChecker = new TestChecker();
|
||||||
testChecker.setTestValue("");
|
testChecker.setTestValue("");
|
||||||
String actual = objectMapper.writeValueAsString(testChecker);
|
String actual = objectMapper.writeValueAsString(testChecker);
|
||||||
@ -48,7 +48,7 @@ public class AbstractHealthCheckerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
||||||
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
||||||
assertEquals("", actual.getTestValue());
|
assertEquals("", actual.getTestValue());
|
||||||
@ -56,7 +56,7 @@ public class AbstractHealthCheckerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone() throws CloneNotSupportedException {
|
void testClone() throws CloneNotSupportedException {
|
||||||
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
|
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
|
||||||
assertEquals(AbstractHealthChecker.None.class, none.getClass());
|
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.Http;
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class HealthCheckTypeTest {
|
class HealthCheckTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForBuildInType() {
|
void testOfHealthCheckerClassForBuildInType() {
|
||||||
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
||||||
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
||||||
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
||||||
@ -37,18 +37,18 @@ public class HealthCheckTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForExtendType() {
|
void testOfHealthCheckerClassForExtendType() {
|
||||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||||
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForNonExistType() {
|
void testOfHealthCheckerClassForNonExistType() {
|
||||||
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLoadedHealthCheckerClasses() {
|
void testGetLoadedHealthCheckerClasses() {
|
||||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||||
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
||||||
assertEquals(5, actual.size());
|
assertEquals(5, actual.size());
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user