Merge remote-tracking branch 'upstream/develop' into asoc2022_issue#8460-2

# Conflicts:
#	persistence/src/test/java/com/alibaba/nacos/persistence/configuration/condition/ConfigChangeConfigsTest.java
This commit is contained in:
KomachiSion 2023-05-11 15:41:17 +08:00
commit 131dc643b3
672 changed files with 25714 additions and 6688 deletions

View File

@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Continuous Integration
name: "Continuous Integration"
on:
push:
@ -13,34 +13,37 @@ permissions:
contents: read # to fetch code (actions/checkout)
jobs:
unix:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
java: [8]
steps:
- name: Cache Maven Repos
- name: "Cache Maven Repos"
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
- name: "Checkout"
uses: actions/checkout@v3
- name: "Set up JDK ${{ matrix.java }}"
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
architecture: x64
- name: Check with Maven
run: mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
- name: Build with Maven
run: mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
- name: Test With Maven
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false
- name: Codecov
- name: "Print maven version"
run: mvn -version
- name: "Check with Maven"
run: mvn -B clean package apache-rat:check findbugs:findbugs -DskipTests -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Build with Maven"
run: mvn -Prelease-nacos -DskipTests clean install -U -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Test With Maven"
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Codecov"
uses: codecov/codecov-action@v3.1.0
with:
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./plugin-default-impl/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml

View File

@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Integration Test
name: "Integration Test"
on:
push:
@ -13,33 +13,36 @@ permissions:
contents: read # to fetch code (actions/checkout)
jobs:
unix:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
java: [8, 8.0.192, 11, 11.0.3]
steps:
- name: Cache Maven Repos
- name: "Cache Maven Repos"
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
- name: "Checkout"
uses: actions/checkout@v3
- name: "Set up JDK ${{ matrix.java }}"
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
architecture: x64
- name: Test Config
run: mvn clean package -Pcit-test
- name: Clean Env
run: mvn clean -Premove-test-data
- name: Test Naming
run: mvn clean package -Pnit-test
- name: Clean Env
run: mvn clean -Premove-test-data
- name: "Print maven version"
run: mvn -version
- name: "Test Config"
run: mvn clean package -Pcit-test -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Clean Env"
run: mvn clean -Premove-test-data -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Test Naming"
run: mvn clean package -Pnit-test -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Clean Env"
run: mvn clean -Premove-test-data -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn

View File

@ -5,6 +5,7 @@
[![Gitter](https://badges.gitter.im/alibaba/nacos.svg)](https://gitter.im/alibaba/nacos?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![Gitter](https://travis-ci.org/alibaba/nacos.svg?branch=master)](https://travis-ci.org/alibaba/nacos)
[![](https://img.shields.io/badge/Nacos-Check%20Your%20Contribution-orange)](https://opensource.alibaba.com/contribution_leaderboard/details?projectValue=nacos)
-------
@ -195,12 +196,11 @@ 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)

View File

@ -1,6 +1,6 @@
# How to report bugs
If any part of the Nacos project has bugs or documentation mistakes, please let us know by [opening an issue][Nacos-issue]. We treat bugs and mistakes very seriously and believe no issue is too small, anyOne is implement. Before creating a bug report, please check that an issue reporting the same problem does not already exist.
If any part of the Nacos project has bugs or documentation mistakes, please let us know by [opening an issue][Nacos-issue]. We treat bugs and mistakes very seriously and believe no issue is too small, anyone is implement. Before creating a bug report, please check that an issue reporting the same problem does not already exist.
To make the bug report accurate and easy to understand, please try to create bug reports that are:

View File

@ -27,13 +27,7 @@
<packaging>jar</packaging>
<name>nacos-address ${project.version}</name>
<url>http://nacos.io</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<url>https://nacos.io</url>
<dependencies>
<dependency>

View File

@ -28,7 +28,8 @@
<packaging>jar</packaging>
<name>nacos-api ${project.version}</name>
<url>http://nacos.io</url>
<url>https://nacos.io</url>
<description>Nacos api pom.xml file</description>
<build>
<plugins>
<!-- reuse when you need to update grpc model -->
@ -50,22 +51,9 @@
</execution>
</executions>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@ -105,11 +93,6 @@
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>protoc-gen-grpc-java</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>

View File

@ -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.

View File

@ -71,8 +71,4 @@ public class NacosApiException extends NacosException {
}
return Constants.NULL;
}
public void setErrAbstract(String errAbstract) {
this.errAbstract = errAbstract;
}
}

View File

@ -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;
}
}

View File

