commit
ca6d1518bf
36
.github/workflows/pr-ci.yml
vendored
Normal file
36
.github/workflows/pr-ci.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: PR-CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ develop, v1.x-develop ]
|
||||
|
||||
jobs:
|
||||
dist-tar:
|
||||
name: Build distribution tar
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 120
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "8"
|
||||
cache: "maven"
|
||||
- name: Build distribution tar
|
||||
run: |
|
||||
mvn -Prelease-nacos -DskipTests clean install -U -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
with:
|
||||
name: nacos
|
||||
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
|
||||
- name: Save PR number
|
||||
run: |
|
||||
mkdir -p ./pr
|
||||
echo ${{ github.event.number }} > ./pr/NR
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: pr
|
||||
path: pr/
|
210
.github/workflows/pr-e2e-test.yml
vendored
Normal file
210
.github/workflows/pr-e2e-test.yml
vendored
Normal file
@ -0,0 +1,210 @@
|
||||
name: E2E test for pull request
|
||||
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["PR-CI"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
if: >
|
||||
github.event.workflow_run.event == 'pull_request' &&
|
||||
github.event.workflow_run.conclusion == 'success'
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
matrix:
|
||||
base-image: ["ubuntu"]
|
||||
java-version: ["8"]
|
||||
steps:
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v3.1.0
|
||||
with:
|
||||
script: |
|
||||
var artifacts = await github.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }},
|
||||
});
|
||||
var matchArtifactNacos = artifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "nacos"
|
||||
})[0];
|
||||
var download = await github.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifactNacos.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
var fs = require('fs');
|
||||
fs.writeFileSync('${{github.workspace}}/nacos.zip', Buffer.from(download.data));
|
||||
- run: |
|
||||
unzip nacos.zip
|
||||
mkdir nacos
|
||||
cp -r nacos-* nacos/
|
||||
ls
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: nacos-group/nacos-e2e.git
|
||||
ref: main
|
||||
path: nacos-e2e
|
||||
- name: docker-login
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and save docker images
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build
|
||||
cd nacos-e2e/cicd/build
|
||||
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
||||
echo $tag
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
||||
docker push ${DOCKER_REPO}:${tag}
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
with:
|
||||
name: versionlist
|
||||
path: nacos-e2e/cicd/build/versionlist/*
|
||||
|
||||
|
||||
list-version:
|
||||
if: always()
|
||||
name: List version
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
name: Download versionlist
|
||||
with:
|
||||
name: versionlist
|
||||
path: versionlist
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls versionlist`)
|
||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
deploy:
|
||||
if: ${{ success() }}
|
||||
name: Deploy nacos
|
||||
needs: [list-version,docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
REPLICA_COUNT: 3
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: Deploy nacos
|
||||
with:
|
||||
action: "deploy"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
chart-git: "https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git"
|
||||
chart-branch: "main"
|
||||
chart-path: "./cicd/helm"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
helm-values: |
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-test:
|
||||
if: ${{ success() }}
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: e2e test
|
||||
with:
|
||||
action: "test"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
||||
test-code-branch: "main"
|
||||
test-code-path: "java/nacos-2X"
|
||||
test-cmd: 'mvn clean test -B'
|
||||
job-id: ${{ strategy.job-index }}
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v3
|
||||
if: always() # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/test_report/TEST-*.xml'
|
||||
annotate_only: true
|
||||
include_passed: true
|
||||
detailed_summary: true
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
path: testlog.txt
|
||||
|
||||
clean:
|
||||
if: always()
|
||||
name: Clean
|
||||
needs: [list-version, e2e-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: clean
|
||||
with:
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
221
.github/workflows/push-ci.yaml
vendored
Normal file
221
.github/workflows/push-ci.yaml
vendored
Normal file
@ -0,0 +1,221 @@
|
||||
name: PUSH-CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, develop, v1.x-develop, v1.X]
|
||||
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
|
||||
concurrency:
|
||||
group: nacos-${{ github.ref }}
|
||||
|
||||
env:
|
||||
DOCKER_REPO: wuyfeedocker/nacos-ci
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||
|
||||
|
||||
jobs:
|
||||
dist-tar:
|
||||
name: Build dist tar
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "8"
|
||||
cache: "maven"
|
||||
- name: Build distribution tar
|
||||
run: |
|
||||
mvn -Prelease-nacos -DskipTests clean install -U -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
with:
|
||||
name: nacos
|
||||
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
|
||||
|
||||
docker:
|
||||
if: ${{ success() }}
|
||||
name: Docker images
|
||||
needs: [dist-tar]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
matrix:
|
||||
base-image: ["centos"]
|
||||
java-version: ["8"]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: nacos-group/nacos-e2e.git
|
||||
ref: main
|
||||
path: nacos-e2e
|
||||
- uses: actions/download-artifact@v3
|
||||
name: Download distribution tar
|
||||
with:
|
||||
name: nacos
|
||||
path: ./
|
||||
- name: docker-login
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and save docker images
|
||||
id: build-images
|
||||
run: |
|
||||
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build/
|
||||
cd nacos-e2e/cicd/build
|
||||
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
|
||||
mkdir versionlist
|
||||
touch versionlist/"${version}-`echo ${{ matrix.java-version }} | sed -e "s/:/-/g"`"
|
||||
ls versionlist/
|
||||
tag=${version}-$(echo ${{ matrix.java-version }} | sed -e "s/:/-/g")
|
||||
echo $tag
|
||||
docker build --no-cache -f Dockerfile -t ${DOCKER_REPO}:${tag} .
|
||||
docker push ${DOCKER_REPO}:${tag}
|
||||
- uses: actions/upload-artifact@v3
|
||||
name: Upload distribution tar
|
||||
with:
|
||||
name: versionlist
|
||||
path: nacos-e2e/cicd/build/versionlist/*
|
||||
|
||||
|
||||
list-version:
|
||||
if: always()
|
||||
name: List version
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
outputs:
|
||||
version-json: ${{ steps.show_versions.outputs.version-json }}
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
name: Download versionlist
|
||||
with:
|
||||
name: versionlist
|
||||
path: versionlist
|
||||
- name: Show versions
|
||||
id: show_versions
|
||||
run: |
|
||||
a=(`ls versionlist`)
|
||||
printf '%s\n' "${a[@]}" | jq -R . | jq -s .
|
||||
echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT
|
||||
|
||||
deploy:
|
||||
if: ${{ success() }}
|
||||
name: Deploy nacos
|
||||
needs: [list-version,docker]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
REPLICA_COUNT: 3
|
||||
DATABASE: mysql
|
||||
NODE_PORT: 30000
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- name: set nodeport
|
||||
run: |
|
||||
echo "::set-env name=NODE_PORT::$(expr $(expr $(expr $(expr 1 * $(expr ${{ github.run_number }} - 1)) + ${{ strategy.job-index }}) % 30000) + 30000)"
|
||||
- name: set cluster params
|
||||
if: ${{ matrix.mode == 'standalone' }}
|
||||
run: |
|
||||
echo "::set-env name=REPLICA_COUNT::1"
|
||||
echo "::set-env name=DATABASE::embedded"
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: Deploy nacos
|
||||
with:
|
||||
action: "deploy"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
chart-git: "https://ghproxy.com/https://github.com/nacos-group/nacos-e2e.git"
|
||||
chart-branch: "main"
|
||||
chart-path: "./cicd/helm"
|
||||
job-id: ${{ strategy.job-index }}
|
||||
helm-values: |
|
||||
namespace: nacos-${{ github.run_id }}-${{ strategy.job-index }}
|
||||
global:
|
||||
mode: ${{ matrix.mode }}
|
||||
nacos:
|
||||
replicaCount: ${{ env.REPLICA_COUNT }}
|
||||
image:
|
||||
repository: ${{ env.DOCKER_REPO }}
|
||||
tag: ${{ matrix.version }}
|
||||
storage:
|
||||
type: ${{ env.DATABASE }}
|
||||
db:
|
||||
port: 3306
|
||||
username: nacos
|
||||
password: nacos
|
||||
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
|
||||
service:
|
||||
nodePort: ${{ env.NODE_PORT }}
|
||||
type: ClusterIP
|
||||
e2e-test:
|
||||
if: ${{ success() }}
|
||||
name: E2E Test
|
||||
needs: [list-version, deploy]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: e2e test
|
||||
with:
|
||||
action: "test"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
test-code-git: "https://github.com/nacos-group/nacos-e2e.git"
|
||||
test-code-branch: "main"
|
||||
test-code-path: "java/nacos-2X"
|
||||
test-cmd: 'mvn clean test -B'
|
||||
job-id: ${{ strategy.job-index }}
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v3
|
||||
if: always() # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/test_report/TEST-*.xml'
|
||||
annotate_only: true
|
||||
include_passed: true
|
||||
detailed_summary: true
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
name: Upload test log
|
||||
with:
|
||||
name: testlog.txt ${{ matrix.mode }}
|
||||
path: testlog.txt
|
||||
|
||||
clean:
|
||||
if: always()
|
||||
name: Clean
|
||||
needs: [list-version, e2e-test]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
matrix:
|
||||
mode: ["cluster","standalone"]
|
||||
version: ${{ fromJSON(needs.list-version.outputs.version-json) }}
|
||||
steps:
|
||||
- uses: apache/rocketmq-test-tool@136205caa6e97f81744e30adea114dd2f09cc55e
|
||||
name: clean
|
||||
with:
|
||||
action: "clean"
|
||||
ask-config: "${{ secrets.ASK_CONFIG_VIRGINA }}"
|
||||
test-version: "${{ matrix.version }}"
|
||||
job-id: ${{ strategy.job-index }}
|
30
README.md
30
README.md
@ -82,7 +82,7 @@ For more details, see [quick-start.](https://nacos.io/en-us/docs/quick-start.htm
|
||||
|
||||
## Documentation
|
||||
|
||||
You can view the full documentation from the [Nacos website](https://nacos.io/en-us/docs/what-is-nacos.html).
|
||||
You can view the full documentation from the [Nacos website](https://nacos.io/en-us/docs/v2/what-is-nacos.html).
|
||||
|
||||
You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).
|
||||
|
||||
@ -149,31 +149,19 @@ These are only part of the companies using Nacos, for reference only. If you are
|
||||
![瑞安农村商业银行](https://img.alicdn.com/tfs/TB1lxu7EBLoK1RjSZFuXXXn0XXa-409-74.png)
|
||||
![司法大数据](https://img.alicdn.com/tfs/TB1L16eEzTpK1RjSZKPXXa3UpXa-302-50.png)
|
||||
![搜易贷](https://www.souyidai.com/www-style/images/logo.gif)
|
||||
![美菜](https://www.meicai.cn/assets/images/new-img/logo.png)
|
||||
![松格科技](http://songe.so/images/logo.gif)
|
||||
![平行云](https://img.alicdn.com/tfs/TB1OigyDyLaK1RjSZFxXXamPFXa-168-70.png)
|
||||
![甘肃紫光](https://img.alicdn.com/tfs/TB1gJ4vIhTpK1RjSZR0XXbEwXXa-462-60.jpg)
|
||||
![海云天](http://www.seaskylight.com/cn/uploadfiles/image/logo.png)
|
||||
![集萃智能](http://www.iimt.org.cn/pic/logosy.png)
|
||||
![Acmedcare+](https://img.alicdn.com/tfs/TB1DZWSEzDpK1RjSZFrXXa78VXa-240-62.png)
|
||||
![吾享](https://w.wuuxiang.com/theme/images/common/logo1.png)
|
||||
![北京天合互联信息有限公司](https://14605854.s21i.faiusr.com/4/ABUIABAEGAAg4OvkzwUo8b-qlwUwxQ449gM!300x300.png)
|
||||
![上海密尔克卫化工](http://www.mwclg.com/static-resource/front/images/home/img_logo_nav.png)
|
||||
![大连新唯](https://www.synwe.com/logo-full.png)
|
||||
![立思辰](https://user-images.githubusercontent.com/10215557/51593180-7563af00-1f2c-11e9-95b1-ec2c645d6a0b.png)
|
||||
![拓深科技](http://www.tpson.cn/images/new/icon/LOGO_1.png)
|
||||
![东家](https://img.alicdn.com/tfs/TB1zWW2EpYqK1RjSZLeXXbXppXa-262-81.png)
|
||||
![上海克垚](http://www.sh-guiyao.com/images/logo.jpg)
|
||||
![郑州山水](http://www.zzssxx.com/style/images/logo.png)
|
||||
![联采科技](http://www.lckjep.com:80//theme/img/logoTop.png)
|
||||
![南京28研究所](https://img.alicdn.com/tfs/TB1G216EsbpK1RjSZFyXXX_qFXa-325-53.jpg)
|
||||
![长亮科技](http://www.sunline.cn/Uploads/image/20170724/59759a405c3b2.png)
|
||||
![深圳易停车库](http://www.ytparking.com/yiting/images/logo.png)
|
||||
![凤凰网-汽车](https://p1.ifengimg.com/auto/image/2017/0922/auto_logo.png)
|
||||
![武汉日创科技](http://www.dragonwake.cn/static/css/default/images/logo.png)
|
||||
![易管智能](http://ebmsw.mro1598.com/UpLoadFile/MainCompany/20170308-1501-495c-a62f-fc03424f86f1/20170405/20170405-1056-4fe5-90e8-c055f8a1bb23.png)
|
||||
![云帐房](http://www.yunzhangfang.com/yzf-pc/img/logo.png)
|
||||
![知氏教育](https://www.chyeth.com/622e88980a5d091eaa6449f82d48ca43.png)
|
||||
![中化信息](http://www.sinochem.com/Portals/0/xinlogo.png)
|
||||
![一点车](https://img.alicdn.com/tfs/TB1DXerNgDqK1RjSZSyXXaxEVXa-333-103.png)
|
||||
![明传无线](https://img.alicdn.com/tfs/TB1VfOANgHqK1RjSZFPXXcwapXa-313-40.png)
|
||||
@ -196,12 +184,22 @@ These are only part of the companies using Nacos, for reference only. If you are
|
||||
![康美](https://img.alicdn.com/tfs/TB19RCANgHqK1RjSZFPXXcwapXa-180-180.jpg)
|
||||
![环球易购](https://img.alicdn.com/tfs/TB1iCGyNb2pK1RjSZFsXXaNlXXa-143-143.jpg)
|
||||
![Nepxion](https://avatars0.githubusercontent.com/u/16344119?s=200&v=4)
|
||||
![东莞最佳拍档](https://img.alicdn.com/tfs/TB11ugsDzTpK1RjSZKPXXa3UpXa-300-300.png)
|
||||
![chigua](https://img.alicdn.com/tfs/TB1aUe5EpzqK1RjSZSgXXcpAVXa-248-124.png)
|
||||
![宅无限](https://img.alicdn.com/tfs/TB1H9O5EAvoK1RjSZFNXXcxMVXa-221-221.jpg)
|
||||
![天阙](https://img.alicdn.com/tfs/TB1rNq4EwHqK1RjSZFgXXa7JXXa-200-200.jpg)
|
||||
![联合永道](https://img.alicdn.com/tfs/TB1CRAxDxYaK1RjSZFnXXa80pXa-190-190.jpg)
|
||||
![明源云](https://img.alicdn.com/tfs/TB1.q14ErrpK1RjSZTEXXcWAVXa-219-219.jpg)
|
||||
![三诺生物](http://www.sinocare.com/public/static/images/logored6000321.png)
|
||||
|
||||
![DaoCloud](https://www.daocloud.io/static/Logo-Light.png)
|
||||
![美菜](https://www.meicai.cn/img/logo.9210b6eb.jpg)
|
||||
![松格科技](https://img5.tianyancha.com/logo/lll/3aad34039972b57e70874df8c919ae8b.png@!f_200x200)
|
||||
![集萃智能](https://www.jsic-tech.com/Public/uploads/20191206/5de9b9baac696.jpg)
|
||||
![吾享](https://www.wuuxiang.com/theme/images/common/logo1.png)
|
||||
![拓深科技](http://www.tpson.cn/static/upload/image/20230111/1673427385140440.png)
|
||||
![长亮科技](https://www.sunline.cn/u_file/fileUpload/2021-06/25/2021062586431.png)
|
||||
![深圳易停车库](http://pmt2f499f.pic44.websiteonline.cn/upload/wv0c.png)
|
||||
![武汉日创科技](http://www.dragonwake.cn/static/css/default/img/logo.png)
|
||||
![易管智能](https://i4im-web.oss-cn-shanghai.aliyuncs.com/images/logo.png)
|
||||
![云帐房](https://www.yunzhangfang.com/assets/img/logo.4096cf52.png)
|
||||
![三诺生物](https://www.sinocare.com/sannuo/templates/web/img/bocweb-logo.svg)
|
||||
|
||||
郑州山水, 知氏教育
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
<name>nacos-api ${project.version}</name>
|
||||
<url>https://nacos.io</url>
|
||||
<description>Nacos api pom.xml file</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- reuse when you need to update grpc model -->
|
||||
|
@ -77,6 +77,10 @@ public class PropertyKeyConst {
|
||||
|
||||
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";
|
||||
|
||||
/**
|
||||
* Get the key value of some variable value from the system property.
|
||||
*/
|
||||
|
@ -28,6 +28,7 @@ import java.io.Serializable;
|
||||
* @author liuzunfei
|
||||
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
@Deprecated
|
||||
public class ClientAbilities implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3590789441404549261L;
|
||||
|
@ -29,6 +29,7 @@ import java.util.Objects;
|
||||
* @author liuzunfei
|
||||
* @version $Id: ServerAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
|
||||
*/
|
||||
@Deprecated
|
||||
public class ServerAbilities implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2120543002911304171L;
|
||||
|
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.Map;
|
||||
import java.util.HashMap;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
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,59 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
/**.
|
||||
* 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 + ":}";
|
||||
|
||||
/**
|
||||
* 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 + ":}";
|
||||
|
||||
|
@ -19,7 +19,7 @@ package com.alibaba.nacos.api.cmdb.pojo;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* CMDB lable.
|
||||
* CMDB label.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB preserverd entity type.
|
||||
* CMDB preserved entity type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
|
@ -86,9 +86,9 @@ public class Constants {
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
|
||||
|
||||
|
||||
public static final Integer SDK_GRPC_PORT_DEFAULT_OFFSET = 1000;
|
||||
|
||||
|
||||
public static final Integer CLUSTER_GRPC_PORT_DEFAULT_OFFSET = 1001;
|
||||
|
||||
/**
|
||||
@ -216,13 +216,20 @@ public class Constants {
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* The constants in config directory.
|
||||
*/
|
||||
public static class Config {
|
||||
|
||||
public static final String CONFIG_MODULE = "config";
|
||||
|
||||
|
||||
public static final String NOTIFY_HEADER = "notify";
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
@ -143,6 +144,15 @@ public interface ConfigService {
|
||||
* @return whether health
|
||||
*/
|
||||
String getServerStatus();
|
||||
|
||||
/**
|
||||
* add config filter.
|
||||
* It is recommended to use {@link com.alibaba.nacos.api.config.filter.AbstractConfigFilter} to expand the filter.
|
||||
*
|
||||
* @param configFilter filter
|
||||
* @since 2.3.0
|
||||
*/
|
||||
void addConfigFilter(IConfigFilter configFilter);
|
||||
|
||||
/**
|
||||
* Shutdown the resource service.
|
||||
|
@ -58,6 +58,11 @@ public enum ConfigType {
|
||||
*/
|
||||
YAML("yaml"),
|
||||
|
||||
/**
|
||||
* config type is "toml".
|
||||
*/
|
||||
TOML("toml"),
|
||||
|
||||
/**
|
||||
* not a real type.
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,11 +21,42 @@ import com.alibaba.nacos.api.remote.request.Request;
|
||||
|
||||
/**
|
||||
* abstract request of config module request,all config module request should extends this class.
|
||||
*
|
||||
* @author liuzunfei
|
||||
* @version $Id: ConfigCommonRequest.java, v 0.1 2020年07月13日 9:05 PM liuzunfei Exp $
|
||||
*/
|
||||
public abstract class AbstractConfigRequest extends Request {
|
||||
|
||||
|
||||
private String dataId;
|
||||
|
||||
private String group;
|
||||
|
||||
private String tenant;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return Constants.Config.CONFIG_MODULE;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -27,12 +27,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class ConfigPublishRequest extends AbstractConfigRequest {
|
||||
|
||||
String dataId;
|
||||
|
||||
String group;
|
||||
|
||||
String tenant;
|
||||
|
||||
String content;
|
||||
|
||||
String casMd5;
|
||||
@ -43,6 +37,13 @@ public class ConfigPublishRequest extends AbstractConfigRequest {
|
||||
|
||||
}
|
||||
|
||||
public ConfigPublishRequest(String dataId, String group, String tenant, String content) {
|
||||
this.content = content;
|
||||
super.setGroup(group);
|
||||
super.setTenant(tenant);
|
||||
super.setDataId(dataId);
|
||||
}
|
||||
|
||||
/**
|
||||
* get additional param.
|
||||
*
|
||||
@ -66,49 +67,6 @@ public class ConfigPublishRequest extends AbstractConfigRequest {
|
||||
additionMap.put(key, value);
|
||||
}
|
||||
|
||||
public ConfigPublishRequest(String dataId, String group, String tenant, String content) {
|
||||
this.content = content;
|
||||
this.dataId = dataId;
|
||||
this.group = group;
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>group</tt>.
|
||||
*
|
||||
* @return property value of group
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>group</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property group
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>content</tt>.
|
||||
*
|
||||
@ -163,21 +121,4 @@ public class ConfigPublishRequest extends AbstractConfigRequest {
|
||||
this.additionMap = additionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -26,12 +26,6 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
*/
|
||||
public class ConfigQueryRequest extends AbstractConfigRequest {
|
||||
|
||||
private String dataId;
|
||||
|
||||
private String group;
|
||||
|
||||
private String tenant;
|
||||
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
@ -50,60 +44,6 @@ public class ConfigQueryRequest extends AbstractConfigRequest {
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>group</tt>.
|
||||
*
|
||||
* @return property value of group
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>group</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property group
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tag</tt>.
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,12 +24,6 @@ package com.alibaba.nacos.api.config.remote.request;
|
||||
*/
|
||||
public class ConfigRemoveRequest extends AbstractConfigRequest {
|
||||
|
||||
String dataId;
|
||||
|
||||
String group;
|
||||
|
||||
String tenant;
|
||||
|
||||
String tag;
|
||||
|
||||
public ConfigRemoveRequest() {
|
||||
@ -37,19 +31,10 @@ public class ConfigRemoveRequest extends AbstractConfigRequest {
|
||||
}
|
||||
|
||||
public ConfigRemoveRequest(String dataId, String group, String tenant, String tag) {
|
||||
this.dataId = dataId;
|
||||
this.group = group;
|
||||
super.setDataId(dataId);
|
||||
super.setGroup(group);
|
||||
super.setTenant(tenant);
|
||||
this.tag = tag;
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,48 +55,4 @@ public class ConfigRemoveRequest extends AbstractConfigRequest {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>group</tt>.
|
||||
*
|
||||
* @return property value of group
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>group</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property group
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -26,18 +26,14 @@ import com.alibaba.nacos.api.config.remote.request.AbstractConfigRequest;
|
||||
*/
|
||||
public class ConfigChangeClusterSyncRequest extends AbstractConfigRequest {
|
||||
|
||||
String dataId;
|
||||
|
||||
String group;
|
||||
|
||||
String tenant;
|
||||
|
||||
String tag;
|
||||
|
||||
long lastModified;
|
||||
|
||||
boolean isBeta;
|
||||
|
||||
boolean isBatch;
|
||||
|
||||
public boolean isBeta() {
|
||||
return isBeta;
|
||||
}
|
||||
@ -46,58 +42,12 @@ public class ConfigChangeClusterSyncRequest extends AbstractConfigRequest {
|
||||
isBeta = beta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @return property value of dataId
|
||||
*/
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
public boolean isBatch() {
|
||||
return isBatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>dataId</tt>.
|
||||
*
|
||||
* @param dataId value to be assigned to property dataId
|
||||
*/
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>group</tt>.
|
||||
*
|
||||
* @return property value of group
|
||||
*/
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>group</tt>.
|
||||
*
|
||||
* @param group value to be assigned to property group
|
||||
*/
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @return property value of tenant
|
||||
*/
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>tenant</tt>.
|
||||
*
|
||||
* @param tenant value to be assigned to property tenant
|
||||
*/
|
||||
public void setTenant(String tenant) {
|
||||
this.tenant = tenant;
|
||||
public void setBatch(boolean batch) {
|
||||
isBatch = batch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,7 +181,7 @@ public class NacosException extends Exception {
|
||||
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.
|
||||
*/
|
||||
public static final int HTTP_CLIENT_ERROR_CODE = -500;
|
||||
|
@ -71,8 +71,4 @@ public class NacosApiException extends NacosException {
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
|
||||
public void setErrAbstract(String errAbstract) {
|
||||
this.errAbstract = errAbstract;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class NacosRuntimeException extends RuntimeException {
|
||||
|
||||
public static final String ERROR_MESSAGE_FORMAT = "errCode: %d, errMsg: %s ";
|
||||
|
||||
private int errCode;
|
||||
private final int errCode;
|
||||
|
||||
public NacosRuntimeException(int errCode) {
|
||||
super();
|
||||
@ -52,8 +52,4 @@ public class NacosRuntimeException extends RuntimeException {
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public void setErrCode(int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ private static final long serialVersionUID = 0L;
|
||||
if (key == null) { throw new NullPointerException(); }
|
||||
java.util.Map<String, String> map =
|
||||
internalGetHeaders().getMap();
|
||||
return map.containsKey(key) ? map.get(key) : defaultValue;
|
||||
return map.getOrDefault(key, defaultValue);
|
||||
}
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
@ -797,7 +797,7 @@ private static final long serialVersionUID = 0L;
|
||||
}
|
||||
private com.google.protobuf.MapField<String, String>
|
||||
internalGetMutableHeaders() {
|
||||
onChanged();;
|
||||
onChanged();
|
||||
if (headers_ == null) {
|
||||
headers_ = com.google.protobuf.MapField.newMapField(
|
||||
HeadersDefaultEntryHolder.defaultEntry);
|
||||
|
@ -17,21 +17,14 @@
|
||||
package com.alibaba.nacos.api.grpc.auto;
|
||||
|
||||
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.blockingServerStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
|
||||
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.asyncUnimplementedStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@javax.annotation.Generated(
|
||||
value = "by gRPC proto compiler (version 1.14.0)",
|
||||
|
@ -21,7 +21,7 @@ import com.alibaba.nacos.api.common.ResponseCode;
|
||||
/**
|
||||
* 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 1.2.0
|
||||
|
@ -68,9 +68,6 @@ public class DefaultRequestFuture implements RequestFuture {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public DefaultRequestFuture() {
|
||||
}
|
||||
|
||||
public DefaultRequestFuture(String connectionId, String requestId) {
|
||||
this(connectionId, requestId, null, null);
|
||||
}
|
||||
@ -167,7 +164,9 @@ public class DefaultRequestFuture implements RequestFuture {
|
||||
if (timeoutInnerTrigger != null) {
|
||||
timeoutInnerTrigger.triggerOnTimeout();
|
||||
}
|
||||
throw new TimeoutException("request timeout after " + timeout + " milliseconds, requestId=" + requestId);
|
||||
throw new TimeoutException(
|
||||
"request timeout after " + timeout + " milliseconds, requestId=" + requestId + ", connectionId="
|
||||
+ connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +190,8 @@ public class DefaultRequestFuture implements RequestFuture {
|
||||
@Override
|
||||
public void run() {
|
||||
setFailResult(new TimeoutException(
|
||||
"Timeout After " + requestCallBack.getTimeout() + " milliseconds,requestId =" + requestId));
|
||||
"Timeout After " + requestCallBack.getTimeout() + " milliseconds, requestId=" + requestId
|
||||
+ ", connectionId=" + connectionId));
|
||||
if (timeoutInnerTrigger != null) {
|
||||
timeoutInnerTrigger.triggerOnTimeout();
|
||||
}
|
||||
@ -203,7 +203,7 @@ public class DefaultRequestFuture implements RequestFuture {
|
||||
/**
|
||||
* triggered on timeout .
|
||||
*/
|
||||
public void triggerOnTimeout();
|
||||
void triggerOnTimeout();
|
||||
|
||||
}
|
||||
|
||||
@ -215,14 +215,4 @@ public class DefaultRequestFuture implements RequestFuture {
|
||||
public String getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>timeoutFuture</tt>.
|
||||
*
|
||||
* @param timeoutFuture value to be assigned to property timeoutFuture
|
||||
*/
|
||||
public void setTimeoutFuture(ScheduledFuture timeoutFuture) {
|
||||
this.timeoutFuture = timeoutFuture;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,4 +38,6 @@ public class RemoteConstants {
|
||||
public static final String LABEL_MODULE_CONFIG = "config";
|
||||
|
||||
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,
|
||||
"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,
|
||||
"com.alibaba.nacos.remote.ServerCommonScheduler");
|
||||
|
||||
public RpcScheduledExecutor(int corePoolSize, final String threadName) {
|
||||
super(corePoolSize, new ThreadFactory() {
|
||||
private AtomicLong index = new AtomicLong();
|
||||
private final AtomicLong index = new AtomicLong();
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
|
@ -30,11 +30,31 @@ public class ConnectResetRequest extends ServerRequest {
|
||||
|
||||
String serverPort;
|
||||
|
||||
String connectionId;
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
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>.
|
||||
*
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
package com.alibaba.nacos.api.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.ability.ClientAbilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -31,12 +29,12 @@ public class ConnectionSetupRequest extends InternalRequest {
|
||||
|
||||
private String clientVersion;
|
||||
|
||||
private ClientAbilities abilities;
|
||||
|
||||
private String tenant;
|
||||
|
||||
private Map<String, String> labels = new HashMap<>();
|
||||
|
||||
private Map<String, Boolean> abilityTable;
|
||||
|
||||
public ConnectionSetupRequest() {
|
||||
}
|
||||
|
||||
@ -64,11 +62,11 @@ public class ConnectionSetupRequest extends InternalRequest {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
public ClientAbilities getAbilities() {
|
||||
return abilities;
|
||||
public Map<String, Boolean> getAbilityTable() {
|
||||
return abilityTable;
|
||||
}
|
||||
|
||||
public void setAbilities(ClientAbilities abilities) {
|
||||
this.abilities = abilities;
|
||||
public void setAbilityTable(Map<String, Boolean> abilityTable) {
|
||||
this.abilityTable = abilityTable;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
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.Map;
|
||||
|
||||
@ -34,7 +37,25 @@ public class RequestMeta {
|
||||
private String clientVersion = "";
|
||||
|
||||
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>.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -52,15 +52,6 @@ public enum ResponseCode {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>code</tt>.
|
||||
*
|
||||
* @param code value to be assigned to property code
|
||||
*/
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>desc</tt>.
|
||||
*
|
||||
@ -69,13 +60,4 @@ public enum ResponseCode {
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>desc</tt>.
|
||||
*
|
||||
* @param desc value to be assigned to property desc
|
||||
*/
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,15 @@ public class ServerCheckResponse extends Response {
|
||||
|
||||
private String connectionId;
|
||||
|
||||
private boolean supportAbilityNegotiation;
|
||||
|
||||
public ServerCheckResponse() {
|
||||
|
||||
}
|
||||
|
||||
public ServerCheckResponse(String connectionId) {
|
||||
public ServerCheckResponse(String connectionId, boolean supportAbilityNegotiation) {
|
||||
this.connectionId = connectionId;
|
||||
this.supportAbilityNegotiation = supportAbilityNegotiation;
|
||||
}
|
||||
|
||||
public String getConnectionId() {
|
||||
@ -41,4 +44,12 @@ public class ServerCheckResponse extends Response {
|
||||
public void setConnectionId(String connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
||||
public boolean isSupportAbilityNegotiation() {
|
||||
return supportAbilityNegotiation;
|
||||
}
|
||||
|
||||
public void setSupportAbilityNegotiation(boolean supportAbilityNegotiation) {
|
||||
this.supportAbilityNegotiation = supportAbilityNegotiation;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.response;
|
||||
|
||||
/**.
|
||||
* @author Daydreamer
|
||||
* @description Server tells the client that the connection is established
|
||||
* @date 2022/7/12 19:21
|
||||
**/
|
||||
public class SetupAckResponse extends Response {
|
||||
|
||||
}
|
@ -34,6 +34,8 @@ import static com.alibaba.nacos.api.common.Constants.Naming.CMDB_CONTEXT_TYPE;
|
||||
*/
|
||||
public abstract class AbstractCmdbSelector<T extends Instance> implements Selector<List<T>, CmdbContext<T>, String> {
|
||||
|
||||
private static final long serialVersionUID = 56587385358330901L;
|
||||
|
||||
/**
|
||||
* the labels expression.
|
||||
*/
|
||||
|
@ -64,7 +64,7 @@ public interface Selector<R, C, E> extends Serializable {
|
||||
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.
|
||||
*/
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package com.alibaba.nacos.api.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
@ -93,8 +92,7 @@ public class NetUtils {
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
//ignore
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
@ -103,8 +101,7 @@ public class NetUtils {
|
||||
|
||||
try {
|
||||
return InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
//ignore
|
||||
} catch (UnknownHostException ignore) {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -22,6 +22,8 @@ com.alibaba.nacos.api.remote.request.PushAckRequest
|
||||
com.alibaba.nacos.api.remote.request.ServerCheckRequest
|
||||
com.alibaba.nacos.api.remote.request.ServerLoaderInfoRequest
|
||||
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.ConnectResetResponse
|
||||
com.alibaba.nacos.api.remote.response.ErrorResponse
|
||||
|
@ -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.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ClusterClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public 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.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SdkClientAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testGetStaticAbilities() {
|
||||
// TODO add the sdk client abilities.
|
||||
assertTrue(SdkClientAbilities.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.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerAbilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testGetStaticAbilities() {
|
||||
// TODO add the server abilities.
|
||||
assertTrue(ServerAbilities.getStaticAbilities().isEmpty());
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.cmdb.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EntityEventTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
EntityEvent entity = new EntityEvent();
|
||||
entity.setEntityName("test-entity");
|
||||
entity.setEntityType("CMDB");
|
||||
entity.setType(EntityEventType.ENTITY_ADD_OR_UPDATE);
|
||||
String actual = mapper.writeValueAsString(entity);
|
||||
System.out.println(actual);
|
||||
assertTrue(actual.contains("\"entityName\":\"test-entity\""));
|
||||
assertTrue(actual.contains("\"entityType\":\"CMDB\""));
|
||||
assertTrue(actual.contains("\"type\":\"ENTITY_ADD_OR_UPDATE\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
||||
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
||||
assertEquals("test-entity", entity.getEntityName());
|
||||
assertEquals("CMDB", entity.getEntityType());
|
||||
assertEquals(EntityEventType.ENTITY_REMOVE, entity.getType());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.cmdb.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EntityTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
Entity entity = new Entity();
|
||||
entity.setName("test-entity");
|
||||
entity.setType(PreservedEntityTypes.ip.name());
|
||||
entity.setLabels(Collections.singletonMap("test-label-key", "test-label-value"));
|
||||
String actual = mapper.writeValueAsString(entity);
|
||||
assertTrue(actual.contains("\"type\":\"ip\""));
|
||||
assertTrue(actual.contains("\"name\":\"test-entity\""));
|
||||
assertTrue(actual.contains("\"labels\":{\"test-label-key\":\"test-label-value\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
||||
Entity entity = mapper.readValue(json, Entity.class);
|
||||
assertEquals("test-entity", entity.getName());
|
||||
assertEquals(PreservedEntityTypes.service.name(), entity.getType());
|
||||
assertEquals(1, entity.getLabels().size());
|
||||
assertTrue(entity.getLabels().containsKey("test-label-key"));
|
||||
assertEquals("test-label-value", entity.getLabels().get("test-label-key"));
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.cmdb.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LabelTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
Label label = new Label();
|
||||
label.setName("test-label");
|
||||
label.setDescription("CMDB description");
|
||||
label.setValues(Collections.singletonMap("test-value", "test-value").keySet());
|
||||
String actual = mapper.writeValueAsString(label);
|
||||
System.out.println(actual);
|
||||
assertTrue(actual.contains("\"name\":\"test-label\""));
|
||||
assertTrue(actual.contains("\"description\":\"CMDB description\""));
|
||||
assertTrue(actual.contains("\"values\":[\"test-value\"]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
||||
Label label = mapper.readValue(json, Label.class);
|
||||
assertEquals("test-label", label.getName());
|
||||
assertEquals("CMDB description", label.getDescription());
|
||||
assertEquals(1, label.getValues().size());
|
||||
assertEquals("test-value", label.getValues().iterator().next());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class ConfigChangeEventTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
||||
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
||||
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
||||
assertEquals(1, event.getChangeItems().size());
|
||||
assertEquals("testKey", event.getChangeItem("test").getKey());
|
||||
assertNull(event.getChangeItem("test").getOldValue());
|
||||
assertEquals("testValue", event.getChangeItem("test").getNewValue());
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class ConfigChangeItemTest {
|
||||
|
||||
@Test
|
||||
public void testSetNewValue() {
|
||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||
item.setType(PropertyChangeType.ADDED);
|
||||
assertEquals("testKey", item.getKey());
|
||||
assertNull(item.getOldValue());
|
||||
assertEquals("testValue", item.getNewValue());
|
||||
assertEquals(PropertyChangeType.ADDED, item.getType());
|
||||
item.setOldValue("testValue");
|
||||
item.setNewValue("testValue2");
|
||||
item.setType(PropertyChangeType.MODIFIED);
|
||||
assertEquals("testKey", item.getKey());
|
||||
assertEquals("testValue", item.getOldValue());
|
||||
assertEquals("testValue2", item.getNewValue());
|
||||
assertEquals(PropertyChangeType.MODIFIED, item.getType());
|
||||
|
||||
item.setKey("deletedKey");
|
||||
item.setType(PropertyChangeType.DELETED);
|
||||
assertEquals("deletedKey", item.getKey());
|
||||
assertEquals(PropertyChangeType.DELETED, item.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||
item.setType(PropertyChangeType.ADDED);
|
||||
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
||||
item.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigTypeTest {
|
||||
|
||||
@Test
|
||||
public void isValidType() {
|
||||
assertTrue(ConfigType.isValidType("xml"));
|
||||
assertTrue(ConfigType.isValidType("properties"));
|
||||
assertTrue(ConfigType.isValidType("json"));
|
||||
assertTrue(ConfigType.isValidType("text"));
|
||||
assertTrue(ConfigType.isValidType("html"));
|
||||
assertTrue(ConfigType.isValidType("yaml"));
|
||||
assertTrue(ConfigType.isValidType("unset"));
|
||||
assertFalse(ConfigType.isValidType(""));
|
||||
assertFalse(ConfigType.isValidType("yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultType() {
|
||||
assertEquals("text", ConfigType.getDefaultType().getType());
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.config.ability;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class ServerConfigAbilityTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
ServerConfigAbility ability = new ServerConfigAbility();
|
||||
ability.setSupportRemoteMetrics(true);
|
||||
assertEquals(ability, ability);
|
||||
assertFalse(ability.equals(null));
|
||||
assertFalse(ability.equals(new ClientConfigAbility()));
|
||||
ServerConfigAbility newOne = new ServerConfigAbility();
|
||||
assertNotEquals(ability, newOne);
|
||||
newOne.setSupportRemoteMetrics(true);
|
||||
assertEquals(ability, newOne);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.config.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class AbstractListenerTest {
|
||||
|
||||
@Test
|
||||
public void testGetExecutor() {
|
||||
// Default listener executor is null.
|
||||
assertNull(new AbstractListener() {
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
}
|
||||
}.getExecutor());
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.config.listener;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class AbstractSharedListenerTest {
|
||||
|
||||
private static final String CONFIG_CONTENT = "test";
|
||||
|
||||
private static Map<String, String> receivedMap;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
receivedMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillContext() {
|
||||
assertEquals(0, receivedMap.size());
|
||||
MockShardListener listener = new MockShardListener();
|
||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||
assertEquals(2, receivedMap.size());
|
||||
assertNull(receivedMap.get("group"));
|
||||
assertNull(receivedMap.get("dataId"));
|
||||
listener.fillContext("aaa", "ggg");
|
||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||
assertEquals(2, receivedMap.size());
|
||||
assertEquals("ggg", receivedMap.get("group"));
|
||||
assertEquals("aaa", receivedMap.get("dataId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExecutor() {
|
||||
// Default listener executor is null.
|
||||
assertNull(new MockShardListener().getExecutor());
|
||||
}
|
||||
|
||||
private static class MockShardListener extends AbstractSharedListener {
|
||||
|
||||
@Override
|
||||
public void innerReceive(String dataId, String group, String configInfo) {
|
||||
assertEquals(CONFIG_CONTENT, configInfo);
|
||||
receivedMap.put("group", group);
|
||||
receivedMap.put("dataId", dataId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class BasedConfigRequestTest {
|
||||
|
||||
protected static ObjectMapper mapper;
|
||||
|
||||
protected static final String DATA_ID = "test_data";
|
||||
|
||||
protected static final String GROUP = "group";
|
||||
|
||||
protected static final String TENANT = "test_tenant";
|
||||
|
||||
protected static final String MD5 = "test_MD5";
|
||||
|
||||
protected static final String TAG = "tag";
|
||||
|
||||
protected static final String[] KEY = new String[] {DATA_ID, GROUP, TENANT};
|
||||
|
||||
protected static final Map<String, String> HEADERS = new HashMap<>();
|
||||
|
||||
protected static final String HEADER_KEY = "header1";
|
||||
|
||||
protected static final String HEADER_VALUE = "test_header1";
|
||||
|
||||
protected static final String CONTENT = "content";
|
||||
|
||||
static {
|
||||
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
public abstract void testSerialize() throws JsonProcessingException;
|
||||
|
||||
public abstract void testDeserialize() throws JsonProcessingException;
|
||||
|
||||
protected String injectRequestUuId(Request request) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
request.setRequestId(uuid);
|
||||
return uuid;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.CACHE_DATA;
|
||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ClientConfigMetricRequest clientMetrics = new ClientConfigMetricRequest();
|
||||
clientMetrics.putAllHeader(HEADERS);
|
||||
clientMetrics.getMetricsKeys()
|
||||
.add(ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY)));
|
||||
clientMetrics.getMetricsKeys()
|
||||
.add(ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA, String.join("+", KEY)));
|
||||
final String requestId = injectRequestUuId(clientMetrics);
|
||||
String json = mapper.writeValueAsString(clientMetrics);
|
||||
assertTrue(json.contains("\"type\":\"" + "cacheData" + "\""));
|
||||
assertTrue(json.contains("\"type\":\"" + "snapshotData" + "\""));
|
||||
assertTrue(json.contains("\"key\":\"" + String.join("+", KEY) + "\""));
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json =
|
||||
"{\"headers\":{\"header1\":\"test_header1\"}," + "\"metricsKeys\":[{\"type\":\"cacheData\",\"key\":"
|
||||
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
||||
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
||||
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
||||
assertEquals(actual.getMetricsKeys().size(), 2);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsKeysEquals() {
|
||||
String dataKey = String.join("+", KEY);
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||
assertEquals(key, key);
|
||||
assertFalse(key.equals(null));
|
||||
assertFalse(key.equals(new ClientConfigMetricRequest()));
|
||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey
|
||||
.build(SNAPSHOT_DATA, dataKey);
|
||||
assertNotEquals(key, newOne);
|
||||
newOne.setType(CACHE_DATA);
|
||||
assertEquals(key, newOne);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsHashCode() {
|
||||
String dataKey = String.join("+", KEY);
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricsToString() {
|
||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY));
|
||||
assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
||||
configBatchListenRequest.putAllHeader(HEADERS);
|
||||
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
||||
final String requestId = injectRequestUuId(configBatchListenRequest);
|
||||
String json = mapper.writeValueAsString(configBatchListenRequest);
|
||||
assertTrue(json.contains("\"listen\":" + "true"));
|
||||
assertTrue(json.contains(
|
||||
"\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"listen\":true,"
|
||||
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
||||
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
||||
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
||||
assertEquals(actual.isListen(), true);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
assertEquals(actual.getConfigListenContexts().size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigListenContextToString() {
|
||||
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
||||
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
||||
assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}",
|
||||
configBatchListenRequest.getConfigListenContexts().get(0).toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
||||
configChangeNotifyRequest.putAllHeader(HEADERS);
|
||||
requestId = injectRequestUuId(configChangeNotifyRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configChangeNotifyRequest);
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"dataId\":\"" + DATA_ID));
|
||||
assertTrue(json.contains("\"group\":\"" + GROUP));
|
||||
assertTrue(json.contains("\"tenant\":\"" + TENANT));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
||||
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
||||
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigPublishRequest configPublishRequest;
|
||||
|
||||
private static final String TAG_PARAM = "tag";
|
||||
|
||||
private static final String APP_NAME_PARAM = "appName";
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
||||
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
||||
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
||||
configPublishRequest.setCasMd5(MD5);
|
||||
configPublishRequest.putAllHeader(HEADERS);
|
||||
requestId = injectRequestUuId(configPublishRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configPublishRequest);
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"dataId\":\"" + DATA_ID));
|
||||
assertTrue(json.contains("\"group\":\"" + GROUP));
|
||||
assertTrue(json.contains("\"tenant\":\"" + TENANT));
|
||||
assertTrue(json.contains("\"content\":\"" + CONTENT));
|
||||
assertTrue(json.contains("\"casMd5\":\"" + MD5));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
||||
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
||||
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
||||
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getContent(), CONTENT);
|
||||
assertEquals(actual.getCasMd5(), MD5);
|
||||
assertEquals(actual.getAdditionParam(TAG_PARAM), TAG_PARAM);
|
||||
assertEquals(actual.getAdditionParam(APP_NAME_PARAM), APP_NAME_PARAM);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigQueryRequest configQueryRequest;
|
||||
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
||||
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
||||
configQueryRequest.putAllHeader(headers);
|
||||
configQueryRequest.setTag(TAG);
|
||||
requestId = injectRequestUuId(configQueryRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotify() {
|
||||
assertTrue(configQueryRequest.isNotify());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configQueryRequest);
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"dataId\":\"" + DATA_ID));
|
||||
assertTrue(json.contains("\"group\":\"" + GROUP));
|
||||
assertTrue(json.contains("\"tenant\":\"" + TENANT));
|
||||
assertTrue(json.contains("\"tag\":\"" + TAG));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
||||
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
||||
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.config.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigRemoveRequest configRemoveRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
||||
requestId = injectRequestUuId(configRemoveRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configRemoveRequest);
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"dataId\":\"" + DATA_ID));
|
||||
assertTrue(json.contains("\"group\":\"" + GROUP));
|
||||
assertTrue(json.contains("\"tenant\":\"" + TENANT));
|
||||
assertTrue(json.contains("\"tag\":\"" + TAG));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
||||
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
||||
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getTag(), TAG);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.config.remote.request.cluster;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||
|
||||
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
||||
|
||||
String requestId;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
||||
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
||||
configChangeClusterSyncRequest.setGroup(GROUP);
|
||||
configChangeClusterSyncRequest.setTenant(TENANT);
|
||||
configChangeClusterSyncRequest.setTag(TAG);
|
||||
configChangeClusterSyncRequest.setBeta(Boolean.TRUE);
|
||||
configChangeClusterSyncRequest.setLastModified(0L);
|
||||
configChangeClusterSyncRequest.setBatch(false);
|
||||
configChangeClusterSyncRequest.putAllHeader(HEADERS);
|
||||
requestId = injectRequestUuId(configChangeClusterSyncRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configChangeClusterSyncRequest);
|
||||
System.out.println(json);
|
||||
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
|
||||
assertTrue(json.contains("\"dataId\":\"" + DATA_ID));
|
||||
assertTrue(json.contains("\"group\":\"" + GROUP));
|
||||
assertTrue(json.contains("\"tenant\":\"" + TENANT));
|
||||
assertTrue(json.contains("\"tag\":\"" + TAG));
|
||||
assertTrue(json.contains("\"beta\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"lastModified\":" + 0));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
||||
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
||||
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
||||
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
||||
assertEquals(actual.getDataId(), DATA_ID);
|
||||
assertEquals(actual.getGroup(), GROUP);
|
||||
assertEquals(actual.getTenant(), TENANT);
|
||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
||||
assertEquals(actual.getLastModified(), 0L);
|
||||
assertTrue(actual.isBeta());
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class BasedConfigResponseTest extends BasedConfigRequestTest {
|
||||
|
||||
protected String requestId;
|
||||
|
||||
@Override
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
|
||||
}
|
||||
|
||||
public abstract void testSerializeSuccessResponse() throws JsonProcessingException;
|
||||
|
||||
public abstract void testSerializeFailResponse() throws JsonProcessingException;
|
||||
|
||||
protected String injectResponseUuId(Response response) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
response.setRequestId(uuid);
|
||||
return uuid;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ClientConfigMetricResponse clientConfigMetricResponse;
|
||||
|
||||
Map<String, Object> metric = new HashMap<>(16);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
metric.put("m1", "v1");
|
||||
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
||||
clientConfigMetricResponse.setMetrics(metric);
|
||||
clientConfigMetricResponse.putMetric("m2", "v2");
|
||||
requestId = injectResponseUuId(clientConfigMetricResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(clientConfigMetricResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"6ef9237b-24f3-448a-87fc-713f18ee06a1\","
|
||||
+ "\"metrics\":{\"m1\":\"v1\",\"m2\":\"v2\"},\"success\":true}";
|
||||
ClientConfigMetricResponse actual = mapper.readValue(json, ClientConfigMetricResponse.class);
|
||||
assertTrue(actual.isSuccess());
|
||||
assertEquals(actual.getResultCode(), ResponseCode.SUCCESS.getCode());
|
||||
assertEquals(actual.getMetrics(), metric);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
||||
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
||||
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
assertTrue(json.contains(
|
||||
"\"changedConfigs\":[{\"group\":\"group\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse
|
||||
.buildFailResponse("Fail");
|
||||
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
assertTrue(json.contains("\"message\":\"Fail\""));
|
||||
assertTrue(json.contains("\"success\":false"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"061e36b0-c7bd-4fd0-950c-73b13ca1cb2f\","
|
||||
+ "\"changedConfigs\":[{\"group\":\"group\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"success\":true}";
|
||||
ConfigChangeBatchListenResponse actual = mapper.readValue(json, ConfigChangeBatchListenResponse.class);
|
||||
assertTrue(actual.isSuccess());
|
||||
assertEquals(ResponseCode.SUCCESS.getCode(), actual.getResultCode());
|
||||
assertEquals("061e36b0-c7bd-4fd0-950c-73b13ca1cb2f", actual.getRequestId());
|
||||
assertEquals(TENANT, actual.getChangedConfigs().get(0).getTenant());
|
||||
assertEquals(GROUP, actual.getChangedConfigs().get(0).getGroup());
|
||||
assertEquals(DATA_ID, actual.getChangedConfigs().get(0).getDataId());
|
||||
assertEquals("ConfigContext{group='group', dataId='test_data', tenant='test_tenant'}",
|
||||
actual.getChangedConfigs().get(0).toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
||||
requestId = injectResponseUuId(configChangeNotifyResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configChangeNotifyResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigPublishResponse configPublishResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
||||
requestId = injectResponseUuId(configPublishResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configPublishResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ConfigPublishResponse configPublishResponse = ConfigPublishResponse.buildFailResponse(500, "Fail");
|
||||
String json = mapper.writeValueAsString(configPublishResponse);
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":500"));
|
||||
assertTrue(json.contains("\"message\":\"Fail\""));
|
||||
assertTrue(json.contains("\"success\":false"));
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigQueryResponse configQueryResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
||||
configQueryResponse.setContentType("text");
|
||||
configQueryResponse.setEncryptedDataKey("encryptedKey");
|
||||
configQueryResponse.setLastModified(1111111L);
|
||||
configQueryResponse.setMd5(MD5);
|
||||
configQueryResponse.setTag(TAG);
|
||||
requestId = injectResponseUuId(configQueryResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configQueryResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"md5\":\"" + MD5 + "\""));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
assertTrue(json.contains("\"content\":\"success\""));
|
||||
assertTrue(json.contains("\"contentType\":\"text\""));
|
||||
assertTrue(json.contains("\"lastModified\":1111111"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ConfigQueryResponse configQueryResponse = ConfigQueryResponse.buildFailResponse(500, "Fail");
|
||||
String json = mapper.writeValueAsString(configQueryResponse);
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":500"));
|
||||
assertTrue(json.contains("\"message\":\"Fail\""));
|
||||
assertTrue(json.contains("\"success\":false"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testDeserialize() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"2239753e-e682-441c-83cf-fb8129ca68a4\","
|
||||
+ "\"content\":\"success\",\"encryptedDataKey\":\"encryptedKey\",\"contentType\":\"text\",\"md5\":\"test_MD5\","
|
||||
+ "\"lastModified\":1111111,\"tag\":\"tag\",\"beta\":false,\"success\":true}\n";
|
||||
ConfigQueryResponse actual = mapper.readValue(json, ConfigQueryResponse.class);
|
||||
assertTrue(actual.isSuccess());
|
||||
assertEquals(ResponseCode.SUCCESS.getCode(), actual.getResultCode());
|
||||
assertEquals("success", actual.getContent());
|
||||
assertEquals("text", actual.getContentType());
|
||||
assertEquals("2239753e-e682-441c-83cf-fb8129ca68a4", actual.getRequestId());
|
||||
assertEquals(MD5, actual.getMd5());
|
||||
assertEquals(TAG, actual.getTag());
|
||||
assertEquals("text", actual.getContentType());
|
||||
assertEquals(1111111L, actual.getLastModified());
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.config.remote.response;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigRemoveResponse configRemoveResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
||||
requestId = injectResponseUuId(configRemoveResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configRemoveResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
ConfigRemoveResponse configRemoveResponse = ConfigRemoveResponse.buildFailResponse("Fail");
|
||||
String json = mapper.writeValueAsString(configRemoveResponse);
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
assertTrue(json.contains("\"message\":\"Fail\""));
|
||||
assertTrue(json.contains("\"success\":false"));
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.config.remote.response.cluster;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.response.BasedConfigResponseTest;
|
||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
||||
|
||||
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
||||
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||
String json = mapper.writeValueAsString(configChangeClusterSyncResponse);
|
||||
assertTrue(json.contains("\"success\":" + Boolean.TRUE));
|
||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||
assertTrue(json.contains("\"errorCode\":0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class NacosExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
NacosException exception = new NacosException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||
assertEquals("ErrCode:0, ErrMsg:", exception.toString());
|
||||
exception.setErrCode(NacosException.INVALID_PARAM);
|
||||
exception.setErrMsg("test");
|
||||
assertEquals("ErrCode:400, ErrMsg:test", exception.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrMsg() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
assertEquals("ErrCode:500, ErrMsg:test", exception.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("cause test", exception.getErrMsg());
|
||||
assertEquals("ErrCode:500, ErrMsg:cause test", exception.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithMultiCauses() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
||||
new RuntimeException("cause test", new RuntimeException("multi")));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("multi", exception.getErrMsg());
|
||||
assertEquals("ErrCode:500, ErrMsg:multi", exception.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithFull() {
|
||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
||||
new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
assertEquals("ErrCode:500, ErrMsg:test", exception.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.exception.api;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class NacosApiExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
NacosApiException exception = new NacosApiException();
|
||||
assertEquals(0, exception.getErrCode());
|
||||
assertEquals(0, exception.getDetailErrCode());
|
||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||
assertEquals(Constants.NULL, exception.getErrAbstract());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithoutCause() {
|
||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
||||
assertEquals(500, exception.getErrCode());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getMsg(), exception.getErrAbstract());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
||||
new RuntimeException("cause test"), "test");
|
||||
assertEquals(500, exception.getErrCode());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
||||
assertEquals("test", exception.getErrMsg());
|
||||
assertEquals(ErrorCode.SERVER_ERROR.getMsg(), exception.getErrAbstract());
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class NacosDeserializationExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException();
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
assertNull(exception.getTargetClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetClass() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class);
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 101, errMsg: Nacos deserialize for class [%s] failed. ",
|
||||
NacosDeserializationExceptionTest.class.getName()), exception.getMessage());
|
||||
assertEquals(NacosDeserializationExceptionTest.class, exception.getTargetClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetType() {
|
||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||
NacosDeserializationException exception = new NacosDeserializationException(type);
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(
|
||||
String.format("errCode: 101, errMsg: Nacos deserialize for class [%s] failed. ", type.getTypeName()),
|
||||
exception.getMessage());
|
||||
assertNull(exception.getTargetClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
||||
assertNull(exception.getTargetClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetClassAndCause() {
|
||||
NacosDeserializationException exception = new NacosDeserializationException(
|
||||
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 101, errMsg: Nacos deserialize for class [%s] failed, cause error[%s]. ",
|
||||
NacosDeserializationExceptionTest.class.getName(), "test"), exception.getMessage());
|
||||
assertEquals(NacosDeserializationExceptionTest.class, exception.getTargetClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithTargetTypeAndCause() {
|
||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 101, errMsg: Nacos deserialize for class [%s] failed, cause error[%s]. ",
|
||||
type.getTypeName(), "test"), exception.getMessage());
|
||||
assertNull(exception.getTargetClass());
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.exception.runtime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class NacosLoadExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
NacosLoadException exception = new NacosLoadException("test");
|
||||
assertEquals("test", exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class NacosRuntimeExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCode() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCodeAndMsg() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithErrorCodeAndCause() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertEquals("java.lang.RuntimeException: test", exception.getMessage());
|
||||
assertTrue(exception.getCause() instanceof RuntimeException);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithFull() {
|
||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||
"test", new RuntimeException("cause test"));
|
||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||
assertTrue(exception.getCause() instanceof RuntimeException);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.exception.runtime;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class NacosSerializationExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
NacosSerializationException exception = new NacosSerializationException();
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertNull(exception.getMessage());
|
||||
assertNull(exception.getSerializedClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithSerializedClass() {
|
||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
||||
NacosSerializationExceptionTest.class.getName()), exception.getMessage());
|
||||
assertEquals(NacosSerializationExceptionTest.class, exception.getSerializedClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithCause() {
|
||||
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
||||
assertNull(exception.getSerializedClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorWithSerializedClassAndCause() {
|
||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
||||
new RuntimeException("test"));
|
||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
||||
NacosSerializationExceptionTest.class.getName(), "test"), exception.getMessage());
|
||||
assertEquals(NacosSerializationExceptionTest.class, exception.getSerializedClass());
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.remote;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AbstractPushCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
public void testAbstractPushCallBack() {
|
||||
AbstractPushCallBack callBack = new AbstractPushCallBack(2000) {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
testValue = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Throwable e) {
|
||||
testValue = false;
|
||||
}
|
||||
};
|
||||
assertEquals(2000, callBack.getTimeout());
|
||||
assertFalse(testValue);
|
||||
callBack.onSuccess();
|
||||
assertTrue(testValue);
|
||||
callBack.onFail(new RuntimeException("test"));
|
||||
assertFalse(testValue);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.remote;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.ErrorResponse;
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AbstractRequestCallBackTest {
|
||||
|
||||
boolean testValue;
|
||||
|
||||
@Test
|
||||
public void testAbstractPushCallBack() {
|
||||
AbstractRequestCallBack callBack = new AbstractRequestCallBack() {
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Response response) {
|
||||
testValue = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
testValue = false;
|
||||
}
|
||||
};
|
||||
assertEquals(3000L, callBack.getTimeout());
|
||||
assertFalse(testValue);
|
||||
callBack.onResponse(new ErrorResponse());
|
||||
assertTrue(testValue);
|
||||
callBack.onException(new RuntimeException("test"));
|
||||
assertFalse(testValue);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,328 @@
|
||||
/*
|
||||
* 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.remote;
|
||||
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultRequestFutureTest {
|
||||
|
||||
private static final String CONNECTION_ID = "1233_1.1.1.1_3306";
|
||||
|
||||
private static final String REQUEST_ID = "10000";
|
||||
|
||||
@Mock
|
||||
private Response response;
|
||||
|
||||
@Mock
|
||||
private ExecutorService executor;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get();
|
||||
assertEquals(response, actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setFailResult(new RuntimeException("test"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get();
|
||||
assertNull(actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get(1000L);
|
||||
assertEquals(response, actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get(-1L);
|
||||
assertEquals(response, actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException {
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||
requestFuture.get(100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get();
|
||||
assertEquals(response, actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
assertFalse(trigger.isTimeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setFailResult(new RuntimeException("test"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get();
|
||||
assertNull(actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
assertFalse(trigger.isTimeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
Response actual = requestFuture.get(1000L);
|
||||
assertEquals(response, actual);
|
||||
assertEquals(CONNECTION_ID, requestFuture.getConnectionId());
|
||||
assertEquals(REQUEST_ID, requestFuture.getRequestId());
|
||||
assertTrue(requestFuture.isDone());
|
||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||
assertFalse(trigger.isTimeout);
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
public void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||
try {
|
||||
requestFuture.get(100L);
|
||||
} finally {
|
||||
assertTrue(trigger.isTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(200L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
TimeUnit.MILLISECONDS.sleep(250);
|
||||
assertEquals(response, callback.response);
|
||||
assertNull(callback.exception);
|
||||
assertFalse(trigger.isTimeout);
|
||||
assertEquals(callback, requestFuture.getRequestCallBack());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(executor, 200L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setResponse(response);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
TimeUnit.MILLISECONDS.sleep(250);
|
||||
assertEquals(callback, requestFuture.getRequestCallBack());
|
||||
verify(executor).execute(any(DefaultRequestFuture.CallBackHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(1000L);
|
||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
requestFuture.setFailResult(new RuntimeException("test"));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
TimeUnit.MILLISECONDS.sleep(250);
|
||||
assertNull(callback.response);
|
||||
assertTrue(callback.exception instanceof RuntimeException);
|
||||
assertFalse(trigger.isTimeout);
|
||||
assertEquals(callback, requestFuture.getRequestCallBack());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testASyncGetResponseFailureWithTimeout() throws InterruptedException {
|
||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||
MockRequestCallback callback = new MockRequestCallback(100L);
|
||||
final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
assertNull(callback.response);
|
||||
assertTrue(callback.exception instanceof TimeoutException);
|
||||
assertTrue(trigger.isTimeout);
|
||||
assertEquals(callback, requestFuture.getRequestCallBack());
|
||||
}
|
||||
|
||||
private class MockTimeoutInnerTrigger implements DefaultRequestFuture.TimeoutInnerTrigger {
|
||||
|
||||
boolean isTimeout;
|
||||
|
||||
@Override
|
||||
public void triggerOnTimeout() {
|
||||
isTimeout = true;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockRequestCallback implements RequestCallBack<Response> {
|
||||
|
||||
private final Executor executor;
|
||||
|
||||
private final long timeout;
|
||||
|
||||
private Response response;
|
||||
|
||||
private Throwable exception;
|
||||
|
||||
public MockRequestCallback(long timeout) {
|
||||
this(null, timeout);
|
||||
}
|
||||
|
||||
public MockRequestCallback(Executor executor, long timeout) {
|
||||
this.executor = executor;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Response response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.remote;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RpcScheduledExecutorTest {
|
||||
|
||||
private static final String NAME = "test.rpc.thread";
|
||||
|
||||
Map<String, String> threadNameMap = new HashMap<>();
|
||||
|
||||
@Test
|
||||
public void testRpcScheduledExecutor() throws InterruptedException {
|
||||
RpcScheduledExecutor executor = new RpcScheduledExecutor(2, NAME);
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
executor.submit(new TestRunner(1, latch));
|
||||
executor.submit(new TestRunner(2, latch));
|
||||
latch.await(1, TimeUnit.SECONDS);
|
||||
assertEquals(2, threadNameMap.size());
|
||||
assertEquals(NAME + ".0", threadNameMap.get("1"));
|
||||
assertEquals(NAME + ".1", threadNameMap.get("2"));
|
||||
}
|
||||
|
||||
private class TestRunner implements Runnable {
|
||||
|
||||
int id;
|
||||
|
||||
CountDownLatch latch;
|
||||
|
||||
public TestRunner(int id, CountDownLatch latch) {
|
||||
this.id = id;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
threadNameMap.put(String.valueOf(id), Thread.currentThread().getName());
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class BasicRequestTest {
|
||||
|
||||
protected ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConnectResetRequestTest extends BasicRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws Exception {
|
||||
ConnectResetRequest request = new ConnectResetRequest();
|
||||
request.setServerIp("127.0.0.1");
|
||||
request.setServerPort("8888");
|
||||
request.setRequestId("1");
|
||||
request.setConnectionId("11111_127.0.0.1_8888");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
Assert.assertNotNull(json);
|
||||
Assert.assertTrue(json.contains("\"serverIp\":\"127.0.0.1\""));
|
||||
Assert.assertTrue(json.contains("\"serverPort\":\"8888\""));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
Assert.assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\","
|
||||
+ "\"module\":\"internal\",\"connectionId\":\"11111_127.0.0.1_8888\"}";
|
||||
ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals("127.0.0.1", result.getServerIp());
|
||||
Assert.assertEquals("8888", result.getServerPort());
|
||||
Assert.assertEquals("11111_127.0.0.1_8888", result.getConnectionId());
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnectionSetupRequestTest extends BasicRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws Exception {
|
||||
ConnectionSetupRequest request = new ConnectionSetupRequest();
|
||||
request.setClientVersion("2.2.2");
|
||||
request.setAbilityTable(new HashMap<>());
|
||||
request.setTenant("testNamespaceId");
|
||||
request.setLabels(Collections.singletonMap("labelKey", "labelValue"));
|
||||
request.setRequestId("1");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
Assert.assertNotNull(json);
|
||||
Assert.assertTrue(json.contains("\"clientVersion\":\"2.2.2\""));
|
||||
Assert.assertTrue(json.contains("\"tenant\":\"testNamespaceId\""));
|
||||
Assert.assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}"));
|
||||
Assert.assertTrue(json.contains("\"abilityTable\":{"));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"clientVersion\":\"2.2.2\",\"abilities\":{\"remoteAbility\":"
|
||||
+ "{\"supportRemoteConnection\":false},\"configAbility\":{\"supportRemoteMetrics\":false},"
|
||||
+ "\"namingAbility\":{\"supportDeltaPush\":false,\"supportRemoteMetric\":false}},\"tenant\":\"testNamespaceId\","
|
||||
+ "\"labels\":{\"labelKey\":\"labelValue\"},\"module\":\"internal\"}";
|
||||
ConnectionSetupRequest result = mapper.readValue(json, ConnectionSetupRequest.class);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals("2.2.2", result.getClientVersion());
|
||||
Assert.assertEquals("testNamespaceId", result.getTenant());
|
||||
Assert.assertEquals(1, result.getLabels().size());
|
||||
Assert.assertEquals("labelValue", result.getLabels().get("labelKey"));
|
||||
Assert.assertEquals("1", result.getRequestId());
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EmptyContentRequestTest extends BasicRequestTest {
|
||||
|
||||
private static final String COMMON_JSON = "{\"headers\":{\"clientIp\":\"1.1.1.1\"},\"requestId\":\"1\",\"module\":\"internal\"}";
|
||||
|
||||
private static final String TO_STRING = "%s{headers={clientIp=1.1.1.1}, requestId='1'}";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientDetectionRequest()
|
||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||
doTest(ClientDetectionRequest.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealthCheckRequest()
|
||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||
doTest(HealthCheckRequest.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerCheckRequest()
|
||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||
doTest(ServerCheckRequest.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerLoaderInfoRequest()
|
||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||
doTest(ServerLoaderInfoRequest.class);
|
||||
}
|
||||
|
||||
private void doTest(Class<? extends Request> clazz)
|
||||
throws IllegalAccessException, InstantiationException, JsonProcessingException {
|
||||
Request request = clazz.newInstance();
|
||||
request.setRequestId("1");
|
||||
request.putHeader("clientIp", "1.1.1.1");
|
||||
String actual = mapper.writeValueAsString(request);
|
||||
assertCommonRequestJson(actual);
|
||||
request = mapper.readValue(COMMON_JSON, ServerLoaderInfoRequest.class);
|
||||
assertCommonRequest(request);
|
||||
}
|
||||
|
||||
private void assertCommonRequestJson(String actualJson) {
|
||||
assertTrue(actualJson.contains("\"requestId\":\"1\""));
|
||||
assertTrue(actualJson.contains("\"module\":\"internal\""));
|
||||
assertTrue(actualJson.contains("\"headers\":{\"clientIp\":\"1.1.1.1\"}"));
|
||||
}
|
||||
|
||||
private void assertCommonRequest(Request request) {
|
||||
assertEquals("1", request.getRequestId());
|
||||
assertEquals("internal", request.getModule());
|
||||
assertEquals(1, request.getHeaders().size());
|
||||
assertEquals("1.1.1.1", request.getHeader("clientIp"));
|
||||
assertEquals(String.format(TO_STRING, request.getClass().getSimpleName()), request.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PushAckRequestTest extends BasicRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws Exception {
|
||||
PushAckRequest request = PushAckRequest.build("1", false);
|
||||
request.setException(new NacosRuntimeException(500, "test"));
|
||||
String json = mapper.writeValueAsString(request);
|
||||
Assert.assertNotNull(json);
|
||||
Assert.assertTrue(json.contains("\"success\":false"));
|
||||
Assert.assertTrue(json.contains("\"exception\":{"));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"success\":false,"
|
||||
+ "\"exception\":{\"stackTrace\":[],\"errCode\":500,\"message\":\"errCode: 500, errMsg: test \","
|
||||
+ "\"localizedMessage\":\"errCode: 500, errMsg: test \",\"suppressed\":[]},\"module\":\"internal\"}";
|
||||
PushAckRequest result = mapper.readValue(json, PushAckRequest.class);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertFalse(result.isSuccess());
|
||||
Assert.assertEquals("1", result.getRequestId());
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class RequestMetaTest {
|
||||
|
||||
private RequestMeta requestMeta;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
requestMeta = new RequestMeta();
|
||||
requestMeta.setClientIp("127.0.0.1");
|
||||
requestMeta.setClientVersion("1.0.0");
|
||||
requestMeta.setConnectionId("test-connection-id");
|
||||
Map<String, String> labels = new HashMap<>();
|
||||
labels.put("env", "dev");
|
||||
requestMeta.setLabels(labels);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClientIp() {
|
||||
assertEquals("127.0.0.1", requestMeta.getClientIp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClientVersion() {
|
||||
assertEquals("1.0.0", requestMeta.getClientVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnectionId() {
|
||||
assertEquals("test-connection-id", requestMeta.getConnectionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLabels() {
|
||||
Map<String, String> labels = requestMeta.getLabels();
|
||||
assertNotNull(labels);
|
||||
assertEquals(1, labels.size());
|
||||
assertEquals("dev", labels.get("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
String expected = "RequestMeta{connectionId='test-connection-id', clientIp='127.0.0.1', clientVersion='1.0.0', labels={env=dev}}";
|
||||
assertEquals(expected, requestMeta.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnectionAbilityForNonExist() {
|
||||
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||
requestMeta.setAbilityTable(Collections.emptyMap());
|
||||
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnectionAbilityForExist() {
|
||||
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.FALSE));
|
||||
assertEquals(AbilityStatus.NOT_SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
||||
assertEquals(AbilityStatus.SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class RequestTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeader() {
|
||||
MockRequest request = new MockRequest();
|
||||
assertTrue(request.getHeaders().isEmpty());
|
||||
assertNull(request.getHeader("clientIp"));
|
||||
assertEquals("1.1.1.1", request.getHeader("clientIp", "1.1.1.1"));
|
||||
|
||||
request.putHeader("clientIp", "2.2.2.2");
|
||||
assertEquals(1, request.getHeaders().size());
|
||||
assertEquals("2.2.2.2", request.getHeader("clientIp"));
|
||||
assertEquals("2.2.2.2", request.getHeader("clientIp", "1.1.1.1"));
|
||||
|
||||
request.putAllHeader(Collections.singletonMap("connectionId", "aaa"));
|
||||
assertEquals(2, request.getHeaders().size());
|
||||
request.putAllHeader(null);
|
||||
assertEquals(2, request.getHeaders().size());
|
||||
|
||||
request.clearHeaders();
|
||||
assertTrue(request.getHeaders().isEmpty());
|
||||
}
|
||||
|
||||
private static class MockRequest extends Request {
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
return "mock";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ServerReloadRequestTest extends BasicRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws Exception {
|
||||
ServerReloadRequest request = new ServerReloadRequest();
|
||||
request.setReloadCount(10);
|
||||
request.setReloadServer("1.1.1.1");
|
||||
request.setRequestId("1");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
System.out.println(json);
|
||||
Assert.assertNotNull(json);
|
||||
Assert.assertTrue(json.contains("\"reloadCount\":10"));
|
||||
Assert.assertTrue(json.contains("\"reloadServer\":\"1.1.1.1\""));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"reloadCount\":10,\"reloadServer\":\"1.1.1.1\","
|
||||
+ "\"module\":\"internal\"}";
|
||||
ServerReloadRequest result = mapper.readValue(json, ServerReloadRequest.class);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(10, result.getReloadCount());
|
||||
Assert.assertEquals("1.1.1.1", result.getReloadServer());
|
||||
Assert.assertEquals("1", result.getRequestId());
|
||||
Assert.assertEquals("internal", result.getModule());
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class SetupAckRequestTest extends BasicRequestTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws Exception {
|
||||
SetupAckRequest request = new SetupAckRequest(
|
||||
Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
||||
request.setRequestId("1");
|
||||
String json = mapper.writeValueAsString(request);
|
||||
System.out.println(json);
|
||||
Assert.assertNotNull(json);
|
||||
Assert.assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}"));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String json =
|
||||
"{\"headers\":{},\"requestId\":\"1\",\"abilityTable\":{\"test_1\":true}," + "\"module\":\"internal\"}";
|
||||
SetupAckRequest result = mapper.readValue(json, SetupAckRequest.class);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertTrue(result.getAbilityTable().get("test_1"));
|
||||
Assert.assertEquals("1", result.getRequestId());
|
||||
Assert.assertEquals("internal", result.getModule());
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.remote.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EmptyContentResponseTest {
|
||||
|
||||
private static final String COMMON_JSON = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"1\",\"success\":true}";
|
||||
|
||||
private static final String TO_STRING = "Response{resultCode=200, errorCode=0, message='null', requestId='1'}";
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetErrorInfo() {
|
||||
Response response = new Response() {
|
||||
};
|
||||
response.setErrorInfo(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getDesc());
|
||||
assertEquals(ResponseCode.FAIL.getCode(), response.getErrorCode());
|
||||
assertEquals(ResponseCode.FAIL.getCode(), response.getResultCode());
|
||||
assertEquals(ResponseCode.FAIL.getDesc(), response.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientDetectionResponse() throws JsonProcessingException {
|
||||
ClientDetectionResponse response = new ClientDetectionResponse();
|
||||
response.setRequestId("1");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertCommonResponseJson(actual);
|
||||
response = mapper.readValue(COMMON_JSON, ClientDetectionResponse.class);
|
||||
assertCommonResponse(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectResetResponse() throws JsonProcessingException {
|
||||
ConnectResetResponse response = new ConnectResetResponse();
|
||||
response.setRequestId("1");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertCommonResponseJson(actual);
|
||||
response = mapper.readValue(COMMON_JSON, ConnectResetResponse.class);
|
||||
assertCommonResponse(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealthCheckResponse() throws JsonProcessingException {
|
||||
HealthCheckResponse response = new HealthCheckResponse();
|
||||
response.setRequestId("1");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertCommonResponseJson(actual);
|
||||
response = mapper.readValue(COMMON_JSON, HealthCheckResponse.class);
|
||||
assertCommonResponse(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerReloadResponse() throws JsonProcessingException {
|
||||
ServerReloadResponse response = new ServerReloadResponse();
|
||||
response.setRequestId("1");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertCommonResponseJson(actual);
|
||||
response = mapper.readValue(COMMON_JSON, ServerReloadResponse.class);
|
||||
assertCommonResponse(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupAckResponse() throws JsonProcessingException {
|
||||
SetupAckResponse response = new SetupAckResponse();
|
||||
response.setRequestId("1");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertCommonResponseJson(actual);
|
||||
response = mapper.readValue(COMMON_JSON, SetupAckResponse.class);
|
||||
assertCommonResponse(response);
|
||||
}
|
||||
|
||||
private void assertCommonResponse(Response response) {
|
||||
assertTrue(response.isSuccess());
|
||||
assertNull(response.getMessage());
|
||||
assertEquals(0, response.getErrorCode());
|
||||
assertEquals(ResponseCode.SUCCESS.code, response.getResultCode());
|
||||
assertEquals("1", response.getRequestId());
|
||||
assertEquals(TO_STRING, response.toString());
|
||||
}
|
||||
|
||||
private void assertCommonResponseJson(String actualJson) {
|
||||
assertTrue(actualJson.contains("\"requestId\":\"1\""));
|
||||
assertTrue(actualJson.contains("\"success\":true"));
|
||||
assertTrue(actualJson.contains("\"errorCode\":0"));
|
||||
assertTrue(actualJson.contains("\"resultCode\":200"));
|
||||
assertFalse(actualJson.contains("\"message\""));
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.remote.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerCheckResponseTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306", false);
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\""));
|
||||
assertTrue(actual.contains("\"supportAbilityNegotiation\":false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true,"
|
||||
+ "\"supportAbilityNegotiation\":true}";
|
||||
ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class);
|
||||
assertEquals("35643245_1.1.1.1_3306", response.getConnectionId());
|
||||
assertTrue(response.isSupportAbilityNegotiation());
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.remote.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerLoaderInfoResponseTest {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
ServerLoaderInfoResponse response = new ServerLoaderInfoResponse();
|
||||
response.putMetricsValue("test", "testValue");
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
System.out.println(actual);
|
||||
assertTrue(actual.contains("\"loaderMetrics\":{\"test\":\"testValue\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonProcessingException {
|
||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"loaderMetrics\":{\"test\":\"testValue\"},\"success\":true}";
|
||||
ServerLoaderInfoResponse response = mapper.readValue(json, ServerLoaderInfoResponse.class);
|
||||
assertEquals(1, response.getLoaderMetrics().size());
|
||||
assertEquals("testValue", response.getMetricsValue("test"));
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.selector;
|
||||
|
||||
import com.alibaba.nacos.api.cmdb.pojo.Entity;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.selector.context.CmdbContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.Naming.CMDB_CONTEXT_TYPE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AbstractCmdbSelectorTest {
|
||||
|
||||
private AtomicInteger counter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
counter = new AtomicInteger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetExpression() {
|
||||
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
||||
assertNull(cmdbSelector.getExpression());
|
||||
cmdbSelector.setExpression("test");
|
||||
assertEquals("test", cmdbSelector.getExpression());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws NacosException {
|
||||
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
||||
cmdbSelector.parse("test");
|
||||
assertEquals("test", cmdbSelector.getExpression());
|
||||
assertEquals(1, counter.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
CmdbContext<Instance> context = new CmdbContext<>();
|
||||
CmdbContext.CmdbInstance<Instance> provider = new CmdbContext.CmdbInstance<>();
|
||||
provider.setInstance(new Instance());
|
||||
provider.setEntity(new Entity());
|
||||
context.setProviders(Collections.singletonList(provider));
|
||||
CmdbContext.CmdbInstance<Instance> consumer = new CmdbContext.CmdbInstance<>();
|
||||
consumer.setInstance(new Instance());
|
||||
consumer.setEntity(new Entity());
|
||||
context.setConsumer(consumer);
|
||||
List<Instance> actual = new MockCmdbSelector().select(context);
|
||||
assertNull(actual.get(0).getIp());
|
||||
assertTrue(actual.get(0).getMetadata().isEmpty());
|
||||
assertEquals("true", provider.getInstance().getMetadata().get("afterSelect"));
|
||||
assertEquals("true", provider.getEntity().getLabels().get("afterSelect"));
|
||||
assertEquals("true", consumer.getInstance().getMetadata().get("afterSelect"));
|
||||
assertEquals("true", consumer.getEntity().getLabels().get("afterSelect"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContextType() {
|
||||
assertEquals(CMDB_CONTEXT_TYPE, new MockCmdbSelector().getContextType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
assertEquals("mock", new MockCmdbSelector().getType());
|
||||
}
|
||||
|
||||
private class MockCmdbSelector extends AbstractCmdbSelector<Instance> {
|
||||
|
||||
@Override
|
||||
protected void doParse(String expression) throws NacosException {
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Instance> doSelect(CmdbContext<Instance> context) {
|
||||
for (CmdbContext.CmdbInstance<Instance> each : context.getProviders()) {
|
||||
each.getInstance().getMetadata().put("afterSelect", "true");
|
||||
each.getEntity().setLabels(Collections.singletonMap("afterSelect", "true"));
|
||||
}
|
||||
context.getConsumer().getInstance().getMetadata().put("afterSelect", "true");
|
||||
context.getConsumer().getEntity().setLabels(Collections.singletonMap("afterSelect", "true"));
|
||||
return Collections.singletonList(new Instance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "mock";
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user