@ -75,7 +75,7 @@ public class Result<T> implements Serializable {
* @return Result
*/
public static Result<String> failure(String message) {
return Result.failure(ErrorCode.SERVER_ERROR, message);
return new Result<>(ErrorCode.SERVER_ERROR.getCode(), message);
}
/**

View File

@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Instance.
@ -209,7 +210,7 @@ public class Instance implements Serializable {
}
private static boolean strEquals(final String str1, final String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
return Objects.equals(str1, str2);
}
public long getInstanceHeartBeatInterval() {

View File

@ -24,7 +24,6 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -36,15 +35,22 @@ import java.util.List;
@JsonInclude(Include.NON_NULL)
public class ServiceInfo {
/**
* file name pattern: groupName@@name@clusters.
*/
private static final int GROUP_POSITION = 0;
private static final int SERVICE_POSITION = 1;
private static final int CLUSTER_POSITION = 2;
private static final int FILE_NAME_PARTS = 3;
@JsonIgnore
private String jsonFromServer = EMPTY;
private static final String EMPTY = "";
private static final String ALL_IPS = "000--00-ALL_IPS--00--000";
public static final String SPLITER = "@@";
private static final String DEFAULT_CHARSET = "UTF-8";
private String name;
@ -80,20 +86,15 @@ public class ServiceInfo {
* There is only one form of the key:groupName@@name@clusters. This constructor used by DiskCache.read(String) and
* FailoverReactor.FailoverFileReader,you should know that 'groupName' must not be null,and 'clusters' can be null.
*/
public ServiceInfo(String key) {
int maxIndex = 2;
int clusterIndex = 2;
int serviceNameIndex = 1;
int groupIndex = 0;
public ServiceInfo(final String key) {
String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
if (keys.length >= maxIndex + 1) {
this.groupName = keys[groupIndex];
this.name = keys[serviceNameIndex];
this.clusters = keys[clusterIndex];
} else if (keys.length == maxIndex) {
this.groupName = keys[groupIndex];
this.name = keys[serviceNameIndex];
if (keys.length >= FILE_NAME_PARTS) {
this.groupName = keys[GROUP_POSITION];
this.name = keys[SERVICE_POSITION];
this.clusters = keys[CLUSTER_POSITION];
} else if (keys.length == CLUSTER_POSITION) {
this.groupName = keys[GROUP_POSITION];
this.name = keys[SERVICE_POSITION];
} else {
//defensive programming
throw new IllegalArgumentException("Can't parse out 'groupName',but it must not be null!");
@ -231,8 +232,7 @@ public class ServiceInfo {
String serviceName = getGroupedServiceName();
try {
serviceName = URLEncoder.encode(serviceName, DEFAULT_CHARSET);
} catch (UnsupportedEncodingException e) {
//do nothing
} catch (UnsupportedEncodingException ignored) {
}
return getKey(serviceName, clusters);
}
@ -251,19 +251,8 @@ public class ServiceInfo {
* @param key key of service info
* @return new service info
*/
public static ServiceInfo fromKey(String key) {
ServiceInfo serviceInfo = new ServiceInfo();
int maxSegCount = 3;
String[] segs = key.split(Constants.SERVICE_INFO_SPLITER);
if (segs.length == maxSegCount - 1) {
serviceInfo.setGroupName(segs[0]);
serviceInfo.setName(segs[1]);
} else if (segs.length == maxSegCount) {
serviceInfo.setGroupName(segs[0]);
serviceInfo.setName(segs[1]);
serviceInfo.setClusters(segs[2]);
}
return serviceInfo;
public static ServiceInfo fromKey(final String key) {
return new ServiceInfo(key);
}
@Override
@ -283,18 +272,10 @@ public class ServiceInfo {
return str == null || str.length() == 0;
}
private static boolean isEmpty(Collection coll) {
return (coll == null || coll.isEmpty());
}
private static boolean strEquals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
public boolean isReachProtectionThreshold() {
return reachProtectionThreshold;
}
public void setReachProtectionThreshold(boolean reachProtectionThreshold) {
this.reachProtectionThreshold = reachProtectionThreshold;
}

View File

@ -21,10 +21,10 @@ import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
import com.alibaba.nacos.api.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Objects;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Implementation of health checker for HTTP.
@ -100,10 +100,6 @@ public class Http extends AbstractHealthChecker {
final Http other = (Http) obj;
if (!StringUtils.equals(type, other.getType())) {
return false;
}
if (!StringUtils.equals(path, other.getPath())) {
return false;
}

View File

@ -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;
}
}

View File

@ -34,6 +34,11 @@ public class ServerRemoteAbility implements Serializable {
*/
private boolean supportRemoteConnection;
/**
* if support grpc report.
*/
private boolean grpcReportEnabled = true;
public boolean isSupportRemoteConnection() {
return this.supportRemoteConnection;
}
@ -42,6 +47,14 @@ public class ServerRemoteAbility implements Serializable {
this.supportRemoteConnection = supportRemoteConnection;
}
public boolean isGrpcReportEnabled() {
return grpcReportEnabled;
}
public void setGrpcReportEnabled(boolean grpcReportEnabled) {
this.grpcReportEnabled = grpcReportEnabled;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -51,11 +64,11 @@ public class ServerRemoteAbility implements Serializable {
return false;
}
ServerRemoteAbility that = (ServerRemoteAbility) o;
return supportRemoteConnection == that.supportRemoteConnection;
return supportRemoteConnection == that.supportRemoteConnection && grpcReportEnabled == that.grpcReportEnabled;
}
@Override
public int hashCode() {
return Objects.hash(supportRemoteConnection);
return Objects.hash(supportRemoteConnection, grpcReportEnabled);
}
}

View File

@ -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;
}
}

View File

@ -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.
*/

View File

@ -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;

View File

@ -0,0 +1,59 @@
/*
* 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.ability;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ClientAbilitiesTest {
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
ClientAbilities abilities = new ClientAbilities();
String json = mapper.writeValueAsString(abilities);
assertTrue(json.contains("\"remoteAbility\":{"));
assertTrue(json.contains("\"configAbility\":{"));
assertTrue(json.contains("\"namingAbility\":{"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
+ "\"supportRemoteMetric\":false}}";
ClientAbilities abilities = mapper.readValue(json, ClientAbilities.class);
assertNotNull(abilities.getRemoteAbility());
assertNotNull(abilities.getNamingAbility());
assertNotNull(abilities.getConfigAbility());
}
}

View File

@ -0,0 +1,83 @@
/*
* 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.ability;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ServerAbilitiesTest {
private static ObjectMapper mapper;
private ServerAbilities serverAbilities;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Before
public void setUp() throws Exception {
serverAbilities = new ServerAbilities();
}
@Test
public void testSerialize() throws JsonProcessingException {
serverAbilities = new ServerAbilities();
String json = mapper.writeValueAsString(serverAbilities);
assertTrue(json.contains("\"remoteAbility\":{"));
assertTrue(json.contains("\"configAbility\":{"));
assertTrue(json.contains("\"namingAbility\":{"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
+ "\"supportRemoteMetric\":false}}";
ServerAbilities abilities = mapper.readValue(json, ServerAbilities.class);
assertNotNull(abilities.getRemoteAbility());
assertNotNull(abilities.getNamingAbility());
assertNotNull(abilities.getConfigAbility());
}
@Test
public void testEqualsAndHashCode() {
assertEquals(serverAbilities, serverAbilities);
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
assertNotEquals(serverAbilities, null);
assertNotEquals(serverAbilities, new ClientAbilities());
ServerAbilities test = new ServerAbilities();
assertEquals(serverAbilities, test);
assertEquals(serverAbilities.hashCode(), test.hashCode());
test.setRemoteAbility(null);
assertNotEquals(serverAbilities, test);
assertNotEquals(serverAbilities.hashCode(), test.hashCode());
}
}

View File

@ -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());
}
}

View File

@ -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"));
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -0,0 +1,55 @@
/*
* 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.ability;
import com.alibaba.nacos.api.remote.ability.ClientRemoteAbility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ClientRemoteAbilityTest {
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
ClientRemoteAbility abilities = new ClientRemoteAbility();
String json = mapper.writeValueAsString(abilities);
assertEquals("{\"supportRemoteConnection\":false}", json);
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"supportRemoteConnection\":true}";
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
assertTrue(abilities.isSupportRemoteConnection());
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,83 @@
/*
* 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.ability;
import com.alibaba.nacos.api.ability.ClientAbilities;
import com.alibaba.nacos.api.remote.ability.ServerRemoteAbility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class ServerRemoteAbilityTest {
private static ObjectMapper mapper;
private ServerRemoteAbility serverAbilities;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Before
public void setUp() throws Exception {
serverAbilities = new ServerRemoteAbility();
}
@Test
public void testSerialize() throws JsonProcessingException {
serverAbilities = new ServerRemoteAbility();
String json = mapper.writeValueAsString(serverAbilities);
assertEquals("{\"supportRemoteConnection\":false,\"grpcReportEnabled\":true}", json);
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
assertTrue(abilities.isSupportRemoteConnection());
assertTrue(abilities.isGrpcReportEnabled());
}
@Test
public void testEqualsAndHashCode() {
assertEquals(serverAbilities, serverAbilities);
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
assertNotEquals(serverAbilities, null);
assertNotEquals(serverAbilities, new ClientAbilities());
ServerRemoteAbility test = new ServerRemoteAbility();
assertEquals(serverAbilities, test);
assertEquals(serverAbilities.hashCode(), test.hashCode());
test.setSupportRemoteConnection(true);
assertNotEquals(serverAbilities, test);
assertNotEquals(serverAbilities.hashCode(), test.hashCode());
test.setSupportRemoteConnection(false);
test.setGrpcReportEnabled(false);
assertNotEquals(serverAbilities, test);
assertNotEquals(serverAbilities.hashCode(), test.hashCode());
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,77 @@
/*
* 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.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());
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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 {
}
}

View File

@ -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"));
}
}

View File

@ -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());
}
}

View File

@ -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"));
}
}

View File

@ -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 {
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.api.model.v2;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class ResultTest {
@Test
public void testSuccessEmptyResult() {
Result<String> result = Result.success();
assertNull(result.getData());
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
assertEquals(ErrorCode.SUCCESS.getMsg(), result.getMessage());
}
@Test
public void testSuccessWithData() {
Result<String> result = Result.success("test");
assertEquals("test", result.getData());
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
assertEquals(ErrorCode.SUCCESS.getMsg(), result.getMessage());
}
@Test
public void testFailureMessageResult() {
Result<String> result = Result.failure("test");
assertNull(result.getData());
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
assertEquals("test", result.getMessage());
}
@Test
public void testFailureWithoutData() {
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
assertNull(result.getData());
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getMsg(), result.getMessage());
}
@Test
public void testFailureWithData() {
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
assertEquals("error", result.getData());
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getMsg(), result.getMessage());
}
@Test
public void testToString() {
Result<String> result = Result.success("test");
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.naming.ability;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ClientNamingAbilityTest {
@Test
public void testGetAndSet() {
ClientNamingAbility ability = new ClientNamingAbility();
assertFalse(ability.isSupportDeltaPush());
assertFalse(ability.isSupportRemoteMetric());
ability.setSupportDeltaPush(true);
ability.setSupportRemoteMetric(true);
assertTrue(ability.isSupportDeltaPush());
assertTrue(ability.isSupportRemoteMetric());
}
}

View File

@ -26,6 +26,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class ServerNamingAbilityTest {
@ -57,4 +58,29 @@ public class ServerNamingAbilityTest {
actual.setSupportJraft(true);
assertEquals(expected, actual);
}
@Test
public void testEqualsForOneObject() {
ServerNamingAbility ability = new ServerNamingAbility();
assertTrue(ability.equals(ability));
}
@Test
public void testEqualsForOtherAbility() {
ServerNamingAbility ability = new ServerNamingAbility();
assertFalse(ability.equals(new ClientNamingAbility()));
}
@Test
public void testHashCode() throws JsonProcessingException {
ServerNamingAbility expected = new ServerNamingAbility();
expected.setSupportJraft(true);
String serializeJson = jacksonMapper.writeValueAsString(expected);
ServerNamingAbility actual = jacksonMapper.readValue(serializeJson, ServerNamingAbility.class);
assertEquals(expected, actual);
actual = new ServerNamingAbility();
assertNotEquals(expected, actual);
actual.setSupportJraft(true);
assertEquals(expected.hashCode(), actual.hashCode());
}
}

View File

@ -0,0 +1,77 @@
/*
* 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.naming.listener;
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 NamingEventTest {
private MockNamingEventListener eventListener;
@Before
public void setUp() throws Exception {
eventListener = new MockNamingEventListener();
}
@Test
public void testNamingEventWithSimpleConstructor() {
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
assertEquals("serviceName", event.getServiceName());
assertNull(event.getGroupName());
assertNull(event.getClusters());
assertTrue(event.getInstances().isEmpty());
eventListener.onEvent(event);
assertNull(event.getServiceName());
assertNull(event.getGroupName());
assertNull(event.getClusters());
assertNull(event.getInstances());
}
@Test
public void testNamingEventWithFullConstructor() {
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
assertEquals("serviceName", event.getServiceName());
assertEquals("group", event.getGroupName());
assertEquals("clusters", event.getClusters());
assertTrue(event.getInstances().isEmpty());
eventListener.onEvent(event);
assertNull(event.getServiceName());
assertNull(event.getGroupName());
assertNull(event.getClusters());
assertNull(event.getInstances());
}
private static class MockNamingEventListener extends AbstractEventListener {
@Override
public void onEvent(Event event) {
assertNull(getExecutor());
NamingEvent namingEvent = (NamingEvent) event;
namingEvent.setServiceName(null);
namingEvent.setGroupName(null);
namingEvent.setClusters(null);
namingEvent.setInstances(null);
}
}
}

View File

@ -0,0 +1,109 @@
/*
* 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.naming.pojo;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ClusterTest {
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSetAndGet() {
Cluster actual = new Cluster();
assertNull(actual.getName());
assertNull(actual.getServiceName());
assertEquals(Tcp.TYPE, actual.getHealthChecker().getType());
assertEquals(80, actual.getDefaultPort());
assertEquals(80, actual.getDefaultCheckPort());
assertTrue(actual.isUseIPPort4Check());
assertTrue(actual.getMetadata().isEmpty());
actual.setName("cluster");
actual.setServiceName("group@@service");
actual.setHealthChecker(new Http());
actual.setDefaultPort(81);
actual.setDefaultCheckPort(82);
actual.setUseIPPort4Check(false);
actual.setMetadata(Collections.singletonMap("a", "a"));
assertEquals("cluster", actual.getName());
assertEquals("group@@service", actual.getServiceName());
assertEquals(Http.TYPE, actual.getHealthChecker().getType());
assertEquals(81, actual.getDefaultPort());
assertEquals(82, actual.getDefaultCheckPort());
assertFalse(actual.isUseIPPort4Check());
assertFalse(actual.getMetadata().isEmpty());
assertTrue(actual.getMetadata().containsKey("a"));
assertEquals("a", actual.getMetadata().get("a"));
}
@Test
public void testJsonSerialize() throws JsonProcessingException {
Cluster actual = new Cluster("cluster");
actual.setServiceName("group@@service");
actual.setHealthChecker(new Http());
actual.setDefaultPort(81);
actual.setDefaultCheckPort(82);
actual.setUseIPPort4Check(false);
actual.setMetadata(Collections.singletonMap("a", "a"));
String json = mapper.writeValueAsString(actual);
assertTrue(json.contains("\"serviceName\":\"group@@service\""));
assertTrue(json.contains("\"name\":\"cluster\""));
assertTrue(json.contains("\"type\":\"HTTP\""));
assertTrue(json.contains("\"defaultPort\":81"));
assertTrue(json.contains("\"defaultCheckPort\":82"));
assertTrue(json.contains("\"useIPPort4Check\":false"));
assertTrue(json.contains("\"metadata\":{\"a\":\"a\"}"));
}
@Test
public void testJsonDeserialize() throws JsonProcessingException {
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
Cluster actual = mapper.readValue(json, Cluster.class);
assertEquals("cluster", actual.getName());
assertEquals("group@@service", actual.getServiceName());
assertEquals(Http.TYPE, actual.getHealthChecker().getType());
assertEquals(81, actual.getDefaultPort());
assertEquals(82, actual.getDefaultCheckPort());
assertFalse(actual.isUseIPPort4Check());
assertFalse(actual.getMetadata().isEmpty());
assertTrue(actual.getMetadata().containsKey("a"));
assertEquals("a", actual.getMetadata().get("a"));
}
}

View File

@ -16,15 +16,154 @@
package com.alibaba.nacos.api.naming.pojo;
import junit.framework.TestCase;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
public class InstanceTest extends TestCase {
import java.util.Collections;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class InstanceTest {
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSetAndGet() {
Instance instance = new Instance();
assertNull(instance.getInstanceId());
assertNull(instance.getIp());
assertEquals(0, instance.getPort());
assertEquals(1.0D, instance.getWeight(), 0.1);
assertTrue(instance.isHealthy());
assertTrue(instance.isEnabled());
assertTrue(instance.isEphemeral());
assertNull(instance.getClusterName());
assertNull(instance.getServiceName());
assertTrue(instance.getMetadata().isEmpty());
setInstance(instance);
checkInstance(instance);
}
@Test
public void testJsonSerialize() throws JsonProcessingException {
Instance instance = new Instance();
setInstance(instance);
String actual = mapper.writeValueAsString(instance);
assertTrue(actual.contains("\"instanceId\":\"id\""));
assertTrue(actual.contains("\"ip\":\"1.1.1.1\""));
assertTrue(actual.contains("\"port\":1000"));
assertTrue(actual.contains("\"weight\":100.0"));
assertTrue(actual.contains("\"healthy\":false"));
assertTrue(actual.contains("\"enabled\":false"));
assertTrue(actual.contains("\"ephemeral\":false"));
assertTrue(actual.contains("\"clusterName\":\"cluster\""));
assertTrue(actual.contains("\"serviceName\":\"group@@serviceName\""));
assertTrue(actual.contains("\"metadata\":{\"a\":\"b\"}"));
assertTrue(actual.contains("\"instanceHeartBeatInterval\":5000"));
assertTrue(actual.contains("\"instanceHeartBeatTimeOut\":15000"));
assertTrue(actual.contains("\"ipDeleteTimeout\":30000"));
}
@Test
public void testJsonDeserialize() throws JsonProcessingException {
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
+ "\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000}";
Instance instance = mapper.readValue(json, Instance.class);
checkInstance(instance);
}
@Test
public void testCheckClusterNameFormat() {
Instance instance = new Instance();
instance.setClusterName("demo");
assertEquals("demo", instance.getClusterName());
}
@Test
public void testToInetAddr() {
Instance instance = new Instance();
setInstance(instance);
assertEquals("1.1.1.1:1000", instance.toInetAddr());
}
@Test
public void testContainsMetadata() {
Instance instance = new Instance();
assertFalse(instance.containsMetadata("a"));
instance.setMetadata(null);
assertFalse(instance.containsMetadata("a"));
instance.addMetadata("a", "b");
assertTrue(instance.containsMetadata("a"));
}
@Test
public void testGetInstanceIdGenerator() {
Instance instance = new Instance();
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
assertEquals("test", instance.getInstanceIdGenerator());
}
@Test
public void testEquals() {
Instance actual = new Instance();
setInstance(actual);
actual.setMetadata(new HashMap<>());
actual.addMetadata("a", "b");
assertFalse(actual.equals(new Object()));
Instance expected = new Instance();
setInstance(expected);
expected.setMetadata(new HashMap<>());
expected.addMetadata("a", "b");
assertTrue(actual.equals(expected));
expected.addMetadata("a", "c");
assertFalse(actual.equals(expected));
}
private void setInstance(Instance instance) {
instance.setInstanceId("id");
instance.setIp("1.1.1.1");
instance.setPort(1000);
instance.setWeight(100);
instance.setHealthy(false);
instance.setEnabled(false);
instance.setEphemeral(false);
instance.setClusterName("cluster");
instance.setServiceName("group@@serviceName");
instance.setMetadata(Collections.singletonMap("a", "b"));
}
private void checkInstance(Instance instance) {
assertEquals("id", instance.getInstanceId());
assertEquals("1.1.1.1", instance.getIp());
assertEquals(1000, instance.getPort());
assertEquals(100D, instance.getWeight(), 0.1);
assertFalse(instance.isHealthy());
assertFalse(instance.isEnabled());
assertFalse(instance.isEphemeral());
assertEquals("cluster", instance.getClusterName());
assertEquals("group@@serviceName", instance.getServiceName());
assertFalse(instance.getMetadata().isEmpty());
assertTrue(instance.containsMetadata("a"));
assertEquals("b", instance.getMetadata().get("a"));
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.naming.pojo;
import org.junit.Test;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class ListViewTest {
@Test
public void testToString() {
List<String> data = new LinkedList<>();
data.add("1");
data.add("2");
data.add("3");
ListView<String> listView = new ListView<>();
listView.setData(data);
listView.setCount(data.size());
String actual = listView.toString();
assertEquals("ListView{data=[1, 2, 3], count=3}", actual);
}
@Test
public void testSetAndGet() {
ListView<String> listView = new ListView<>();
assertEquals(0, listView.getCount());
assertNull(listView.getData());
listView.setCount(1);
listView.setData(Collections.singletonList("1"));
assertEquals(1, listView.getCount());
assertEquals(1, listView.getData().size());
}
}

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.api.naming.pojo;
import com.alibaba.nacos.api.utils.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -25,6 +26,9 @@ import org.junit.Test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -65,11 +69,13 @@ public class ServiceInfoTest {
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
assertEquals("G@@testName", actual.getName());
assertEquals(0, actual.ipCount());
assertEquals("testClusters", actual.getClusters());
assertEquals("", actual.getChecksum());
assertEquals("", actual.getGroupName());
assertEquals(1000, actual.getCacheMillis());
assertEquals(0, actual.getLastRefTime());
assertTrue(actual.expired());
assertTrue(actual.getHosts().isEmpty());
assertTrue(actual.isValid());
assertFalse(actual.isAllIPs());
@ -79,6 +85,7 @@ public class ServiceInfoTest {
public void testGetKey() {
String key = serviceInfo.getKey();
assertEquals("G@@testName@@testClusters", key);
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
}
@Test
@ -102,4 +109,67 @@ public class ServiceInfoTest {
assertEquals(key1, s1.getKey());
assertEquals(key2, s2.getKey());
}
@Test(expected = IllegalArgumentException.class)
public void testServiceInfoConstructorWithError() {
String key1 = "name";
ServiceInfo s1 = new ServiceInfo(key1);
}
@Test
public void testValidateForAllIps() {
serviceInfo.setAllIPs(true);
assertTrue(serviceInfo.validate());
}
@Test
public void testValidateForNullHosts() {
serviceInfo.setHosts(null);
assertFalse(serviceInfo.validate());
}
@Test
public void testValidateForEmptyHosts() {
serviceInfo.setHosts(Collections.EMPTY_LIST);
assertFalse(serviceInfo.validate());
}
@Test
public void testValidateForUnhealthyHosts() {
Instance instance = new Instance();
instance.setHealthy(false);
serviceInfo.addHost(instance);
assertFalse(serviceInfo.validate());
}
@Test
public void testValidateForBothUnhealthyAndHealthyHosts() {
List<Instance> instanceList = new LinkedList<>();
Instance instance = new Instance();
instanceList.add(instance);
instance = new Instance();
instance.setHealthy(false);
instanceList.add(instance);
serviceInfo.addAllHosts(instanceList);
assertTrue(serviceInfo.validate());
}
@Test
public void testFromKey() {
String key1 = "group@@name";
String key2 = "group@@name@@c2";
ServiceInfo s1 = ServiceInfo.fromKey(key1);
ServiceInfo s2 = ServiceInfo.fromKey(key2);
assertEquals(key1, s1.getKey());
assertEquals(key2, s2.getKey());
}
@Test
public void testSetAndGet() throws JsonProcessingException {
serviceInfo.setReachProtectionThreshold(true);
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
assertEquals(StringUtils.EMPTY, actual.getJsonFromServer());
assertTrue(actual.isReachProtectionThreshold());
}
}

View File

@ -0,0 +1,62 @@
/*
* 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.naming.pojo;
import org.junit.Test;
import java.util.Collections;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ServiceTest {
@Test
public void testSetAndGet() {
Service service = new Service();
assertNull(service.getName());
assertNull(service.getAppName());
assertNull(service.getGroupName());
assertEquals(0.0f, service.getProtectThreshold(), 0.1);
assertTrue(service.getMetadata().isEmpty());
service.setName("service");
service.setGroupName("group");
service.setAppName("app");
service.setProtectThreshold(1.0f);
HashMap<String, String> metadata = new HashMap<>();
service.setMetadata(metadata);
service.addMetadata("a", "b");
assertEquals("service", service.getName());
assertEquals("app", service.getAppName());
assertEquals("group", service.getGroupName());
assertEquals(1.0f, service.getProtectThreshold(), 0.1);
assertEquals(1, service.getMetadata().size());
assertEquals("b", service.getMetadata().get("a"));
}
@Test
public void testToString() {
Service service = new Service("service");
service.setGroupName("group");
service.setAppName("app");
service.setProtectThreshold(1.0f);
service.setMetadata(Collections.singletonMap("a", "b"));
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", service.toString());
}
}

View File

@ -19,7 +19,11 @@ package com.alibaba.nacos.api.naming.pojo.builder;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@ -67,6 +71,24 @@ public class InstanceBuilderTest {
assertThat(actual.getMetadata().get(META_KEY), is(META_VALUE));
}
@Test
public void testBuildInstanceWithoutNewMetadata() {
InstanceBuilder builder = InstanceBuilder.newBuilder();
Map<String, String> metadata = new HashMap<>();
metadata.put("test", "test");
Instance actual = builder.setMetadata(metadata).build();
assertNull(actual.getServiceName());
assertNull(actual.getClusterName());
assertNull(actual.getInstanceId());
assertNull(actual.getIp());
assertThat(actual.getPort(), is(0));
assertThat(actual.getWeight(), is(1.0));
assertTrue(actual.isHealthy());
assertTrue(actual.isEnabled());
assertTrue(actual.isEphemeral());
assertEquals(1, actual.getMetadata().size());
}
@Test
public void testBuildEmptyInstance() {
InstanceBuilder builder = InstanceBuilder.newBuilder();

View File

@ -54,4 +54,10 @@ public class AbstractHealthCheckerTest {
assertEquals("", actual.getTestValue());
assertEquals(TestChecker.TYPE, actual.getType());
}
@Test
public void testClone() throws CloneNotSupportedException {
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
assertEquals(AbstractHealthChecker.None.class, none.getClass());
}
}

View File

@ -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.naming.pojo.healthcheck;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class HealthCheckTypeTest {
@Test
public void testOfHealthCheckerClassForBuildInType() {
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
assertEquals(AbstractHealthChecker.None.class, HealthCheckType.ofHealthCheckerClass("NONE"));
}
@Test
public void testOfHealthCheckerClassForExtendType() {
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
}
@Test
public void testOfHealthCheckerClassForNonExistType() {
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
}
@Test
public void testGetLoadedHealthCheckerClasses() {
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
assertEquals(5, actual.size());
}
}

View File

@ -16,18 +16,21 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck;
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
import com.alibaba.nacos.api.exception.runtime.NacosSerializationException;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class HealthCheckerFactoryTest {
@BeforeClass
public static void beforeClass() {
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
HealthCheckerFactory.registerSubType(new TestChecker());
}
@Test
@ -57,4 +60,74 @@ public class HealthCheckerFactoryTest {
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
assertEquals(TestChecker.class, actual.getClass());
}
@Test
public void testSerializeNoRegister() {
NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker();
assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register"));
}
@Test
public void testDeserializeNoRegister() {
String tcpString = "{\"type\":\"no register\",\"testValue\":null}";
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
assertEquals(AbstractHealthChecker.None.class, actual.getClass());
}
@Test(expected = NacosSerializationException.class)
public void testSerializeFailure() {
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
}
@Test(expected = NacosDeserializationException.class)
public void testDeserializeFailure() {
String errorString = "{\"type\"=\"TCP\"}";
System.out.println(HealthCheckerFactory.deserialize(errorString));
}
@Test
public void testCreateNoneHealthChecker() {
assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass());
}
private static class NoRegisterHealthChecker extends AbstractHealthChecker {
private static final long serialVersionUID = 9020783491111797559L;
private String testValue;
protected NoRegisterHealthChecker() {
super("no register");
}
public String getTestValue() {
return testValue;
}
public void setTestValue(String testValue) {
this.testValue = testValue;
}
@Override
public AbstractHealthChecker clone() throws CloneNotSupportedException {
return null;
}
}
private static class SelfDependHealthChecker extends AbstractHealthChecker {
private static final long serialVersionUID = 876677992848225965L;
public SelfDependHealthChecker self = this;
protected SelfDependHealthChecker() {
super("self depend");
}
@Override
public AbstractHealthChecker clone() throws CloneNotSupportedException {
return null;
}
}
}

View File

@ -76,4 +76,25 @@ public class HttpTest {
assertEquals("x:a|y:", actual.getHeaders());
assertEquals(Http.TYPE, actual.getType());
}
@Test
public void testClone() throws CloneNotSupportedException {
Http cloned = http.clone();
assertEquals(http.hashCode(), cloned.hashCode());
assertTrue(http.equals(cloned));
}
@Test
public void testNotEquals() throws CloneNotSupportedException {
assertFalse(http.equals(new Tcp()));
Http cloned = http.clone();
cloned.setPath("aaa");
assertFalse(http.equals(cloned));
cloned = http.clone();
cloned.setHeaders("aaa");
assertFalse(http.equals(cloned));
cloned = http.clone();
cloned.setExpectedResponseCode(500);
assertFalse(http.equals(cloned));
}
}

View File

@ -24,6 +24,7 @@ import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class MysqlTest {
@ -59,4 +60,25 @@ public class MysqlTest {
assertEquals("user", actual.getUser());
assertEquals(Mysql.TYPE, actual.getType());
}
@Test
public void testClone() throws CloneNotSupportedException {
Mysql cloned = mysql.clone();
assertEquals(mysql.hashCode(), cloned.hashCode());
assertTrue(mysql.equals(cloned));
}
@Test
public void testNotEquals() throws CloneNotSupportedException {
assertFalse(mysql.equals(new Tcp()));
Mysql cloned = mysql.clone();
cloned.setUser("aaa");
assertFalse(mysql.equals(cloned));
cloned = mysql.clone();
cloned.setPwd("aaa");
assertFalse(mysql.equals(cloned));
cloned = mysql.clone();
cloned.setCmd("aaa");
assertFalse(mysql.equals(cloned));
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.naming.pojo.healthcheck.impl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TcpTest {
@Test
public void testClone() throws CloneNotSupportedException {
Tcp original = new Tcp();
Tcp cloned = original.clone();
assertEquals(original.hashCode(), cloned.hashCode());
assertTrue(original.equals(cloned));
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.naming.remote.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public abstract class BasedNamingRequestTest {
protected static final String SERVICE = "service";
protected static final String GROUP = "group";
protected static final String NAMESPACE = "namespace";
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
protected void injectNamingRequestBasedInfo(AbstractNamingRequest request) {
request.setServiceName(SERVICE);
request.setGroupName(GROUP);
request.setNamespace(NAMESPACE);
}
protected void checkNamingRequestBasedInfo(AbstractNamingRequest request) {
assertEquals(SERVICE, request.getServiceName());
assertEquals(GROUP, request.getGroupName());
assertEquals(NAMESPACE, request.getNamespace());
assertEquals(NAMING_MODULE, request.getModule());
}
protected void checkSerializeBasedInfo(String json) {
assertTrue(json.contains("\"serviceName\":\"" + SERVICE + "\""));
assertTrue(json.contains("\"groupName\":\"" + GROUP + "\""));
assertTrue(json.contains("\"namespace\":\"" + NAMESPACE + "\""));
assertTrue(json.contains("\"module\":\"" + NAMING_MODULE + "\""));
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.naming.remote.request;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class BatchInstanceRequestTest extends BasedNamingRequestTest {
@Test
public void testSerialize() throws JsonProcessingException {
BatchInstanceRequest request = new BatchInstanceRequest(NAMESPACE, SERVICE, GROUP,
NamingRemoteConstants.BATCH_REGISTER_INSTANCE, Collections.singletonList(new Instance()));
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.BATCH_REGISTER_INSTANCE + "\""));
assertTrue(json.contains("\"instances\":[{"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"type\":\"batchRegisterInstance\",\"instances\":[{\"port\":0,\"weight\":1.0,\"healthy\":true,"
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
+ "\"instanceHeartBeatInterval\":5000,\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000}],"
+ "\"module\":\"naming\"}";
BatchInstanceRequest actual = mapper.readValue(json, BatchInstanceRequest.class);
checkNamingRequestBasedInfo(actual);
assertEquals(NamingRemoteConstants.BATCH_REGISTER_INSTANCE, actual.getType());
assertEquals(1, actual.getInstances().size());
assertEquals(new Instance(), actual.getInstances().get(0));
}
}

View File

@ -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.naming.remote.request;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class InstanceRequestTest extends BasedNamingRequestTest {
@Test
public void testSerialize() throws JsonProcessingException {
InstanceRequest request = new InstanceRequest(NAMESPACE, SERVICE, GROUP,
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
assertTrue(json.contains("\"instance\":{"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
+ "\"instanceHeartBeatInterval\":5000,\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000},"
+ "\"module\":\"naming\"}";
InstanceRequest actual = mapper.readValue(json, InstanceRequest.class);
checkNamingRequestBasedInfo(actual);
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, actual.getType());
assertEquals(new Instance(), actual.getInstance());
}
}

View File

@ -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.naming.remote.request;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class NotifySubscriberRequestTest {
private static final String SERVICE = "service";
private static final String GROUP = "group";
private static final String NAMESPACE = "namespace";
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE);
NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo);
request.setServiceName(SERVICE);
request.setGroupName(GROUP);
request.setNamespace(NAMESPACE);
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"serviceInfo\":{"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"serviceInfo\":{\"name\":\"service\",\"groupName\":\"group\",\"cacheMillis\":1000,\"hosts\":[],"
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
+ "\"valid\":true},\"module\":\"naming\"}";
NotifySubscriberRequest actual = mapper.readValue(json, NotifySubscriberRequest.class);
checkRequestBasedInfo(actual);
assertEquals(GROUP + "@@" + SERVICE, actual.getServiceInfo().getKey());
}
private void checkRequestBasedInfo(NotifySubscriberRequest request) {
assertEquals(SERVICE, request.getServiceName());
assertEquals(GROUP, request.getGroupName());
assertEquals(NAMESPACE, request.getNamespace());
assertEquals(NAMING_MODULE, request.getModule());
}
private void checkSerializeBasedInfo(String json) {
assertTrue(json.contains("\"serviceName\":\"" + SERVICE + "\""));
assertTrue(json.contains("\"groupName\":\"" + GROUP + "\""));
assertTrue(json.contains("\"namespace\":\"" + NAMESPACE + "\""));
assertTrue(json.contains("\"module\":\"" + NAMING_MODULE + "\""));
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.naming.remote.request;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ServiceListRequestTest extends BasedNamingRequestTest {
@Test
public void testSerialize() throws JsonProcessingException {
ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10);
request.setSelector("label");
String json = mapper.writeValueAsString(request);
assertTrue(json.contains("\"groupName\":\"" + GROUP + "\""));
assertTrue(json.contains("\"namespace\":\"" + NAMESPACE + "\""));
assertTrue(json.contains("\"module\":\"" + NAMING_MODULE + "\""));
assertTrue(json.contains("\"selector\":\"label\""));
assertTrue(json.contains("\"pageNo\":1"));
assertTrue(json.contains("\"pageSize\":10"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"\",\"groupName\":\"group\","
+ "\"pageNo\":1,\"pageSize\":10,\"selector\":\"label\",\"module\":\"naming\"}";
ServiceListRequest actual = mapper.readValue(json, ServiceListRequest.class);
assertEquals(GROUP, actual.getGroupName());
assertEquals(NAMESPACE, actual.getNamespace());
assertEquals(NAMING_MODULE, actual.getModule());
assertEquals(1, actual.getPageNo());
assertEquals(10, actual.getPageSize());
assertEquals("label", actual.getSelector());
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.naming.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 ServiceQueryRequestTest extends BasedNamingRequestTest {
@Test
public void testSerialize() throws JsonProcessingException {
ServiceQueryRequest request = new ServiceQueryRequest(NAMESPACE, SERVICE, GROUP);
request.setCluster(Constants.DEFAULT_CLUSTER_NAME);
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"cluster\":\"" + Constants.DEFAULT_CLUSTER_NAME + "\""));
assertTrue(json.contains("\"healthyOnly\":false"));
assertTrue(json.contains("\"udpPort\":0"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"cluster\":\"DEFAULT\",\"healthyOnly\":true,\"udpPort\":0,\"module\":\"naming\"}";
ServiceQueryRequest actual = mapper.readValue(json, ServiceQueryRequest.class);
checkNamingRequestBasedInfo(actual);
assertEquals(Constants.DEFAULT_CLUSTER_NAME, actual.getCluster());
assertTrue(actual.isHealthyOnly());
assertEquals(0, actual.getUdpPort());
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.naming.remote.request;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
@Test
public void testSerialize() throws JsonProcessingException {
SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true);
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"clusters\":\"\""));
assertTrue(json.contains("\"subscribe\":true"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"subscribe\":false,\"clusters\":\"aa,bb\",\"module\":\"naming\"}";
SubscribeServiceRequest actual = mapper.readValue(json, SubscribeServiceRequest.class);
checkNamingRequestBasedInfo(actual);
assertEquals("aa,bb", actual.getClusters());
assertFalse(actual.isSubscribe());
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.naming.remote.response;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class BatchInstanceResponseTest {
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"registerInstance\",\"success\":true}";
BatchInstanceResponse response = mapper.readValue(json, BatchInstanceResponse.class);
assertEquals(NamingRemoteConstants.REGISTER_INSTANCE, response.getType());
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.naming.remote.response;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class InstanceResponseTest {
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"deregisterInstance\",\"success\":true}";
InstanceResponse response = mapper.readValue(json, InstanceResponse.class);
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, response.getType());
}
}

View File

@ -0,0 +1,70 @@
/*
* 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.naming.remote.response;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class QueryServiceResponseTest {
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerializeSuccessResponse() throws JsonProcessingException {
QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo());
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"serviceInfo\":{"));
assertTrue(json.contains("\"resultCode\":200"));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains("\"success\":true"));
}
@Test
public void testSerializeFailResponse() throws JsonProcessingException {
QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test");
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"resultCode\":500"));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains("\"message\":\"test\""));
assertTrue(json.contains("\"success\":false"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
+ "\"valid\":true},\"success\":true}";
QueryServiceResponse response = mapper.readValue(json, QueryServiceResponse.class);
assertNotNull(response.getServiceInfo());
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.naming.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.BeforeClass;
import org.junit.Test;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ServiceListResponseTest {
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerializeSuccessResponse() throws JsonProcessingException {
ServiceListResponse response = ServiceListResponse.buildSuccessResponse(10, Collections.singletonList("a"));
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"count\":10"));
assertTrue(json.contains("\"serviceNames\":[\"a\"]"));
assertTrue(json.contains("\"resultCode\":200"));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains("\"success\":true"));
}
@Test
public void testSerializeFailResponse() throws JsonProcessingException {
ServiceListResponse response = ServiceListResponse.buildFailResponse("test");
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"resultCode\":500"));
assertTrue(json.contains("\"errorCode\":500"));
assertTrue(json.contains("\"message\":\"test\""));
assertTrue(json.contains("\"success\":false"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"count\":10,\"serviceNames\":[\"a\"],\"success\":true}";
ServiceListResponse response = mapper.readValue(json, ServiceListResponse.class);
assertEquals(10, response.getCount());
assertEquals(1, response.getServiceNames().size());
assertEquals("a", response.getServiceNames().get(0));
}
}

View File

@ -0,0 +1,70 @@
/*
* 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.naming.remote.response;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class SubscribeServiceResponseTest {
protected static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerializeSuccessResponse() throws JsonProcessingException {
SubscribeServiceResponse response = new SubscribeServiceResponse(200, null, new ServiceInfo());
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"serviceInfo\":{"));
assertTrue(json.contains("\"resultCode\":200"));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains("\"success\":true"));
}
@Test
public void testSerializeFailResponse() throws JsonProcessingException {
SubscribeServiceResponse response = new SubscribeServiceResponse(500, "test", null);
String json = mapper.writeValueAsString(response);
assertTrue(json.contains("\"resultCode\":500"));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains("\"message\":\"test\""));
assertTrue(json.contains("\"success\":false"));
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
+ "\"valid\":true},\"success\":true}";
SubscribeServiceResponse response = mapper.readValue(json, SubscribeServiceResponse.class);
assertNotNull(response.getServiceInfo());
}
}

View File

@ -16,6 +16,7 @@
package com.alibaba.nacos.api.naming.utils;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.api.naming.pojo.Instance;
@ -33,6 +34,79 @@ import static org.junit.Assert.assertTrue;
public class NamingUtilsTest {
@Test
public void testGetGroupedName() {
assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group"));
}
@Test(expected = IllegalArgumentException.class)
public void testGetGroupedNameWithoutGroup() {
NamingUtils.getGroupedName("serviceName", "");
}
@Test(expected = IllegalArgumentException.class)
public void testGetGroupedNameWithoutServiceName() {
NamingUtils.getGroupedName("", "group");
}
@Test
public void testGetServiceName() {
String validServiceName = "group@@serviceName";
assertEquals("serviceName", NamingUtils.getServiceName(validServiceName));
}
@Test
public void testGetServiceNameWithoutGroup() {
String serviceName = "serviceName";
assertEquals(serviceName, NamingUtils.getServiceName(serviceName));
}
@Test
public void testGetServiceNameWithEmpty() {
assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null));
}
@Test
public void testGetGroupName() {
String validServiceName = "group@@serviceName";
assertEquals("group", NamingUtils.getGroupName(validServiceName));
}
@Test
public void testGetGroupNameWithoutGroup() {
String serviceName = "serviceName";
assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName));
}
@Test
public void testGetGroupNameWithEmpty() {
assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null));
}
@Test
public void testCheckServiceNameFormat() {
String validServiceName = "group@@serviceName";
NamingUtils.checkServiceNameFormat(validServiceName);
}
@Test(expected = IllegalArgumentException.class)
public void testCheckServiceNameFormatWithoutGroupAndService() {
String validServiceName = "@@";
NamingUtils.checkServiceNameFormat(validServiceName);
}
@Test(expected = IllegalArgumentException.class)
public void testCheckServiceNameFormatWithoutGroup() {
String validServiceName = "@@service";
NamingUtils.checkServiceNameFormat(validServiceName);
}
@Test(expected = IllegalArgumentException.class)
public void testCheckServiceNameFormatWithoutService() {
String validServiceName = "group@@";
NamingUtils.checkServiceNameFormat(validServiceName);
}
@Test
public void testGetGroupedNameOptional() {
String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA");

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.remote.ability;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ClientRemoteAbilityTest {
private static ObjectMapper mapper;
@BeforeClass
public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Test
public void testSerialize() throws JsonProcessingException {
ClientRemoteAbility abilities = new ClientRemoteAbility();
String json = mapper.writeValueAsString(abilities);
assertEquals("{\"supportRemoteConnection\":false}", json);
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"supportRemoteConnection\":true}";
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
assertTrue(abilities.isSupportRemoteConnection());
}
}

View File

@ -0,0 +1,82 @@
/*
* 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.remote.ability;
import com.alibaba.nacos.api.ability.ClientAbilities;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class ServerRemoteAbilityTest {
private static ObjectMapper mapper;
private ServerRemoteAbility serverAbilities;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
@Before
public void setUp() throws Exception {
serverAbilities = new ServerRemoteAbility();
}
@Test
public void testSerialize() throws JsonProcessingException {
serverAbilities = new ServerRemoteAbility();
String json = mapper.writeValueAsString(serverAbilities);
assertEquals("{\"supportRemoteConnection\":false,\"grpcReportEnabled\":true}", json);
}
@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
assertTrue(abilities.isSupportRemoteConnection());
assertTrue(abilities.isGrpcReportEnabled());
}
@Test
public void testEqualsAndHashCode() {
assertEquals(serverAbilities, serverAbilities);
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
assertNotEquals(serverAbilities, null);
assertNotEquals(serverAbilities, new ClientAbilities());
ServerRemoteAbility test = new ServerRemoteAbility();
assertEquals(serverAbilities, test);
assertEquals(serverAbilities.hashCode(), test.hashCode());
test.setSupportRemoteConnection(true);
assertNotEquals(serverAbilities, test);
assertNotEquals(serverAbilities.hashCode(), test.hashCode());
test.setSupportRemoteConnection(false);
test.setGrpcReportEnabled(false);
assertNotEquals(serverAbilities, test);
assertNotEquals(serverAbilities.hashCode(), test.hashCode());
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,46 @@
/*
* 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");
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\""));
}
@Test
public void testDeserialize() throws Exception {
String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\",\"module\":\"internal\"}";
ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class);
Assert.assertNotNull(result);
Assert.assertEquals("127.0.0.1", result.getServerIp());
Assert.assertEquals("8888", result.getServerPort());
}
}

View File

@ -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 com.alibaba.nacos.api.ability.ClientAbilities;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
public class ConnectionSetupRequestTest extends BasicRequestTest {
@Test
public void testSerialize() throws Exception {
ConnectionSetupRequest request = new ConnectionSetupRequest();
request.setClientVersion("2.2.2");
request.setAbilities(new ClientAbilities());
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("\"abilities\":{"));
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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.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());
}
}

View File

@ -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";
}
}
}

View File

@ -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());
}
}

View File

@ -0,0 +1,111 @@
/*
* 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);
}
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\""));
}
}

View File

@ -0,0 +1,52 @@
/*
* 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");
String actual = mapper.writeValueAsString(response);
assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\""));
}
@Test
public void testDeserialization() throws JsonProcessingException {
String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true}";
ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class);
assertEquals("35643245_1.1.1.1_3306", response.getConnectionId());
}
}

View File

@ -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"));
}
}

View File

@ -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