Upgrade junt to junit5 (#3149)
* upgrade junit to junit5 * modify test * 批量修改upgrade_junt_to_junit5 * 删除多余的文件 * fi test case * Disabled soem test case temporarily * upgrade junit to junit5 and batch modify test case * copy some code from jupiter5.4.0.M1 for some issues * 修改rat福泽 * update rat path * revert case * add junit-platform-surefire-provider to maven-surefire-plugin * update dependency * fix coverage issue (#1) * use jupiter 5.4.0-M1 and remove junit5 source code
This commit is contained in:
parent
460c3a1756
commit
5298afdf40
|
|
@ -398,11 +398,16 @@
|
|||
|
||||
<!-- Temporarily add this part to exclude transitive dependency -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit_version}</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit_jupiter_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit_jupiter_version}</version>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ import org.apache.dubbo.rpc.RpcInvocation;
|
|||
import org.apache.dubbo.rpc.RpcResult;
|
||||
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -56,7 +56,7 @@ public class StickyTest {
|
|||
);
|
||||
private int runs = 1;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
dic = mock(Directory.class);
|
||||
invocation = new RpcInvocation();
|
||||
|
|
@ -77,26 +77,26 @@ public class StickyTest {
|
|||
public void testStickyNoCheck() {
|
||||
int count = testSticky(null, false);
|
||||
System.out.println(count);
|
||||
Assert.assertTrue(count > 0 && count <= runs);
|
||||
Assertions.assertTrue(count > 0 && count <= runs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStickyForceCheck() {
|
||||
int count = testSticky(null, true);
|
||||
Assert.assertTrue(count == 0 || count == runs);
|
||||
Assertions.assertTrue(count == 0 || count == runs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodStickyNoCheck() {
|
||||
int count = testSticky("method1", false);
|
||||
System.out.println(count);
|
||||
Assert.assertTrue(count > 0 && count <= runs);
|
||||
Assertions.assertTrue(count > 0 && count <= runs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodStickyForceCheck() {
|
||||
int count = testSticky("method1", true);
|
||||
Assert.assertTrue(count == 0 || count == runs);
|
||||
Assertions.assertTrue(count == 0 || count == runs);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -104,7 +104,7 @@ public class StickyTest {
|
|||
for (int i = 0; i < 100; i++) {//Two different methods should always use the same invoker every time.
|
||||
int count1 = testSticky("method1", true);
|
||||
int count2 = testSticky("method2", true);
|
||||
Assert.assertTrue(count1 == count2);
|
||||
Assertions.assertTrue(count1 == count2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ public class StickyTest {
|
|||
|
||||
int count = 0;
|
||||
for (int i = 0; i < runs; i++) {
|
||||
Assert.assertEquals(null, clusterinvoker.invoke(invocation));
|
||||
Assertions.assertEquals(null, clusterinvoker.invoke(invocation));
|
||||
if (invoker1 == clusterinvoker.getSelectedInvoker()) {
|
||||
count++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import org.apache.dubbo.common.URL;
|
|||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.rpc.cluster.configurator.consts.UrlConstant;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* OverrideConfiguratorTest
|
||||
|
|
@ -34,16 +34,16 @@ public class AbsentConfiguratorTest {
|
|||
AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://foo@0.0.0.0/com.foo.BarService?timeout=200"));
|
||||
|
||||
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_11));
|
||||
Assert.assertNull(url.getParameter("timeout"));
|
||||
Assertions.assertNull(url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_11));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -51,18 +51,18 @@ public class AbsentConfiguratorTest {
|
|||
AbsentConfigurator configurator = new AbsentConfigurator(URL.valueOf("override://" + NetUtils.getLocalHost() + "/com.foo.BarService?timeout=200"));
|
||||
|
||||
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
|
||||
AbsentConfigurator configurator1 = new AbsentConfigurator(URL.valueOf(UrlConstant.SERVICE_TIMEOUT_200));
|
||||
|
||||
url = configurator1.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_10));
|
||||
Assert.assertNull(url.getParameter("timeout"));
|
||||
Assertions.assertNull(url.getParameter("timeout"));
|
||||
|
||||
url = configurator1.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_10));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import org.apache.dubbo.common.utils.NetUtils;
|
|||
import org.apache.dubbo.rpc.cluster.configurator.absent.AbsentConfigurator;
|
||||
import org.apache.dubbo.rpc.cluster.configurator.consts.UrlConstant;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* OverrideConfiguratorTest
|
||||
|
|
@ -34,16 +34,16 @@ public class OverrideConfiguratorTest {
|
|||
OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://foo@0.0.0.0/com.foo.BarService?timeout=200"));
|
||||
|
||||
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_11));
|
||||
Assert.assertNull(url.getParameter("timeout"));
|
||||
Assertions.assertNull(url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_11));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -51,18 +51,18 @@ public class OverrideConfiguratorTest {
|
|||
OverrideConfigurator configurator = new OverrideConfigurator(URL.valueOf("override://" + NetUtils.getLocalHost() + "/com.foo.BarService?timeout=200"));
|
||||
|
||||
URL url = configurator.configure(URL.valueOf(UrlConstant.URL_CONSUMER));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
url = configurator.configure(URL.valueOf(UrlConstant.URL_ONE));
|
||||
Assert.assertEquals("200", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("200", url.getParameter("timeout"));
|
||||
|
||||
AbsentConfigurator configurator1 = new AbsentConfigurator(URL.valueOf("override://10.20.153.10/com.foo.BarService?timeout=200"));
|
||||
|
||||
url = configurator1.configure(URL.valueOf(UrlConstant.APPLICATION_BAR_SIDE_CONSUMER_10));
|
||||
Assert.assertNull(url.getParameter("timeout"));
|
||||
Assertions.assertNull(url.getParameter("timeout"));
|
||||
|
||||
url = configurator1.configure(URL.valueOf(UrlConstant.TIMEOUT_1000_SIDE_CONSUMER_10));
|
||||
Assert.assertEquals("1000", url.getParameter("timeout"));
|
||||
Assertions.assertEquals("1000", url.getParameter("timeout"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import org.apache.dubbo.common.URL;
|
|||
import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfigItem;
|
||||
import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfiguratorConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
|
@ -44,7 +44,7 @@ public class ConfigParserTest {
|
|||
|
||||
@Test
|
||||
public void snakeYamlBasicTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
|
||||
|
||||
Constructor constructor = new Constructor(ConfiguratorConfig.class);
|
||||
TypeDescription carDescription = new TypeDescription(ConfiguratorConfig.class);
|
||||
|
|
@ -59,109 +59,111 @@ public class ConfigParserTest {
|
|||
|
||||
@Test
|
||||
public void parseConfiguratorsServiceNoAppTest() throws Exception {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(2, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(2, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals(url.getAddress(), "127.0.0.1:20880");
|
||||
Assert.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222);
|
||||
Assertions.assertEquals(url.getAddress(), "127.0.0.1:20880");
|
||||
Assertions.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsServiceGroupVersionTest() throws Exception {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(1, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(1, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
|
||||
Assert.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY));
|
||||
Assertions.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
|
||||
Assertions.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsServiceMultiAppsTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(4, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(4, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assert.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void parseConfiguratorsServiceNoRuleTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) {
|
||||
ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.fail();
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsServiceNoRuleTest() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) {
|
||||
ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assertions.fail();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsAppMultiServicesTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml")) {
|
||||
String yamlFile = streamToString(yamlStream);
|
||||
List<URL> urls = ConfigParser.parseConfigurators(yamlFile);
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(4, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(4, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assert.assertEquals("service1", url.getServiceInterface());
|
||||
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("service1", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsAppAnyServicesTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(2, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(2, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assert.assertEquals("*", url.getServiceInterface());
|
||||
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConfiguratorsAppNoServiceTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(1, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(1, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assert.assertEquals("*", url.getServiceInterface());
|
||||
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseConsumerSpecificProvidersTest() throws IOException {
|
||||
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml")) {
|
||||
try (InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml")) {
|
||||
List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
|
||||
Assert.assertNotNull(urls);
|
||||
Assert.assertEquals(1, urls.size());
|
||||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(1, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assert.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assert.assertEquals("*", url.getServiceInterface());
|
||||
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assert.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY));
|
||||
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import org.apache.dubbo.rpc.cluster.Router;
|
|||
import org.apache.dubbo.rpc.cluster.router.MockInvoker;
|
||||
import org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -56,10 +56,10 @@ public class StaticDirectoryTest {
|
|||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
|
||||
boolean isAvailable = staticDirectory.isAvailable();
|
||||
Assert.assertTrue(!isAvailable);
|
||||
Assertions.assertTrue(!isAvailable);
|
||||
List<Invoker<String>> newInvokers = staticDirectory.list(new MockDirInvocation());
|
||||
Assert.assertTrue(newInvokers.size() > 0);
|
||||
Assertions.assertTrue(newInvokers.size() > 0);
|
||||
staticDirectory.destroy();
|
||||
Assert.assertEquals(0, newInvokers.size());
|
||||
Assertions.assertEquals(0, newInvokers.size());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ package org.apache.dubbo.rpc.cluster.loadbalance;
|
|||
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -28,27 +28,27 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public class ConsistentHashLoadBalanceTest extends LoadBalanceBaseTest {
|
||||
|
||||
@Test
|
||||
public void testConsistentHashLoadBalance() {
|
||||
int runs = 10000;
|
||||
long unHitedInvokerCount = 0;
|
||||
Map<Invoker, Long> hitedInvokers = new HashMap<>();
|
||||
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, ConsistentHashLoadBalance.NAME);
|
||||
for (Invoker minvoker : counter.keySet()) {
|
||||
Long count = counter.get(minvoker).get();
|
||||
@Test
|
||||
public void testConsistentHashLoadBalance() {
|
||||
int runs = 10000;
|
||||
long unHitedInvokerCount = 0;
|
||||
Map<Invoker, Long> hitedInvokers = new HashMap<>();
|
||||
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, ConsistentHashLoadBalance.NAME);
|
||||
for (Invoker minvoker : counter.keySet()) {
|
||||
Long count = counter.get(minvoker).get();
|
||||
|
||||
if (count == 0) {
|
||||
unHitedInvokerCount++;
|
||||
} else {
|
||||
hitedInvokers.put(minvoker, count);
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
unHitedInvokerCount++;
|
||||
} else {
|
||||
hitedInvokers.put(minvoker, count);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertEquals("the number of unHitedInvoker should be counter.size() - 1", counter.size() - 1,
|
||||
unHitedInvokerCount);
|
||||
Assert.assertEquals("the number of hitedInvoker should be 1", 1, hitedInvokers.size());
|
||||
Assert.assertEquals("the number of hited count should be the number of runs", runs,
|
||||
hitedInvokers.values().iterator().next().intValue());
|
||||
}
|
||||
Assertions.assertEquals(counter.size() - 1,
|
||||
unHitedInvokerCount, "the number of unHitedInvoker should be counter.size() - 1");
|
||||
Assertions.assertEquals(1, hitedInvokers.size(), "the number of hitedInvoker should be 1");
|
||||
Assertions.assertEquals(runs,
|
||||
hitedInvokers.values().iterator().next().intValue(), "the number of hited count should be the number of runs");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@
|
|||
package org.apache.dubbo.rpc.cluster.loadbalance;
|
||||
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class LeastActiveBalanceTest extends LoadBalanceBaseTest {
|
||||
@Ignore
|
||||
@Disabled
|
||||
@Test
|
||||
public void testLeastActiveLoadBalance_select() {
|
||||
int runs = 10000;
|
||||
|
|
@ -33,8 +34,8 @@ public class LeastActiveBalanceTest extends LoadBalanceBaseTest {
|
|||
for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
|
||||
Long count = entry.getValue().get();
|
||||
// System.out.println(count);
|
||||
Assert.assertTrue("abs diff shoud < avg",
|
||||
Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()));
|
||||
Assertions.assertTrue(
|
||||
Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()), "abs diff shoud < avg");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,13 +57,13 @@ public class LeastActiveBalanceTest extends LoadBalanceBaseTest {
|
|||
sumInvoker2++;
|
||||
}
|
||||
// never select invoker3 because it's active is more than invoker1 and invoker2
|
||||
Assert.assertTrue("select is not the least active one", !selected.getUrl().getProtocol().equals("test3"));
|
||||
Assertions.assertTrue(!selected.getUrl().getProtocol().equals("test3"), "select is not the least active one");
|
||||
}
|
||||
|
||||
// the sumInvoker1 : sumInvoker2 approximately equal to 1: 9
|
||||
System.out.println(sumInvoker1);
|
||||
System.out.println(sumInvoker2);
|
||||
|
||||
Assert.assertEquals("select failed!", sumInvoker1 + sumInvoker2, loop);
|
||||
Assertions.assertEquals(sumInvoker1 + sumInvoker2, loop, "select failed!");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ import org.apache.dubbo.rpc.Invoker;
|
|||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.RpcStatus;
|
||||
import org.apache.dubbo.rpc.cluster.LoadBalance;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.mockito.Mockito;
|
||||
|
|
@ -63,14 +63,14 @@ public class LoadBalanceBaseTest {
|
|||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
invocation = mock(Invocation.class);
|
||||
|
|
@ -136,20 +136,20 @@ public class LoadBalanceBaseTest {
|
|||
|
||||
@Test
|
||||
public void testLoadBalanceWarmup() {
|
||||
Assert.assertEquals(1, calculateDefaultWarmupWeight(0));
|
||||
Assert.assertEquals(1, calculateDefaultWarmupWeight(13));
|
||||
Assert.assertEquals(1, calculateDefaultWarmupWeight(6 * 1000));
|
||||
Assert.assertEquals(2, calculateDefaultWarmupWeight(12 * 1000));
|
||||
Assert.assertEquals(10, calculateDefaultWarmupWeight(60 * 1000));
|
||||
Assert.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000));
|
||||
Assert.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000 + 23));
|
||||
Assert.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000 + 5999));
|
||||
Assert.assertEquals(51, calculateDefaultWarmupWeight(5 * 60 * 1000 + 6000));
|
||||
Assert.assertEquals(90, calculateDefaultWarmupWeight(9 * 60 * 1000));
|
||||
Assert.assertEquals(98, calculateDefaultWarmupWeight(10 * 60 * 1000 - 12 * 1000));
|
||||
Assert.assertEquals(99, calculateDefaultWarmupWeight(10 * 60 * 1000 - 6 * 1000));
|
||||
Assert.assertEquals(100, calculateDefaultWarmupWeight(10 * 60 * 1000));
|
||||
Assert.assertEquals(100, calculateDefaultWarmupWeight(20 * 60 * 1000));
|
||||
Assertions.assertEquals(1, calculateDefaultWarmupWeight(0));
|
||||
Assertions.assertEquals(1, calculateDefaultWarmupWeight(13));
|
||||
Assertions.assertEquals(1, calculateDefaultWarmupWeight(6 * 1000));
|
||||
Assertions.assertEquals(2, calculateDefaultWarmupWeight(12 * 1000));
|
||||
Assertions.assertEquals(10, calculateDefaultWarmupWeight(60 * 1000));
|
||||
Assertions.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000));
|
||||
Assertions.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000 + 23));
|
||||
Assertions.assertEquals(50, calculateDefaultWarmupWeight(5 * 60 * 1000 + 5999));
|
||||
Assertions.assertEquals(51, calculateDefaultWarmupWeight(5 * 60 * 1000 + 6000));
|
||||
Assertions.assertEquals(90, calculateDefaultWarmupWeight(9 * 60 * 1000));
|
||||
Assertions.assertEquals(98, calculateDefaultWarmupWeight(10 * 60 * 1000 - 12 * 1000));
|
||||
Assertions.assertEquals(99, calculateDefaultWarmupWeight(10 * 60 * 1000 - 6 * 1000));
|
||||
Assertions.assertEquals(100, calculateDefaultWarmupWeight(10 * 60 * 1000));
|
||||
Assertions.assertEquals(100, calculateDefaultWarmupWeight(20 * 60 * 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,7 +209,7 @@ public class LoadBalanceBaseTest {
|
|||
protected Invoker<LoadBalanceBaseTest> weightInvoker3;
|
||||
protected Invoker<LoadBalanceBaseTest> weightInvokerTmp;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() throws Exception {
|
||||
weightInvoker1 = mock(Invoker.class, Mockito.withSettings().stubOnly());
|
||||
weightInvoker2 = mock(Invoker.class, Mockito.withSettings().stubOnly());
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ package org.apache.dubbo.rpc.cluster.loadbalance;
|
|||
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.RpcStatus;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
|
@ -34,7 +35,7 @@ public class RandomLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, RandomLoadBalance.NAME);
|
||||
for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
|
||||
Long count = entry.getValue().get();
|
||||
Assert.assertTrue("abs diff should < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()));
|
||||
Assertions.assertTrue(Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size()), "abs diff should < avg");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
|
@ -46,11 +47,11 @@ public class RandomLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
|
||||
Long count = entry.getValue().get();
|
||||
}
|
||||
Assert.assertEquals(runs, counter.get(invoker1).intValue());
|
||||
Assert.assertEquals(0, counter.get(invoker2).intValue());
|
||||
Assert.assertEquals(0, counter.get(invoker3).intValue());
|
||||
Assert.assertEquals(0, counter.get(invoker4).intValue());
|
||||
Assert.assertEquals(0, counter.get(invoker5).intValue());
|
||||
Assertions.assertEquals(runs, counter.get(invoker1).intValue());
|
||||
Assertions.assertEquals(0, counter.get(invoker2).intValue());
|
||||
Assertions.assertEquals(0, counter.get(invoker3).intValue());
|
||||
Assertions.assertEquals(0, counter.get(invoker4).intValue());
|
||||
Assertions.assertEquals(0, counter.get(invoker5).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -81,7 +82,7 @@ public class RandomLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
System.out.println(sumInvoker1);
|
||||
System.out.println(sumInvoker2);
|
||||
System.out.println(sumInvoker3);
|
||||
Assert.assertEquals("select failed!", sumInvoker1 + sumInvoker2 + sumInvoker3, loop);
|
||||
Assertions.assertEquals(sumInvoker1 + sumInvoker2 + sumInvoker3, loop, "select failed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
package org.apache.dubbo.rpc.cluster.loadbalance;
|
||||
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -30,7 +31,7 @@ import java.util.Map.Entry;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Ignore
|
||||
@Disabled
|
||||
public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
||||
|
||||
private void assertStrictWRRResult(int loop, Map<Invoker, InvokeResult> resultMap) {
|
||||
|
|
@ -38,11 +39,11 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
for (InvokeResult invokeResult : resultMap.values()) {
|
||||
int count = (int) invokeResult.getCount().get();
|
||||
// Because it's a strictly round robin, so the abs delta should be < 10 too
|
||||
Assert.assertTrue("delta with expected count should < 10",
|
||||
Math.abs(invokeResult.getExpected(loop) - count) < 10);
|
||||
Assertions.assertTrue(
|
||||
Math.abs(invokeResult.getExpected(loop) - count) < 10, "delta with expected count should < 10");
|
||||
invokeCount += count;
|
||||
}
|
||||
Assert.assertEquals("select failed!", invokeCount, loop);
|
||||
Assertions.assertEquals(invokeCount, loop, "select failed!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -51,7 +52,7 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
Map<Invoker, AtomicLong> counter = getInvokeCounter(runs, RoundRobinLoadBalance.NAME);
|
||||
for (Map.Entry<Invoker, AtomicLong> entry : counter.entrySet()) {
|
||||
Long count = entry.getValue().get();
|
||||
Assert.assertTrue("abs diff should < 1", Math.abs(count - runs / (0f + invokers.size())) < 1f);
|
||||
Assertions.assertTrue(Math.abs(count - runs / (0f + invokers.size())) < 1f, "abs diff should < 1");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
final int runs = 10000;
|
||||
List<Thread> threads = new ArrayList<Thread>();
|
||||
int threadNum = 10;
|
||||
for (int i = 0; i < threadNum; i ++) {
|
||||
for (int i = 0; i < threadNum; i++) {
|
||||
threads.add(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -109,15 +110,15 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
assertStrictWRRResult(loop, resultMap);
|
||||
|
||||
// inner nodes cache judgement
|
||||
RoundRobinLoadBalance lb = (RoundRobinLoadBalance)getLoadBalance(RoundRobinLoadBalance.NAME);
|
||||
Assert.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
RoundRobinLoadBalance lb = (RoundRobinLoadBalance) getLoadBalance(RoundRobinLoadBalance.NAME);
|
||||
Assertions.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
|
||||
weightInvokers.remove(weightInvokerTmp);
|
||||
|
||||
resultMap = getWeightedInvokeResult(loop, RoundRobinLoadBalance.NAME);
|
||||
assertStrictWRRResult(loop, resultMap);
|
||||
|
||||
Assert.assertNotEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
Assertions.assertNotEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
} finally {
|
||||
//prevent other UT's failure
|
||||
weightInvokers.remove(weightInvokerTmp);
|
||||
|
|
@ -134,13 +135,13 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
recycleTimeField.setAccessible(true);
|
||||
recycleTimeField.setInt(RoundRobinLoadBalance.class, 10);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Assert.assertTrue("getField failed", true);
|
||||
Assertions.assertTrue(true, "getField failed");
|
||||
} catch (SecurityException e) {
|
||||
Assert.assertTrue("getField failed", true);
|
||||
Assertions.assertTrue(true, "getField failed");
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assert.assertTrue("getField failed", true);
|
||||
Assertions.assertTrue(true, "getField failed");
|
||||
} catch (IllegalAccessException e) {
|
||||
Assert.assertTrue("getField failed", true);
|
||||
Assertions.assertTrue(true, "getField failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,15 +153,15 @@ public class RoundRobinLoadBalanceTest extends LoadBalanceBaseTest {
|
|||
assertStrictWRRResult(loop, resultMap);
|
||||
|
||||
// inner nodes cache judgement
|
||||
RoundRobinLoadBalance lb = (RoundRobinLoadBalance)getLoadBalance(RoundRobinLoadBalance.NAME);
|
||||
Assert.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
RoundRobinLoadBalance lb = (RoundRobinLoadBalance) getLoadBalance(RoundRobinLoadBalance.NAME);
|
||||
Assertions.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
|
||||
weightInvokers.remove(weightInvokerTmp);
|
||||
|
||||
resultMap = getWeightedInvokeResult(loop, RoundRobinLoadBalance.NAME);
|
||||
assertStrictWRRResult(loop, resultMap);
|
||||
|
||||
Assert.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
Assertions.assertEquals(weightInvokers.size(), lb.getInvokerAddrList(weightInvokers, weightTestInvocation).size());
|
||||
} finally {
|
||||
//prevent other UT's failure
|
||||
weightInvokers.remove(weightInvokerTmp);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.cluster.merger;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -36,9 +36,9 @@ public class ResultMergerTest {
|
|||
public void testMergerFactoryIllegalArgumentException() {
|
||||
try {
|
||||
MergerFactory.getMerger(null);
|
||||
Assert.fail("expected IllegalArgumentException for null argument");
|
||||
Assertions.fail("expected IllegalArgumentException for null argument");
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Assert.assertEquals("returnType is null", exception.getMessage());
|
||||
Assertions.assertEquals("returnType is null", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,9 +51,9 @@ public class ResultMergerTest {
|
|||
Integer[] integerArray = {3, 4, 5};
|
||||
try {
|
||||
Object result = ArrayMerger.INSTANCE.merge(stringArray, null, integerArray);
|
||||
Assert.fail("expected IllegalArgumentException for different arguments' types");
|
||||
Assertions.fail("expected IllegalArgumentException for different arguments' types");
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Assert.assertEquals("Arguments' types are different", exception.getMessage());
|
||||
Assertions.assertEquals("Arguments' types are different", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,11 +67,11 @@ public class ResultMergerTest {
|
|||
String[] stringArray3 = {};
|
||||
|
||||
Object result = ArrayMerger.INSTANCE.merge(stringArray1, stringArray2, stringArray3, null);
|
||||
Assert.assertTrue(result.getClass().isArray());
|
||||
Assert.assertEquals(6, Array.getLength(result));
|
||||
Assert.assertTrue(String.class.isInstance(Array.get(result, 0)));
|
||||
Assertions.assertTrue(result.getClass().isArray());
|
||||
Assertions.assertEquals(6, Array.getLength(result));
|
||||
Assertions.assertTrue(String.class.isInstance(Array.get(result, 0)));
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Assert.assertEquals(String.valueOf(i + 1), Array.get(result, i));
|
||||
Assertions.assertEquals(String.valueOf(i + 1), Array.get(result, i));
|
||||
}
|
||||
|
||||
Integer[] intArray1 = {1, 2, 3};
|
||||
|
|
@ -79,21 +79,21 @@ public class ResultMergerTest {
|
|||
Integer[] intArray3 = {7};
|
||||
// trigger ArrayMerger
|
||||
result = MergerFactory.getMerger(Integer[].class).merge(intArray1, intArray2, intArray3, null);
|
||||
Assert.assertTrue(result.getClass().isArray());
|
||||
Assert.assertEquals(7, Array.getLength(result));
|
||||
Assert.assertTrue(Integer.class == result.getClass().getComponentType());
|
||||
Assertions.assertTrue(result.getClass().isArray());
|
||||
Assertions.assertEquals(7, Array.getLength(result));
|
||||
Assertions.assertTrue(Integer.class == result.getClass().getComponentType());
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Assert.assertEquals(i + 1, Array.get(result, i));
|
||||
Assertions.assertEquals(i + 1, Array.get(result, i));
|
||||
}
|
||||
|
||||
result = ArrayMerger.INSTANCE.merge(null);
|
||||
Assert.assertEquals(0, Array.getLength(result));
|
||||
Assertions.assertEquals(0, Array.getLength(result));
|
||||
|
||||
result = ArrayMerger.INSTANCE.merge(null, null);
|
||||
Assert.assertEquals(0, Array.getLength(result));
|
||||
Assertions.assertEquals(0, Array.getLength(result));
|
||||
|
||||
result = ArrayMerger.INSTANCE.merge(null, new Object[0]);
|
||||
Assert.assertEquals(0, Array.getLength(result));
|
||||
Assertions.assertEquals(0, Array.getLength(result));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -104,17 +104,17 @@ public class ResultMergerTest {
|
|||
boolean[] arrayOne = {true, false};
|
||||
boolean[] arrayTwo = {false};
|
||||
boolean[] result = MergerFactory.getMerger(boolean[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(3, result.length);
|
||||
Assertions.assertEquals(3, result.length);
|
||||
boolean[] mergedResult = {true, false, false};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertEquals(mergedResult[i], result[i]);
|
||||
Assertions.assertEquals(mergedResult[i], result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(boolean[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(boolean[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -125,17 +125,17 @@ public class ResultMergerTest {
|
|||
byte[] arrayOne = {1, 2};
|
||||
byte[] arrayTwo = {1, 32};
|
||||
byte[] result = MergerFactory.getMerger(byte[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
byte[] mergedResult = {1, 2, 1, 32};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertEquals(mergedResult[i], result[i]);
|
||||
Assertions.assertEquals(mergedResult[i], result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(byte[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(byte[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,17 +146,17 @@ public class ResultMergerTest {
|
|||
char[] arrayOne = "hello".toCharArray();
|
||||
char[] arrayTwo = "world".toCharArray();
|
||||
char[] result = MergerFactory.getMerger(char[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(10, result.length);
|
||||
Assertions.assertEquals(10, result.length);
|
||||
char[] mergedResult = "helloworld".toCharArray();
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertEquals(mergedResult[i], result[i]);
|
||||
Assertions.assertEquals(mergedResult[i], result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(char[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(char[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -167,17 +167,17 @@ public class ResultMergerTest {
|
|||
double[] arrayOne = {1.2d, 3.5d};
|
||||
double[] arrayTwo = {2d, 34d};
|
||||
double[] result = MergerFactory.getMerger(double[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
double[] mergedResult = {1.2d, 3.5d, 2d, 34d};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertTrue(mergedResult[i] == result[i]);
|
||||
Assertions.assertTrue(mergedResult[i] == result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(double[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(double[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,17 +188,17 @@ public class ResultMergerTest {
|
|||
float[] arrayOne = {1.2f, 3.5f};
|
||||
float[] arrayTwo = {2f, 34f};
|
||||
float[] result = MergerFactory.getMerger(float[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
double[] mergedResult = {1.2f, 3.5f, 2f, 34f};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertTrue(mergedResult[i] == result[i]);
|
||||
Assertions.assertTrue(mergedResult[i] == result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(float[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(float[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,17 +209,17 @@ public class ResultMergerTest {
|
|||
int[] arrayOne = {1, 2};
|
||||
int[] arrayTwo = {2, 34};
|
||||
int[] result = MergerFactory.getMerger(int[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
double[] mergedResult = {1, 2, 2, 34};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertTrue(mergedResult[i] == result[i]);
|
||||
Assertions.assertTrue(mergedResult[i] == result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(int[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(int[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -238,7 +238,7 @@ public class ResultMergerTest {
|
|||
}};
|
||||
|
||||
List result = MergerFactory.getMerger(List.class).merge(list1, list2, null);
|
||||
Assert.assertEquals(5, result.size());
|
||||
Assertions.assertEquals(5, result.size());
|
||||
ArrayList<String> expected = new ArrayList<String>() {{
|
||||
add(null);
|
||||
add("1");
|
||||
|
|
@ -246,13 +246,13 @@ public class ResultMergerTest {
|
|||
add("3");
|
||||
add("4");
|
||||
}};
|
||||
Assert.assertEquals(expected, result);
|
||||
Assertions.assertEquals(expected, result);
|
||||
|
||||
result = MergerFactory.getMerger(List.class).merge(null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
|
||||
result = MergerFactory.getMerger(List.class).merge(null, null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -269,20 +269,20 @@ public class ResultMergerTest {
|
|||
put("444", 2323);
|
||||
}};
|
||||
Map<Object, Object> result = MergerFactory.getMerger(Map.class).merge(mapOne, mapTwo, null);
|
||||
Assert.assertEquals(4, result.size());
|
||||
Assertions.assertEquals(4, result.size());
|
||||
Map<String, Integer> mergedResult = new HashMap<String, Integer>() {{
|
||||
put("11", 222);
|
||||
put("223", 11);
|
||||
put("3333", 3232);
|
||||
put("444", 2323);
|
||||
}};
|
||||
Assert.assertEquals(mergedResult, result);
|
||||
Assertions.assertEquals(mergedResult, result);
|
||||
|
||||
result = MergerFactory.getMerger(Map.class).merge(null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
|
||||
result = MergerFactory.getMerger(Map.class).merge(null, null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -293,17 +293,17 @@ public class ResultMergerTest {
|
|||
long[] arrayOne = {1l, 2l};
|
||||
long[] arrayTwo = {2l, 34l};
|
||||
long[] result = MergerFactory.getMerger(long[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
double[] mergedResult = {1l, 2l, 2l, 34l};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertTrue(mergedResult[i] == result[i]);
|
||||
Assertions.assertTrue(mergedResult[i] == result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(long[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(long[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -324,8 +324,8 @@ public class ResultMergerTest {
|
|||
|
||||
Set result = MergerFactory.getMerger(Set.class).merge(set1, set2, null);
|
||||
|
||||
Assert.assertEquals(4, result.size());
|
||||
Assert.assertEquals(new HashSet<String>() {
|
||||
Assertions.assertEquals(4, result.size());
|
||||
Assertions.assertEquals(new HashSet<String>() {
|
||||
{
|
||||
add(null);
|
||||
add("1");
|
||||
|
|
@ -335,10 +335,10 @@ public class ResultMergerTest {
|
|||
}, result);
|
||||
|
||||
result = MergerFactory.getMerger(Set.class).merge(null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
|
||||
result = MergerFactory.getMerger(Set.class).merge(null, null);
|
||||
Assert.assertEquals(0, result.size());
|
||||
Assertions.assertEquals(0, result.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -349,16 +349,16 @@ public class ResultMergerTest {
|
|||
short[] arrayOne = {1, 2};
|
||||
short[] arrayTwo = {2, 34};
|
||||
short[] result = MergerFactory.getMerger(short[].class).merge(arrayOne, arrayTwo, null);
|
||||
Assert.assertEquals(4, result.length);
|
||||
Assertions.assertEquals(4, result.length);
|
||||
double[] mergedResult = {1, 2, 2, 34};
|
||||
for (int i = 0; i < mergedResult.length; i++) {
|
||||
Assert.assertTrue(mergedResult[i] == result[i]);
|
||||
Assertions.assertTrue(mergedResult[i] == result[i]);
|
||||
}
|
||||
|
||||
result = MergerFactory.getMerger(short[].class).merge(null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
|
||||
result = MergerFactory.getMerger(short[].class).merge(null, null);
|
||||
Assert.assertEquals(0, result.length);
|
||||
Assertions.assertEquals(0, result.length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package org.apache.dubbo.rpc.cluster.router;
|
|||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* FIXME This is not a formal UT
|
||||
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
public class ConfigConditionRouterTest {
|
||||
private static CuratorFramework client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
|
||||
new ExponentialBackoffRetry(1000, 3));
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package org.apache.dubbo.rpc.cluster.router;
|
|||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* FIXME This is not a formal UT
|
||||
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
public class TagRouterTest {
|
||||
private static CuratorFramework client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
|
||||
new ExponentialBackoffRetry(1000, 3));
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ import org.apache.dubbo.rpc.RpcInvocation;
|
|||
import org.apache.dubbo.rpc.cluster.Router;
|
||||
import org.apache.dubbo.rpc.cluster.router.MockInvoker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -38,11 +38,11 @@ public class ConditionRouterTest {
|
|||
|
||||
private URL SCRIPT_URL = URL.valueOf("condition://0.0.0.0/com.foo.BarService");
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
|
|
@ -56,31 +56,31 @@ public class ConditionRouterTest {
|
|||
|
||||
Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => host = 1.2.3.4"));
|
||||
boolean matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(false, matchWhen);
|
||||
Assertions.assertEquals(false, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.4 & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.* & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.1 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(false, matchWhen);
|
||||
Assertions.assertEquals(false, matchWhen);
|
||||
|
||||
router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.2 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -121,12 +121,12 @@ public class ConditionRouterTest {
|
|||
List<Invoker<String>> filteredInvokers4 = router4.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
List<Invoker<String>> filteredInvokers5 = router5.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
List<Invoker<String>> filteredInvokers6 = router6.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(1, filteredInvokers1.size());
|
||||
Assert.assertEquals(0, filteredInvokers2.size());
|
||||
Assert.assertEquals(0, filteredInvokers3.size());
|
||||
Assert.assertEquals(1, filteredInvokers4.size());
|
||||
Assert.assertEquals(2, filteredInvokers5.size());
|
||||
Assert.assertEquals(1, filteredInvokers6.size());
|
||||
Assertions.assertEquals(1, filteredInvokers1.size());
|
||||
Assertions.assertEquals(0, filteredInvokers2.size());
|
||||
Assertions.assertEquals(0, filteredInvokers3.size());
|
||||
Assertions.assertEquals(1, filteredInvokers4.size());
|
||||
Assertions.assertEquals(2, filteredInvokers5.size());
|
||||
Assertions.assertEquals(1, filteredInvokers6.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -136,23 +136,23 @@ public class ConditionRouterTest {
|
|||
Router router = new ConditionRouterFactory().getRouter(getRouteUrl("methods=getFoo => host = 1.2.3.4"));
|
||||
boolean matchWhen = ((ConditionRouter) router).matchWhen(
|
||||
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=setFoo,getFoo,findFoo"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
// Exactly one method, match
|
||||
matchWhen = ((ConditionRouter) router).matchWhen(
|
||||
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
// Method routing and Other condition routing can work together
|
||||
Router router2 = new ConditionRouterFactory()
|
||||
.getRouter(getRouteUrl("methods=getFoo & host!=1.1.1.1 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router2).matchWhen(
|
||||
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
|
||||
Assert.assertEquals(false, matchWhen);
|
||||
Assertions.assertEquals(false, matchWhen);
|
||||
|
||||
Router router3 = new ConditionRouterFactory()
|
||||
.getRouter(getRouteUrl("methods=getFoo & host=1.1.1.1 => host = 1.2.3.4"));
|
||||
matchWhen = ((ConditionRouter) router3).matchWhen(
|
||||
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
|
||||
Assert.assertEquals(true, matchWhen);
|
||||
Assertions.assertEquals(true, matchWhen);
|
||||
// Test filter condition
|
||||
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
|
||||
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
|
||||
|
|
@ -169,14 +169,14 @@ public class ConditionRouterTest {
|
|||
Constants.FORCE_KEY, String.valueOf(true)));
|
||||
List<Invoker<String>> filteredInvokers1 = router4.route(invokers,
|
||||
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(1, filteredInvokers1.size());
|
||||
Assertions.assertEquals(1, filteredInvokers1.size());
|
||||
|
||||
Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl(
|
||||
"host = " + NetUtils.getLocalHost() + " & methods = unvalidmethod => " + " host = 10.20.3.3")
|
||||
.addParameter(Constants.FORCE_KEY, String.valueOf(true)));
|
||||
List<Invoker<String>> filteredInvokers2 = router5.route(invokers,
|
||||
URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation);
|
||||
Assert.assertEquals(3, filteredInvokers2.size());
|
||||
Assertions.assertEquals(3, filteredInvokers2.size());
|
||||
// Request a non-exists method
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ public class ConditionRouterTest {
|
|||
invokers.add(new MockInvoker<String>());
|
||||
invokers.add(new MockInvoker<String>());
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(0, filteredInvokers.size());
|
||||
Assertions.assertEquals(0, filteredInvokers.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -199,7 +199,7 @@ public class ConditionRouterTest {
|
|||
invokers.add(new MockInvoker<String>());
|
||||
invokers.add(new MockInvoker<String>());
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(0, filteredInvokers.size());
|
||||
Assertions.assertEquals(0, filteredInvokers.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -210,7 +210,7 @@ public class ConditionRouterTest {
|
|||
invokers.add(new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")));
|
||||
invokers.add(new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")));
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(invokers, filteredInvokers);
|
||||
Assertions.assertEquals(invokers, filteredInvokers);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -224,9 +224,9 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(2, filteredInvokers.size());
|
||||
Assert.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assert.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
Assertions.assertEquals(2, filteredInvokers.size());
|
||||
Assertions.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assertions.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -240,9 +240,9 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(2, filteredInvokers.size());
|
||||
Assert.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assert.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
Assertions.assertEquals(2, filteredInvokers.size());
|
||||
Assertions.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assertions.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -256,9 +256,9 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(2, filteredInvokers.size());
|
||||
Assert.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assert.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
Assertions.assertEquals(2, filteredInvokers.size());
|
||||
Assertions.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assertions.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -272,9 +272,9 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(2, filteredInvokers.size());
|
||||
Assert.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assert.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
Assertions.assertEquals(2, filteredInvokers.size());
|
||||
Assertions.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assertions.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -288,7 +288,7 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(invokers, filteredInvokers);
|
||||
Assertions.assertEquals(invokers, filteredInvokers);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -302,7 +302,7 @@ public class ConditionRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
|
||||
Assert.assertEquals(0, filteredInvokers.size());
|
||||
Assertions.assertEquals(0, filteredInvokers.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,10 +31,10 @@ import org.apache.dubbo.rpc.cluster.RouterFactory;
|
|||
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
|
||||
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -55,11 +55,11 @@ public class FileRouterEngineTest {
|
|||
Result result = new RpcResult();
|
||||
private RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getAdaptiveExtension();
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
invokers.add(invoker1);
|
||||
invokers.add(invoker2);
|
||||
|
|
@ -78,7 +78,7 @@ public class FileRouterEngineTest {
|
|||
for (int i = 0; i < 100; i++) {
|
||||
sinvoker.invoke(invocation);
|
||||
Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
|
||||
Assert.assertEquals(invoker2, invoker);
|
||||
Assertions.assertEquals(invoker2, invoker);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ public class FileRouterEngineTest {
|
|||
for (int i = 0; i < 100; i++) {
|
||||
sinvoker.invoke(invocation);
|
||||
Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
|
||||
Assert.assertEquals(invoker1, invoker);
|
||||
Assertions.assertEquals(invoker1, invoker);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ public class FileRouterEngineTest {
|
|||
for (int i = 0; i < 100; i++) {
|
||||
sinvoker.invoke(invocation);
|
||||
Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
|
||||
Assert.assertEquals(invoker1, invoker);
|
||||
Assertions.assertEquals(invoker1, invoker);
|
||||
}
|
||||
}
|
||||
{
|
||||
|
|
@ -125,7 +125,7 @@ public class FileRouterEngineTest {
|
|||
for (int i = 0; i < 100; i++) {
|
||||
sinvoker.invoke(invocation);
|
||||
Invoker<FileRouterEngineTest> invoker = sinvoker.getSelectedInvoker();
|
||||
Assert.assertEquals(invoker2, invoker);
|
||||
Assertions.assertEquals(invoker2, invoker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,29 +17,30 @@
|
|||
package org.apache.dubbo.rpc.cluster.router.script;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.cluster.Router;
|
||||
import org.apache.dubbo.rpc.cluster.router.MockInvoker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptRouterTest {
|
||||
|
||||
private URL SCRIPT_URL = URL.valueOf("script://javascript?type=javascript");
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ public class ScriptRouterTest {
|
|||
invokers.add(new MockInvoker<String>());
|
||||
invokers.add(new MockInvoker<String>());
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
|
||||
Assert.assertEquals(invokers, filteredInvokers);
|
||||
Assertions.assertEquals(invokers, filteredInvokers);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,53 +79,53 @@ public class ScriptRouterTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
List<Invoker<String>> filteredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
|
||||
Assert.assertEquals(2, filteredInvokers.size());
|
||||
Assert.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assert.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
Assertions.assertEquals(2, filteredInvokers.size());
|
||||
Assertions.assertEquals(invoker2, filteredInvokers.get(0));
|
||||
Assertions.assertEquals(invoker3, filteredInvokers.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouteHostFilter() {
|
||||
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
|
||||
MockInvoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.1:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.2:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.3:20880/com.dubbo.HelloService"));
|
||||
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
|
||||
MockInvoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.1:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.2:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.3:20880/com.dubbo.HelloService"));
|
||||
invokers.add(invoker1);
|
||||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
|
||||
String script = "function route(invokers, invocation, context){ " +
|
||||
" var result = new java.util.ArrayList(invokers.size()); " +
|
||||
" var targetHost = new java.util.ArrayList(); " +
|
||||
" targetHost.add(\"10.134.108.2\"); " +
|
||||
" for (var i = 0; i < invokers.length; i++) { " +
|
||||
" if(targetHost.contains(invokers[i].getUrl().getHost())){ " +
|
||||
" result.add(invokers[i]); " +
|
||||
" } " +
|
||||
" } " +
|
||||
" return result; " +
|
||||
"} " +
|
||||
"route(invokers, invocation, context) ";
|
||||
|
||||
|
||||
String script = "function route(invokers, invocation, context){ " +
|
||||
" var result = new java.util.ArrayList(invokers.size()); " +
|
||||
" var targetHost = new java.util.ArrayList(); " +
|
||||
" targetHost.add(\"10.134.108.2\"); " +
|
||||
" for (var i = 0; i < invokers.length; i++) { " +
|
||||
" if(targetHost.contains(invokers[i].getUrl().getHost())){ " +
|
||||
" result.add(invokers[i]); " +
|
||||
" } " +
|
||||
" } " +
|
||||
" return result; " +
|
||||
"} " +
|
||||
"route(invokers, invocation, context) ";
|
||||
|
||||
Router router = new ScriptRouterFactory().getRouter(getRouteUrl(script));
|
||||
List<Invoker<String>> routeResult = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
|
||||
Assert.assertEquals(1, routeResult.size());
|
||||
Assert.assertEquals(invoker2,routeResult.get(0));
|
||||
Assertions.assertEquals(1, routeResult.size());
|
||||
Assertions.assertEquals(invoker2, routeResult.get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRoute_throwException() {
|
||||
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
|
||||
MockInvoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.1:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.2:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.3:20880/com.dubbo.HelloService"));
|
||||
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
|
||||
MockInvoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.1:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.2:20880/com.dubbo.HelloService"));
|
||||
MockInvoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://10.134.108.3:20880/com.dubbo.HelloService"));
|
||||
invokers.add(invoker1);
|
||||
invokers.add(invoker2);
|
||||
invokers.add(invoker3);
|
||||
|
||||
|
||||
String script = "/";
|
||||
Router router = new ScriptRouterFactory().getRouter(getRouteUrl(script));
|
||||
List<Invoker<String>> routeResult = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
|
||||
Assert.assertEquals(3, routeResult.size());
|
||||
Assertions.assertEquals(3, routeResult.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -35,11 +35,11 @@ import org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance;
|
|||
import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
|
||||
import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -72,17 +72,17 @@ public class AbstractClusterInvokerTest {
|
|||
Invoker<IHelloService> mockedInvoker1;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void teardown() throws Exception {
|
||||
RpcContext.getContext().clearAttachments();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
invocation.setMethodName("sayHello");
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ public class AbstractClusterInvokerTest {
|
|||
// setup attachment
|
||||
RpcContext.getContext().setAttachment(attachKey, attachValue);
|
||||
Map<String, String> attachments = RpcContext.getContext().getAttachments();
|
||||
Assert.assertTrue("set attachment failed!", attachments != null && attachments.size() == 1);
|
||||
Assertions.assertTrue( attachments != null && attachments.size() == 1,"set attachment failed!");
|
||||
|
||||
cluster = new AbstractClusterInvoker(dic) {
|
||||
@Override
|
||||
|
|
@ -156,7 +156,7 @@ public class AbstractClusterInvokerTest {
|
|||
throws RpcException {
|
||||
// attachment will be bind to invocation
|
||||
String value = invocation.getAttachment(attachKey);
|
||||
Assert.assertTrue("binding attachment failed!", value != null && value.equals(attachValue));
|
||||
Assertions.assertTrue(value != null && value.equals(attachValue),"binding attachment failed!");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
@ -168,16 +168,16 @@ public class AbstractClusterInvokerTest {
|
|||
@Test
|
||||
public void testSelect_Invokersize0() throws Exception {
|
||||
LoadBalance l = cluster.initLoadBalance(invokers, invocation);
|
||||
Assert.assertNotNull("cluster.initLoadBalance returns null!", l);
|
||||
Assertions.assertNotNull(l,"cluster.initLoadBalance returns null!");
|
||||
{
|
||||
Invoker invoker = cluster.select(l, null, null, null);
|
||||
Assert.assertEquals(null, invoker);
|
||||
Assertions.assertEquals(null, invoker);
|
||||
}
|
||||
{
|
||||
invokers.clear();
|
||||
selectedInvokers.clear();
|
||||
Invoker invoker = cluster.select(l, null, invokers, null);
|
||||
Assert.assertEquals(null, invoker);
|
||||
Assertions.assertEquals(null, invoker);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,9 +186,9 @@ public class AbstractClusterInvokerTest {
|
|||
invokers.clear();
|
||||
invokers.add(invoker1);
|
||||
LoadBalance l = cluster.initLoadBalance(invokers, invocation);
|
||||
Assert.assertNotNull("cluster.initLoadBalance returns null!", l);
|
||||
Assertions.assertNotNull(l,"cluster.initLoadBalance returns null!");
|
||||
Invoker invoker = cluster.select(l, null, invokers, null);
|
||||
Assert.assertEquals(invoker1, invoker);
|
||||
Assertions.assertEquals(invoker1, invoker);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -197,18 +197,18 @@ public class AbstractClusterInvokerTest {
|
|||
invokers.add(invoker2);
|
||||
invokers.add(invoker4);
|
||||
LoadBalance l = cluster.initLoadBalance(invokers, invocation);
|
||||
Assert.assertNotNull("cluster.initLoadBalance returns null!", l);
|
||||
Assertions.assertNotNull(l,"cluster.initLoadBalance returns null!");
|
||||
{
|
||||
selectedInvokers.clear();
|
||||
selectedInvokers.add(invoker4);
|
||||
Invoker invoker = cluster.select(l, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(invoker2, invoker);
|
||||
Assertions.assertEquals(invoker2, invoker);
|
||||
}
|
||||
{
|
||||
selectedInvokers.clear();
|
||||
selectedInvokers.add(invoker2);
|
||||
Invoker invoker = cluster.select(l, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(invoker4, invoker);
|
||||
Assertions.assertEquals(invoker4, invoker);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,8 +228,8 @@ public class AbstractClusterInvokerTest {
|
|||
initlistsize5();
|
||||
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(false, sinvoker.isAvailable());
|
||||
Assert.assertEquals(invoker1, sinvoker);
|
||||
Assertions.assertEquals(false, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(invoker1, sinvoker);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertSame(invoker1, sinvoker);
|
||||
Assertions.assertSame(invoker1, sinvoker);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
|
|
@ -256,7 +256,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertSame(invoker2, sinvoker);
|
||||
Assertions.assertSame(invoker2, sinvoker);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
|
|
@ -266,7 +266,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertSame(invoker3, sinvoker);
|
||||
Assertions.assertSame(invoker3, sinvoker);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
|
|
@ -276,7 +276,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker3);
|
||||
selectedInvokers.add(invoker4);
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertSame(invoker5, sinvoker);
|
||||
Assertions.assertSame(invoker5, sinvoker);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
|
|
@ -287,7 +287,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(invokers.contains(sinvoker));
|
||||
Assertions.assertTrue(invokers.contains(sinvoker));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -305,7 +305,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker3);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(sinvoker == invoker4);
|
||||
Assertions.assertTrue(sinvoker == invoker4);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
|
|
@ -315,14 +315,14 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
}
|
||||
{
|
||||
//Boundary condition test .
|
||||
for (int i = 0; i < 100; i++) {
|
||||
selectedInvokers.clear();
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
}
|
||||
}
|
||||
{
|
||||
|
|
@ -333,7 +333,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker3);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
}
|
||||
}
|
||||
{
|
||||
|
|
@ -346,7 +346,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker4);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
Assertions.assertTrue(sinvoker == invoker2 || sinvoker == invoker4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -357,12 +357,12 @@ public class AbstractClusterInvokerTest {
|
|||
int min = 1000, max = 5000;
|
||||
Double d = (Math.random() * (max - min + 1) + min);
|
||||
int runs = d.intValue();
|
||||
Assert.assertTrue(runs > min);
|
||||
Assertions.assertTrue(runs > min);
|
||||
LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(lbname);
|
||||
initlistsize5();
|
||||
for (int i = 0; i < runs; i++) {
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.clear();
|
||||
selectedInvokers.add(invoker1);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -378,7 +378,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.clear();
|
||||
selectedInvokers.add(invoker2);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -387,7 +387,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker2);
|
||||
selectedInvokers.add(invoker4);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -397,7 +397,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker3);
|
||||
selectedInvokers.add(invoker5);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -408,7 +408,7 @@ public class AbstractClusterInvokerTest {
|
|||
selectedInvokers.add(invoker2);
|
||||
selectedInvokers.add(invoker3);
|
||||
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
|
||||
Assert.assertEquals(true, sinvoker.isAvailable());
|
||||
Assertions.assertEquals(true, sinvoker.isAvailable());
|
||||
|
||||
Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
|
||||
}
|
||||
|
|
@ -438,10 +438,10 @@ public class AbstractClusterInvokerTest {
|
|||
Long count = entry.getValue().get();
|
||||
// System.out.println(count);
|
||||
if (entry.getKey().isAvailable())
|
||||
Assert.assertTrue("count should > avg", count > runs / invokers.size());
|
||||
Assertions.assertTrue(count > runs / invokers.size(),"count should > avg");
|
||||
}
|
||||
|
||||
Assert.assertEquals(runs, counter.get(invoker2).get() + counter.get(invoker4).get());
|
||||
Assertions.assertEquals(runs, counter.get(invoker2).get() + counter.get(invoker4).get());
|
||||
;
|
||||
|
||||
}
|
||||
|
|
@ -491,23 +491,23 @@ public class AbstractClusterInvokerTest {
|
|||
FailoverClusterInvoker<DemoService> failoverClusterInvoker = new FailoverClusterInvoker<DemoService>(directory);
|
||||
try {
|
||||
failoverClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
}
|
||||
ForkingClusterInvoker<DemoService> forkingClusterInvoker = new ForkingClusterInvoker<DemoService>(directory);
|
||||
try {
|
||||
forkingClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
}
|
||||
FailfastClusterInvoker<DemoService> failfastClusterInvoker = new FailfastClusterInvoker<DemoService>(directory);
|
||||
try {
|
||||
failfastClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0]));
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
Assertions.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -525,10 +525,10 @@ public class AbstractClusterInvokerTest {
|
|||
mockedInvocation.setMethodName("sayHello");
|
||||
mockedInvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
|
||||
List<Invoker<IHelloService>> mockedInvokers = dic.list(mockedInvocation);
|
||||
Assert.assertEquals(1, mockedInvokers.size());
|
||||
Assertions.assertEquals(1, mockedInvokers.size());
|
||||
|
||||
List<Invoker<IHelloService>> invokers = dic.list(invocation);
|
||||
Assert.assertEquals(5, invokers.size());
|
||||
Assertions.assertEquals(5, invokers.size());
|
||||
}
|
||||
|
||||
public static interface IHelloService {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package org.apache.dubbo.rpc.cluster.support;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ClusterUtilsTest {
|
||||
|
||||
|
|
@ -53,28 +53,28 @@ public class ClusterUtilsTest {
|
|||
|
||||
URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters());
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.THREADS_KEY));
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY));
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY));
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY));
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY));
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.QUEUES_KEY));
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.QUEUES_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY));
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.ALIVE_KEY));
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.ALIVE_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY));
|
||||
|
||||
Assert.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY));
|
||||
Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY));
|
||||
|
||||
Assert.assertEquals(url.getPath(), "path");
|
||||
Assert.assertEquals(url.getUsername(), "username");
|
||||
Assert.assertEquals(url.getPassword(), "password");
|
||||
Assert.assertEquals(url.getParameter(Constants.PID_KEY), "1234");
|
||||
Assert.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo");
|
||||
Assertions.assertEquals(url.getPath(), "path");
|
||||
Assertions.assertEquals(url.getUsername(), "username");
|
||||
Assertions.assertEquals(url.getPassword(), "password");
|
||||
Assertions.assertEquals(url.getParameter(Constants.PID_KEY), "1234");
|
||||
Assertions.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ import org.apache.dubbo.rpc.RpcResult;
|
|||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
import org.apache.dubbo.rpc.cluster.filter.DemoService;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ public class FailSafeClusterInvokerTest {
|
|||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dic = mock(Directory.class);
|
||||
|
|
@ -85,7 +85,7 @@ public class FailSafeClusterInvokerTest {
|
|||
resetInvokerToException();
|
||||
FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
|
||||
invoker.invoke(invocation);
|
||||
Assert.assertNull(RpcContext.getContext().getInvoker());
|
||||
Assertions.assertNull(RpcContext.getContext().getInvoker());
|
||||
}
|
||||
|
||||
@Test()
|
||||
|
|
@ -95,7 +95,7 @@ public class FailSafeClusterInvokerTest {
|
|||
|
||||
FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
|
||||
Result ret = invoker.invoke(invocation);
|
||||
Assert.assertSame(result, ret);
|
||||
Assertions.assertSame(result, ret);
|
||||
}
|
||||
|
||||
@Test()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -27,27 +28,30 @@ import org.apache.dubbo.rpc.RpcResult;
|
|||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* FailbackClusterInvokerTest
|
||||
*
|
||||
* add annotation @FixMethodOrder, the testARetryFailed Method must to first execution
|
||||
/**
|
||||
* FailbackClusterInvokerTest
|
||||
* <p>
|
||||
* add annotation @TestMethodOrder, the testARetryFailed Method must to first execution
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@FixMethodOrder(org.junit.runners.MethodSorters.NAME_ASCENDING)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class FailbackClusterInvokerTest {
|
||||
|
||||
List<Invoker<FailbackClusterInvokerTest>> invokers = new ArrayList<Invoker<FailbackClusterInvokerTest>>();
|
||||
|
|
@ -61,7 +65,7 @@ public class FailbackClusterInvokerTest {
|
|||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dic = mock(Directory.class);
|
||||
|
|
@ -74,6 +78,15 @@ public class FailbackClusterInvokerTest {
|
|||
invokers.add(invoker);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
|
||||
dic = null;
|
||||
invocation = new RpcInvocation();
|
||||
invokers.clear();
|
||||
}
|
||||
|
||||
|
||||
private void resetInvokerToException() {
|
||||
given(invoker.invoke(invocation)).willThrow(new RuntimeException());
|
||||
given(invoker.getUrl()).willReturn(url);
|
||||
|
|
@ -87,16 +100,18 @@ public class FailbackClusterInvokerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testInvokeException() {
|
||||
resetInvokerToException();
|
||||
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<FailbackClusterInvokerTest>(
|
||||
dic);
|
||||
invoker.invoke(invocation);
|
||||
Assert.assertNull(RpcContext.getContext().getInvoker());
|
||||
Assertions.assertNull(RpcContext.getContext().getInvoker());
|
||||
DubboAppender.clear();
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Test
|
||||
@Order(2)
|
||||
public void testInvokeNoException() {
|
||||
|
||||
resetInvokerToNoException();
|
||||
|
|
@ -104,10 +119,11 @@ public class FailbackClusterInvokerTest {
|
|||
FailbackClusterInvoker<FailbackClusterInvokerTest> invoker = new FailbackClusterInvoker<FailbackClusterInvokerTest>(
|
||||
dic);
|
||||
Result ret = invoker.invoke(invocation);
|
||||
Assert.assertSame(result, ret);
|
||||
Assertions.assertSame(result, ret);
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testNoInvoke() {
|
||||
dic = mock(Directory.class);
|
||||
|
||||
|
|
@ -130,7 +146,9 @@ public class FailbackClusterInvokerTest {
|
|||
LogUtil.stop();
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Disabled
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testARetryFailed() throws Exception {
|
||||
//Test retries and
|
||||
|
||||
|
|
@ -143,15 +161,15 @@ public class FailbackClusterInvokerTest {
|
|||
invoker.invoke(invocation);
|
||||
invoker.invoke(invocation);
|
||||
invoker.invoke(invocation);
|
||||
Assert.assertNull(RpcContext.getContext().getInvoker());
|
||||
Assertions.assertNull(RpcContext.getContext().getInvoker());
|
||||
// invoker.retryFailed();// when retry the invoker which get from failed map already is not the mocked invoker,so
|
||||
//Ensure that the main thread is online
|
||||
CountDownLatch countDown = new CountDownLatch(1);
|
||||
countDown.await(15000L, TimeUnit.MILLISECONDS);
|
||||
LogUtil.stop();
|
||||
Assert.assertEquals("must have four error message ", 4, LogUtil.findMessage(Level.ERROR, "Failed retry to invoke method"));
|
||||
Assert.assertEquals("must have two error message ", 2, LogUtil.findMessage(Level.ERROR, "Failed retry times exceed threshold"));
|
||||
Assert.assertEquals("must have one error message ", 1, LogUtil.findMessage(Level.ERROR, "Failback background works error"));
|
||||
Assertions.assertEquals(4, LogUtil.findMessage(Level.ERROR, "Failed retry to invoke method"), "must have four error message ");
|
||||
Assertions.assertEquals(2, LogUtil.findMessage(Level.ERROR, "Failed retry times exceed threshold"), "must have two error message ");
|
||||
Assertions.assertEquals(1, LogUtil.findMessage(Level.ERROR, "Failback background works error"), "must have one error message ");
|
||||
// it can be invoke successfully
|
||||
}
|
||||
}
|
||||
|
|
@ -25,22 +25,20 @@ import org.apache.dubbo.rpc.RpcInvocation;
|
|||
import org.apache.dubbo.rpc.RpcResult;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* FailfastClusterInvokerTest
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FailfastClusterInvokerTest {
|
||||
|
|
@ -55,7 +53,7 @@ public class FailfastClusterInvokerTest {
|
|||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dic = mock(Directory.class);
|
||||
|
|
@ -81,12 +79,14 @@ public class FailfastClusterInvokerTest {
|
|||
given(invoker1.getInterface()).willReturn(FailfastClusterInvokerTest.class);
|
||||
}
|
||||
|
||||
@Test(expected = RpcException.class)
|
||||
@Test
|
||||
public void testInvokeExceptoin() {
|
||||
resetInvoker1ToException();
|
||||
FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
|
||||
invoker.invoke(invocation);
|
||||
Assert.assertSame(invoker1, RpcContext.getContext().getInvoker());
|
||||
Assertions.assertThrows(RpcException.class, () -> {
|
||||
resetInvoker1ToException();
|
||||
FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
|
||||
invoker.invoke(invocation);
|
||||
Assertions.assertSame(invoker1, RpcContext.getContext().getInvoker());
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
|
|
@ -96,7 +96,7 @@ public class FailfastClusterInvokerTest {
|
|||
|
||||
FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
|
||||
Result ret = invoker.invoke(invocation);
|
||||
Assert.assertSame(result, ret);
|
||||
Assertions.assertSame(result, ret);
|
||||
}
|
||||
|
||||
@Test()
|
||||
|
|
|
|||
|
|
@ -27,18 +27,18 @@ import org.apache.dubbo.rpc.cluster.Directory;
|
|||
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
|
||||
import org.apache.dubbo.rpc.protocol.AbstractInvoker;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ public class FailoverClusterInvokerTest {
|
|||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dic = mock(Directory.class);
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ import org.apache.dubbo.rpc.RpcResult;
|
|||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class ForkingClusterInvokerTest {
|
|||
private Directory<ForkingClusterInvokerTest> dic;
|
||||
private Result result = new RpcResult();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
dic = mock(Directory.class);
|
||||
|
|
@ -111,9 +111,9 @@ public class ForkingClusterInvokerTest {
|
|||
|
||||
try {
|
||||
invoker.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException expected) {
|
||||
Assert.assertTrue(expected.getMessage().contains("Failed to forking invoke provider"));
|
||||
Assertions.assertTrue(expected.getMessage().contains("Failed to forking invoke provider"));
|
||||
assertFalse(expected.getCause() instanceof RpcException);
|
||||
}
|
||||
}
|
||||
|
|
@ -130,16 +130,16 @@ public class ForkingClusterInvokerTest {
|
|||
RpcContext.getContext().setAttachment(attachKey, attachValue);
|
||||
|
||||
Map<String, String> attachments = RpcContext.getContext().getAttachments();
|
||||
Assert.assertTrue("set attachment failed!", attachments != null && attachments.size() == 1);
|
||||
Assertions.assertTrue(attachments != null && attachments.size() == 1, "set attachment failed!");
|
||||
try {
|
||||
invoker.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException expected) {
|
||||
Assert.assertTrue("Succeeded to forking invoke provider !", expected.getMessage().contains("Failed to forking invoke provider"));
|
||||
Assertions.assertTrue(expected.getMessage().contains("Failed to forking invoke provider"), "Succeeded to forking invoke provider !");
|
||||
assertFalse(expected.getCause() instanceof RpcException);
|
||||
}
|
||||
Map<String, String> afterInvoke = RpcContext.getContext().getAttachments();
|
||||
Assert.assertTrue("clear attachment failed!", afterInvoke != null && afterInvoke.size() == 0);
|
||||
Assertions.assertTrue(afterInvoke != null && afterInvoke.size() == 0, "clear attachment failed!");
|
||||
}
|
||||
|
||||
@Test()
|
||||
|
|
@ -150,7 +150,7 @@ public class ForkingClusterInvokerTest {
|
|||
ForkingClusterInvoker<ForkingClusterInvokerTest> invoker = new ForkingClusterInvoker<ForkingClusterInvokerTest>(
|
||||
dic);
|
||||
Result ret = invoker.invoke(invocation);
|
||||
Assert.assertSame(result, ret);
|
||||
Assertions.assertSame(result, ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@ import org.apache.dubbo.rpc.Result;
|
|||
import org.apache.dubbo.rpc.RpcResult;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -38,7 +38,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ public class MergeableClusterInvokerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
|
||||
directory = mock(Directory.class);
|
||||
|
|
@ -155,7 +155,7 @@ public class MergeableClusterInvokerTest {
|
|||
|
||||
// invoke
|
||||
Result result = mergeableClusterInvoker.invoke(invocation);
|
||||
Assert.assertTrue(result.getValue() instanceof Menu);
|
||||
Assertions.assertTrue(result.getValue() instanceof Menu);
|
||||
Menu menu = (Menu) result.getValue();
|
||||
Map<String, List<String>> expected = new HashMap<String, List<String>>();
|
||||
merge(expected, firstMenuMap);
|
||||
|
|
@ -219,7 +219,7 @@ public class MergeableClusterInvokerTest {
|
|||
mergeableClusterInvoker = new MergeableClusterInvoker<MenuService>(directory);
|
||||
|
||||
Result result = mergeableClusterInvoker.invoke(invocation);
|
||||
Assert.assertNull(result.getValue());
|
||||
Assertions.assertNull(result.getValue());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
|
|||
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
|
||||
import org.apache.dubbo.rpc.support.MockProtocol;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -43,7 +43,7 @@ public class MockClusterInvokerTest {
|
|||
|
||||
List<Invoker<IHelloService>> invokers = new ArrayList<Invoker<IHelloService>>();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void beforeMethod() {
|
||||
invokers.clear();
|
||||
}
|
||||
|
|
@ -67,13 +67,13 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("something", ret.getValue());
|
||||
Assertions.assertEquals("something", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -95,19 +95,19 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("aa", ret.getValue());
|
||||
Assertions.assertEquals("aa", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -131,19 +131,19 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("aa", ret.getValue());
|
||||
Assertions.assertEquals("aa", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -162,7 +162,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -178,25 +178,25 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("something", ret.getValue());
|
||||
Assertions.assertEquals("something", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("y", ret.getValue());
|
||||
Assertions.assertEquals("y", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("something3", ret.getValue());
|
||||
Assertions.assertEquals("something3", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,20 +213,20 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("y", ret.getValue());
|
||||
Assertions.assertEquals("y", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
try {
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
|
||||
}
|
||||
|
|
@ -247,25 +247,25 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("y", ret.getValue());
|
||||
Assertions.assertEquals("y", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(null, ret.getValue());
|
||||
Assertions.assertEquals(null, ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -283,25 +283,25 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("y", ret.getValue());
|
||||
Assertions.assertEquals("y", ret.getValue());
|
||||
|
||||
// If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("z", ret.getValue());
|
||||
Assertions.assertEquals("z", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("z", ret.getValue());
|
||||
Assertions.assertEquals("z", ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -319,25 +319,25 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("y", ret.getValue());
|
||||
Assertions.assertEquals("y", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("z", ret.getValue());
|
||||
Assertions.assertEquals("z", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("z", ret.getValue());
|
||||
Assertions.assertEquals("z", ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -353,19 +353,19 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething2");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("sayHello");
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -381,14 +381,14 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("x", ret.getValue());
|
||||
Assertions.assertEquals("x", ret.getValue());
|
||||
|
||||
//If no mock was configured, return null directly
|
||||
invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething3");
|
||||
try {
|
||||
ret = cluster.invoke(invocation);
|
||||
Assert.fail("fail invoke");
|
||||
Assertions.fail("fail invoke");
|
||||
} catch (RpcException e) {
|
||||
|
||||
}
|
||||
|
|
@ -407,7 +407,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("somethingmock", ret.getValue());
|
||||
Assertions.assertEquals("somethingmock", ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -423,7 +423,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("somethingmock", ret.getValue());
|
||||
Assertions.assertEquals("somethingmock", ret.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -438,7 +438,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals("somethingmock", ret.getValue());
|
||||
Assertions.assertEquals("somethingmock", ret.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -451,8 +451,8 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getSomething");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertTrue("result type must be String but was : " + ret.getValue().getClass(), ret.getValue() instanceof String);
|
||||
Assert.assertEquals("1688", (String) ret.getValue());
|
||||
Assertions.assertTrue(ret.getValue() instanceof String, "result type must be String but was : " + ret.getValue().getClass());
|
||||
Assertions.assertEquals("1688", (String) ret.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -465,8 +465,8 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getInt1");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertTrue("result type must be integer but was : " + ret.getValue().getClass(), ret.getValue() instanceof Integer);
|
||||
Assert.assertEquals(new Integer(1688), (Integer) ret.getValue());
|
||||
Assertions.assertTrue(ret.getValue() instanceof Integer, "result type must be integer but was : " + ret.getValue().getClass());
|
||||
Assertions.assertEquals(new Integer(1688), (Integer) ret.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -479,8 +479,8 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getBoolean1");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertTrue("result type must be Boolean but was : " + ret.getValue().getClass(), ret.getValue() instanceof Boolean);
|
||||
Assert.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
|
||||
Assertions.assertTrue(ret.getValue() instanceof Boolean, "result type must be Boolean but was : " + ret.getValue().getClass());
|
||||
Assertions.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -493,7 +493,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getBoolean2");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
|
||||
Assertions.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -507,7 +507,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getListString");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(0, ((List<String>) ret.getValue()).size());
|
||||
Assertions.assertEquals(0, ((List<String>) ret.getValue()).size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -522,8 +522,8 @@ public class MockClusterInvokerTest {
|
|||
invocation.setMethodName("getListString");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
List<String> rl = (List<String>) ret.getValue();
|
||||
Assert.assertEquals(2, rl.size());
|
||||
Assert.assertEquals("hi", rl.get(0));
|
||||
Assertions.assertEquals(2, rl.size());
|
||||
Assertions.assertEquals("hi", rl.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -537,7 +537,7 @@ public class MockClusterInvokerTest {
|
|||
RpcInvocation invocation = new RpcInvocation();
|
||||
invocation.setMethodName("getUsers");
|
||||
Result ret = cluster.invoke(invocation);
|
||||
Assert.assertEquals(0, ((List<User>) ret.getValue()).size());
|
||||
Assertions.assertEquals(0, ((List<User>) ret.getValue()).size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -553,8 +553,8 @@ public class MockClusterInvokerTest {
|
|||
Result ret = cluster.invoke(invocation);
|
||||
List<User> rl = (List<User>) ret.getValue();
|
||||
System.out.println(rl);
|
||||
Assert.assertEquals(2, rl.size());
|
||||
Assert.assertEquals("hi1", ((User) rl.get(0)).getName());
|
||||
Assertions.assertEquals(2, rl.size());
|
||||
Assertions.assertEquals("hi1", ((User) rl.get(0)).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -583,9 +583,9 @@ public class MockClusterInvokerTest {
|
|||
invocation.setMethodName("getBoolean2");
|
||||
try {
|
||||
cluster.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
Assert.assertFalse("not custem exception", e.isBiz());
|
||||
Assertions.assertFalse(e.isBiz(), "not custem exception");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -600,7 +600,7 @@ public class MockClusterInvokerTest {
|
|||
invocation.setMethodName("getBoolean2");
|
||||
try {
|
||||
cluster.invoke(invocation).recreate();
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (MyMockException e) {
|
||||
|
||||
}
|
||||
|
|
@ -617,9 +617,9 @@ public class MockClusterInvokerTest {
|
|||
invocation.setMethodName("getBoolean2");
|
||||
try {
|
||||
cluster.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
Assertions.assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -634,9 +634,9 @@ public class MockClusterInvokerTest {
|
|||
invocation.setMethodName("getBoolean2");
|
||||
try {
|
||||
cluster.invoke(invocation);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (RpcException e) {
|
||||
Assert.assertTrue(e.isTimeout());
|
||||
Assertions.assertTrue(e.isTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.dubbo.common;
|
||||
|
||||
/**
|
||||
* Resetable.
|
||||
*/
|
||||
public interface Resetable {
|
||||
|
||||
/**
|
||||
* reset.
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
void reset(URL url);
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.dubbo.common;
|
||||
|
||||
/**
|
||||
* Resetable.
|
||||
*/
|
||||
public interface Resetable {
|
||||
|
||||
/**
|
||||
* reset.
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
void reset(URL url);
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ package org.apache.dubbo.common;
|
|||
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -27,12 +27,12 @@ import java.util.Map;
|
|||
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class URLTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -16,22 +16,22 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.beanutil;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JavaBeanAccessorTest {
|
||||
|
||||
@Test
|
||||
public void testIsAccessByMethod(){
|
||||
Assert.assertTrue(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.METHOD));
|
||||
Assert.assertTrue(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.ALL));
|
||||
Assert.assertFalse(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.FIELD));
|
||||
Assertions.assertTrue(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.METHOD));
|
||||
Assertions.assertTrue(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.ALL));
|
||||
Assertions.assertFalse(JavaBeanAccessor.isAccessByMethod(JavaBeanAccessor.FIELD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAccessByField(){
|
||||
Assert.assertTrue(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.FIELD));
|
||||
Assert.assertTrue(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.ALL));
|
||||
Assert.assertFalse(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.METHOD));
|
||||
Assertions.assertTrue(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.FIELD));
|
||||
Assertions.assertTrue(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.ALL));
|
||||
Assertions.assertFalse(JavaBeanAccessor.isAccessByField(JavaBeanAccessor.METHOD));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ import org.apache.dubbo.common.model.person.PersonInfo;
|
|||
import org.apache.dubbo.common.model.person.PersonStatus;
|
||||
import org.apache.dubbo.common.model.person.Phone;
|
||||
import org.apache.dubbo.common.utils.PojoUtilsTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -37,142 +38,160 @@ import java.util.UUID;
|
|||
public class JavaBeanSerializeUtilTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize_Primitive() throws Exception {
|
||||
public void testSerialize_Primitive() {
|
||||
JavaBeanDescriptor descriptor;
|
||||
descriptor = JavaBeanSerializeUtil.serialize(Integer.MAX_VALUE);
|
||||
Assert.assertTrue(descriptor.isPrimitiveType());
|
||||
Assert.assertEquals(Integer.MAX_VALUE, descriptor.getPrimitiveProperty());
|
||||
Assertions.assertTrue(descriptor.isPrimitiveType());
|
||||
Assertions.assertEquals(Integer.MAX_VALUE, descriptor.getPrimitiveProperty());
|
||||
|
||||
Date now = new Date();
|
||||
descriptor = JavaBeanSerializeUtil.serialize(now);
|
||||
Assert.assertTrue(descriptor.isPrimitiveType());
|
||||
Assert.assertEquals(now, descriptor.getPrimitiveProperty());
|
||||
Assertions.assertTrue(descriptor.isPrimitiveType());
|
||||
Assertions.assertEquals(now, descriptor.getPrimitiveProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize_Primitive_NUll() throws Exception {
|
||||
public void testSerialize_Primitive_NUll() {
|
||||
JavaBeanDescriptor descriptor;
|
||||
descriptor = JavaBeanSerializeUtil.serialize(null);
|
||||
Assert.assertTrue(descriptor == null);
|
||||
Assertions.assertTrue(descriptor == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_Primitive() throws Exception {
|
||||
public void testDeserialize_Primitive() {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setPrimitiveProperty(Long.MAX_VALUE);
|
||||
Assert.assertEquals(Long.MAX_VALUE, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
Assertions.assertEquals(Long.MAX_VALUE, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
|
||||
BigDecimal decimal = BigDecimal.TEN;
|
||||
Assert.assertEquals(Long.MAX_VALUE, descriptor.setPrimitiveProperty(decimal));
|
||||
Assert.assertEquals(decimal, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
Assertions.assertEquals(Long.MAX_VALUE, descriptor.setPrimitiveProperty(decimal));
|
||||
Assertions.assertEquals(decimal, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
|
||||
String string = UUID.randomUUID().toString();
|
||||
Assert.assertEquals(decimal, descriptor.setPrimitiveProperty(string));
|
||||
Assert.assertEquals(string, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserialize_Primitive0() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_BEAN + 1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserialize_Null() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(null, JavaBeanDescriptor.TYPE_BEAN);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserialize_containsProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.containsProperty(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testSetEnumNameProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setEnumNameProperty(JavaBeanDescriptor.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetEnumNameProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.getEnumPropertyName();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testSetClassNameProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setClassNameProperty(JavaBeanDescriptor.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetClassNameProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.getClassNameProperty();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testSetPrimitiveProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(JavaBeanDescriptor.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
|
||||
descriptor.setPrimitiveProperty(JavaBeanDescriptor.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testGetPrimitiveProperty() throws Exception {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(JavaBeanDescriptor.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
|
||||
descriptor.getPrimitiveProperty();
|
||||
Assertions.assertEquals(decimal, descriptor.setPrimitiveProperty(string));
|
||||
Assertions.assertEquals(string, JavaBeanSerializeUtil.deserialize(descriptor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_get_and_set() throws Exception {
|
||||
public void testDeserialize_Primitive0() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_BEAN + 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_Null() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(null, JavaBeanDescriptor.TYPE_BEAN);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_containsProperty() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.containsProperty(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetEnumNameProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setEnumNameProperty(JavaBeanDescriptor.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnumNameProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.getEnumPropertyName();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetClassNameProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setClassNameProperty(JavaBeanDescriptor.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClassNameProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.getClassNameProperty();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPrimitiveProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(JavaBeanDescriptor.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
|
||||
descriptor.setPrimitiveProperty(JavaBeanDescriptor.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrimitiveProperty() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(JavaBeanDescriptor.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
|
||||
descriptor.getPrimitiveProperty();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_get_and_set() {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
|
||||
descriptor.setType(JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
Assert.assertTrue(descriptor.getType() == JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
Assertions.assertTrue(descriptor.getType() == JavaBeanDescriptor.TYPE_PRIMITIVE);
|
||||
descriptor.setClassName(JavaBeanDescriptor.class.getName());
|
||||
Assert.assertEquals(JavaBeanDescriptor.class.getName(), descriptor.getClassName());
|
||||
Assertions.assertEquals(JavaBeanDescriptor.class.getName(), descriptor.getClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize_Array() throws Exception {
|
||||
public void testSerialize_Array() {
|
||||
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
JavaBeanDescriptor descriptor = JavaBeanSerializeUtil.serialize(array, JavaBeanAccessor.METHOD);
|
||||
Assert.assertTrue(descriptor.isArrayType());
|
||||
Assert.assertEquals(int.class.getName(), descriptor.getClassName());
|
||||
Assertions.assertTrue(descriptor.isArrayType());
|
||||
Assertions.assertEquals(int.class.getName(), descriptor.getClassName());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Assert.assertEquals(array[i],
|
||||
Assertions.assertEquals(array[i],
|
||||
((JavaBeanDescriptor) descriptor.getProperty(i)).getPrimitiveProperty());
|
||||
}
|
||||
|
||||
Integer[] integers = new Integer[]{1, 2, 3, 4, null, null, null};
|
||||
descriptor = JavaBeanSerializeUtil.serialize(integers, JavaBeanAccessor.METHOD);
|
||||
Assert.assertTrue(descriptor.isArrayType());
|
||||
Assert.assertEquals(Integer.class.getName(), descriptor.getClassName());
|
||||
Assert.assertEquals(integers.length, descriptor.propertySize());
|
||||
Assertions.assertTrue(descriptor.isArrayType());
|
||||
Assertions.assertEquals(Integer.class.getName(), descriptor.getClassName());
|
||||
Assertions.assertEquals(integers.length, descriptor.propertySize());
|
||||
for (int i = 0; i < integers.length; i++) {
|
||||
if (integers[i] == null) {
|
||||
Assert.assertTrue(integers[i] == descriptor.getProperty(i));
|
||||
Assertions.assertTrue(integers[i] == descriptor.getProperty(i));
|
||||
} else {
|
||||
Assert.assertEquals(integers[i], ((JavaBeanDescriptor) descriptor.getProperty(i)).getPrimitiveProperty());
|
||||
Assertions.assertEquals(integers[i], ((JavaBeanDescriptor) descriptor.getProperty(i)).getPrimitiveProperty());
|
||||
}
|
||||
}
|
||||
|
||||
int[][] second = {{1, 2}, {3, 4}};
|
||||
descriptor = JavaBeanSerializeUtil.serialize(second, JavaBeanAccessor.METHOD);
|
||||
Assert.assertTrue(descriptor.isArrayType());
|
||||
Assert.assertEquals(int[].class.getName(), descriptor.getClassName());
|
||||
Assertions.assertTrue(descriptor.isArrayType());
|
||||
Assertions.assertEquals(int[].class.getName(), descriptor.getClassName());
|
||||
for (int i = 0; i < second.length; i++) {
|
||||
for (int j = 0; j < second[i].length; j++) {
|
||||
JavaBeanDescriptor item = (((JavaBeanDescriptor) descriptor.getProperty(i)));
|
||||
Assert.assertTrue(item.isArrayType());
|
||||
Assert.assertEquals(int.class.getName(), item.getClassName());
|
||||
Assert.assertEquals(second[i][j], ((JavaBeanDescriptor) item.getProperty(j)).getPrimitiveProperty());
|
||||
Assertions.assertTrue(item.isArrayType());
|
||||
Assertions.assertEquals(int.class.getName(), item.getClassName());
|
||||
Assertions.assertEquals(second[i][j], ((JavaBeanDescriptor) item.getProperty(j)).getPrimitiveProperty());
|
||||
}
|
||||
}
|
||||
|
||||
BigPerson[] persons = new BigPerson[]{createBigPerson(), createBigPerson()};
|
||||
descriptor = JavaBeanSerializeUtil.serialize(persons);
|
||||
Assert.assertTrue(descriptor.isArrayType());
|
||||
Assert.assertEquals(BigPerson.class.getName(), descriptor.getClassName());
|
||||
Assertions.assertTrue(descriptor.isArrayType());
|
||||
Assertions.assertEquals(BigPerson.class.getName(), descriptor.getClassName());
|
||||
for (int i = 0; i < persons.length; i++) {
|
||||
assertEqualsBigPerson(persons[i], descriptor.getProperty(i));
|
||||
}
|
||||
|
|
@ -180,27 +199,27 @@ public class JavaBeanSerializeUtilTest {
|
|||
|
||||
@Test
|
||||
public void testConstructorArg() {
|
||||
Assert.assertFalse((boolean) JavaBeanSerializeUtil.getConstructorArg(boolean.class));
|
||||
Assert.assertFalse((boolean) JavaBeanSerializeUtil.getConstructorArg(Boolean.class));
|
||||
Assert.assertEquals((byte)0, JavaBeanSerializeUtil.getConstructorArg(byte.class));
|
||||
Assert.assertEquals((byte)0, JavaBeanSerializeUtil.getConstructorArg(Byte.class));
|
||||
Assert.assertEquals((short)0, JavaBeanSerializeUtil.getConstructorArg(short.class));
|
||||
Assert.assertEquals((short)0, JavaBeanSerializeUtil.getConstructorArg(Short.class));
|
||||
Assert.assertEquals(0, JavaBeanSerializeUtil.getConstructorArg(int.class));
|
||||
Assert.assertEquals(0, JavaBeanSerializeUtil.getConstructorArg(Integer.class));
|
||||
Assert.assertEquals((long)0, JavaBeanSerializeUtil.getConstructorArg(long.class));
|
||||
Assert.assertEquals((long)0, JavaBeanSerializeUtil.getConstructorArg(Long.class));
|
||||
Assert.assertEquals((float) 0, JavaBeanSerializeUtil.getConstructorArg(float.class));
|
||||
Assert.assertEquals((float) 0, JavaBeanSerializeUtil.getConstructorArg(Float.class));
|
||||
Assert.assertEquals((double) 0, JavaBeanSerializeUtil.getConstructorArg(double.class));
|
||||
Assert.assertEquals((double) 0, JavaBeanSerializeUtil.getConstructorArg(Double.class));
|
||||
Assert.assertEquals((char)0, JavaBeanSerializeUtil.getConstructorArg(char.class));
|
||||
Assert.assertEquals(new Character((char)0), JavaBeanSerializeUtil.getConstructorArg(Character.class));
|
||||
Assert.assertEquals(null, JavaBeanSerializeUtil.getConstructorArg(JavaBeanSerializeUtil.class));
|
||||
Assertions.assertFalse((boolean) JavaBeanSerializeUtil.getConstructorArg(boolean.class));
|
||||
Assertions.assertFalse((boolean) JavaBeanSerializeUtil.getConstructorArg(Boolean.class));
|
||||
Assertions.assertEquals((byte) 0, JavaBeanSerializeUtil.getConstructorArg(byte.class));
|
||||
Assertions.assertEquals((byte) 0, JavaBeanSerializeUtil.getConstructorArg(Byte.class));
|
||||
Assertions.assertEquals((short) 0, JavaBeanSerializeUtil.getConstructorArg(short.class));
|
||||
Assertions.assertEquals((short) 0, JavaBeanSerializeUtil.getConstructorArg(Short.class));
|
||||
Assertions.assertEquals(0, JavaBeanSerializeUtil.getConstructorArg(int.class));
|
||||
Assertions.assertEquals(0, JavaBeanSerializeUtil.getConstructorArg(Integer.class));
|
||||
Assertions.assertEquals((long) 0, JavaBeanSerializeUtil.getConstructorArg(long.class));
|
||||
Assertions.assertEquals((long) 0, JavaBeanSerializeUtil.getConstructorArg(Long.class));
|
||||
Assertions.assertEquals((float) 0, JavaBeanSerializeUtil.getConstructorArg(float.class));
|
||||
Assertions.assertEquals((float) 0, JavaBeanSerializeUtil.getConstructorArg(Float.class));
|
||||
Assertions.assertEquals((double) 0, JavaBeanSerializeUtil.getConstructorArg(double.class));
|
||||
Assertions.assertEquals((double) 0, JavaBeanSerializeUtil.getConstructorArg(Double.class));
|
||||
Assertions.assertEquals((char) 0, JavaBeanSerializeUtil.getConstructorArg(char.class));
|
||||
Assertions.assertEquals(new Character((char) 0), JavaBeanSerializeUtil.getConstructorArg(Character.class));
|
||||
Assertions.assertEquals(null, JavaBeanSerializeUtil.getConstructorArg(JavaBeanSerializeUtil.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_Array() throws Exception {
|
||||
public void testDeserialize_Array() {
|
||||
final int len = 10;
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(int.class.getName(), JavaBeanDescriptor.TYPE_ARRAY);
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
|
@ -208,10 +227,10 @@ public class JavaBeanSerializeUtilTest {
|
|||
}
|
||||
|
||||
Object obj = JavaBeanSerializeUtil.deserialize(descriptor);
|
||||
Assert.assertTrue(obj.getClass().isArray());
|
||||
Assert.assertTrue(int.class == obj.getClass().getComponentType());
|
||||
Assertions.assertTrue(obj.getClass().isArray());
|
||||
Assertions.assertTrue(int.class == obj.getClass().getComponentType());
|
||||
for (int i = 0; i < len; i++) {
|
||||
Assert.assertEquals(i, Array.get(obj, i));
|
||||
Assertions.assertEquals(i, Array.get(obj, i));
|
||||
}
|
||||
|
||||
descriptor = new JavaBeanDescriptor(int[].class.getName(), JavaBeanDescriptor.TYPE_ARRAY);
|
||||
|
|
@ -223,14 +242,14 @@ public class JavaBeanSerializeUtilTest {
|
|||
descriptor.setProperty(i, innerItem);
|
||||
}
|
||||
obj = JavaBeanSerializeUtil.deserialize(descriptor);
|
||||
Assert.assertTrue(obj.getClass().isArray());
|
||||
Assert.assertEquals(int[].class, obj.getClass().getComponentType());
|
||||
Assertions.assertTrue(obj.getClass().isArray());
|
||||
Assertions.assertEquals(int[].class, obj.getClass().getComponentType());
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object innerItem = Array.get(obj, i);
|
||||
Assert.assertTrue(innerItem.getClass().isArray());
|
||||
Assert.assertEquals(int.class, innerItem.getClass().getComponentType());
|
||||
Assertions.assertTrue(innerItem.getClass().isArray());
|
||||
Assertions.assertEquals(int.class, innerItem.getClass().getComponentType());
|
||||
for (int j = 0; j < len; j++) {
|
||||
Assert.assertEquals(j, Array.get(innerItem, j));
|
||||
Assertions.assertEquals(j, Array.get(innerItem, j));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -240,18 +259,18 @@ public class JavaBeanSerializeUtilTest {
|
|||
descriptor.setProperty(0, innerDescriptor);
|
||||
|
||||
obj = JavaBeanSerializeUtil.deserialize(descriptor);
|
||||
Assert.assertTrue(obj.getClass().isArray());
|
||||
Assert.assertEquals(BigPerson[].class, obj.getClass().getComponentType());
|
||||
Assert.assertEquals(1, Array.getLength(obj));
|
||||
Assertions.assertTrue(obj.getClass().isArray());
|
||||
Assertions.assertEquals(BigPerson[].class, obj.getClass().getComponentType());
|
||||
Assertions.assertEquals(1, Array.getLength(obj));
|
||||
obj = Array.get(obj, 0);
|
||||
Assert.assertTrue(obj.getClass().isArray());
|
||||
Assert.assertEquals(BigPerson.class, obj.getClass().getComponentType());
|
||||
Assert.assertEquals(1, Array.getLength(obj));
|
||||
Assert.assertEquals(createBigPerson(), Array.get(obj, 0));
|
||||
Assertions.assertTrue(obj.getClass().isArray());
|
||||
Assertions.assertEquals(BigPerson.class, obj.getClass().getComponentType());
|
||||
Assertions.assertEquals(1, Array.getLength(obj));
|
||||
Assertions.assertEquals(createBigPerson(), Array.get(obj, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_Circular_Reference() throws Exception {
|
||||
public void test_Circular_Reference() {
|
||||
PojoUtilsTest.Parent parent = new PojoUtilsTest.Parent();
|
||||
parent.setAge(Integer.MAX_VALUE);
|
||||
parent.setEmail("a@b");
|
||||
|
|
@ -265,19 +284,19 @@ public class JavaBeanSerializeUtilTest {
|
|||
parent.setChild(child);
|
||||
|
||||
JavaBeanDescriptor descriptor = JavaBeanSerializeUtil.serialize(parent, JavaBeanAccessor.METHOD);
|
||||
Assert.assertTrue(descriptor.isBeanType());
|
||||
Assertions.assertTrue(descriptor.isBeanType());
|
||||
assertEqualsPrimitive(parent.getAge(), descriptor.getProperty("age"));
|
||||
assertEqualsPrimitive(parent.getName(), descriptor.getProperty("name"));
|
||||
assertEqualsPrimitive(parent.getEmail(), descriptor.getProperty("email"));
|
||||
|
||||
JavaBeanDescriptor childDescriptor = (JavaBeanDescriptor) descriptor.getProperty("child");
|
||||
Assert.assertTrue(descriptor == childDescriptor.getProperty("parent"));
|
||||
Assertions.assertTrue(descriptor == childDescriptor.getProperty("parent"));
|
||||
assertEqualsPrimitive(child.getName(), childDescriptor.getProperty("name"));
|
||||
assertEqualsPrimitive(child.getAge(), childDescriptor.getProperty("age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanSerialize() throws Exception {
|
||||
public void testBeanSerialize() {
|
||||
Bean bean = new Bean();
|
||||
bean.setDate(new Date());
|
||||
bean.setStatus(PersonStatus.ENABLED);
|
||||
|
|
@ -295,39 +314,39 @@ public class JavaBeanSerializeUtilTest {
|
|||
bean.setAddresses(map);
|
||||
|
||||
JavaBeanDescriptor descriptor = JavaBeanSerializeUtil.serialize(bean, JavaBeanAccessor.METHOD);
|
||||
Assert.assertTrue(descriptor.isBeanType());
|
||||
Assertions.assertTrue(descriptor.isBeanType());
|
||||
assertEqualsPrimitive(bean.getDate(), descriptor.getProperty("date"));
|
||||
assertEqualsEnum(bean.getStatus(), descriptor.getProperty("status"));
|
||||
Assert.assertTrue(((JavaBeanDescriptor) descriptor.getProperty("type")).isClassType());
|
||||
Assert.assertEquals(Bean.class.getName(), ((JavaBeanDescriptor) descriptor.getProperty("type")).getClassNameProperty());
|
||||
Assert.assertTrue(((JavaBeanDescriptor) descriptor.getProperty("array")).isArrayType());
|
||||
Assert.assertEquals(0, ((JavaBeanDescriptor) descriptor.getProperty("array")).propertySize());
|
||||
Assertions.assertTrue(((JavaBeanDescriptor) descriptor.getProperty("type")).isClassType());
|
||||
Assertions.assertEquals(Bean.class.getName(), ((JavaBeanDescriptor) descriptor.getProperty("type")).getClassNameProperty());
|
||||
Assertions.assertTrue(((JavaBeanDescriptor) descriptor.getProperty("array")).isArrayType());
|
||||
Assertions.assertEquals(0, ((JavaBeanDescriptor) descriptor.getProperty("array")).propertySize());
|
||||
|
||||
JavaBeanDescriptor property = (JavaBeanDescriptor) descriptor.getProperty("collection");
|
||||
Assert.assertTrue(property.isCollectionType());
|
||||
Assert.assertEquals(1, property.propertySize());
|
||||
Assertions.assertTrue(property.isCollectionType());
|
||||
Assertions.assertEquals(1, property.propertySize());
|
||||
property = (JavaBeanDescriptor) property.getProperty(0);
|
||||
Assert.assertTrue(property.isBeanType());
|
||||
Assert.assertEquals(Phone.class.getName(), property.getClassName());
|
||||
Assert.assertEquals(0, property.propertySize());
|
||||
Assertions.assertTrue(property.isBeanType());
|
||||
Assertions.assertEquals(Phone.class.getName(), property.getClassName());
|
||||
Assertions.assertEquals(0, property.propertySize());
|
||||
|
||||
property = (JavaBeanDescriptor) descriptor.getProperty("addresses");
|
||||
Assert.assertTrue(property.isMapType());
|
||||
Assert.assertEquals(bean.getAddresses().getClass().getName(), property.getClassName());
|
||||
Assert.assertEquals(1, property.propertySize());
|
||||
Assertions.assertTrue(property.isMapType());
|
||||
Assertions.assertEquals(bean.getAddresses().getClass().getName(), property.getClassName());
|
||||
Assertions.assertEquals(1, property.propertySize());
|
||||
|
||||
|
||||
Map.Entry<Object, Object> entry = property.iterator().next();
|
||||
Assert.assertTrue(((JavaBeanDescriptor) entry.getKey()).isPrimitiveType());
|
||||
Assert.assertEquals("first", ((JavaBeanDescriptor) entry.getKey()).getPrimitiveProperty());
|
||||
Assertions.assertTrue(((JavaBeanDescriptor) entry.getKey()).isPrimitiveType());
|
||||
Assertions.assertEquals("first", ((JavaBeanDescriptor) entry.getKey()).getPrimitiveProperty());
|
||||
|
||||
Assert.assertTrue(((JavaBeanDescriptor) entry.getValue()).isBeanType());
|
||||
Assert.assertEquals(FullAddress.class.getName(), ((JavaBeanDescriptor) entry.getValue()).getClassName());
|
||||
Assert.assertEquals(0, ((JavaBeanDescriptor) entry.getValue()).propertySize());
|
||||
Assertions.assertTrue(((JavaBeanDescriptor) entry.getValue()).isBeanType());
|
||||
Assertions.assertEquals(FullAddress.class.getName(), ((JavaBeanDescriptor) entry.getValue()).getClassName());
|
||||
Assertions.assertEquals(0, ((JavaBeanDescriptor) entry.getValue()).propertySize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeBean() throws Exception {
|
||||
public void testDeserializeBean() {
|
||||
Bean bean = new Bean();
|
||||
bean.setDate(new Date());
|
||||
bean.setStatus(PersonStatus.ENABLED);
|
||||
|
|
@ -346,45 +365,45 @@ public class JavaBeanSerializeUtilTest {
|
|||
|
||||
JavaBeanDescriptor beanDescriptor = JavaBeanSerializeUtil.serialize(bean, JavaBeanAccessor.METHOD);
|
||||
Object deser = JavaBeanSerializeUtil.deserialize(beanDescriptor);
|
||||
Assert.assertTrue(deser instanceof Bean);
|
||||
Assertions.assertTrue(deser instanceof Bean);
|
||||
Bean deserBean = (Bean) deser;
|
||||
Assert.assertEquals(bean.getDate(), deserBean.getDate());
|
||||
Assert.assertEquals(bean.getStatus(), deserBean.getStatus());
|
||||
Assert.assertEquals(bean.getType(), deserBean.getType());
|
||||
Assert.assertEquals(bean.getCollection().size(), deserBean.getCollection().size());
|
||||
Assert.assertEquals(bean.getCollection().iterator().next().getClass(),
|
||||
Assertions.assertEquals(bean.getDate(), deserBean.getDate());
|
||||
Assertions.assertEquals(bean.getStatus(), deserBean.getStatus());
|
||||
Assertions.assertEquals(bean.getType(), deserBean.getType());
|
||||
Assertions.assertEquals(bean.getCollection().size(), deserBean.getCollection().size());
|
||||
Assertions.assertEquals(bean.getCollection().iterator().next().getClass(),
|
||||
deserBean.getCollection().iterator().next().getClass());
|
||||
Assert.assertEquals(bean.getAddresses().size(), deserBean.getAddresses().size());
|
||||
Assert.assertEquals(bean.getAddresses().entrySet().iterator().next().getKey(),
|
||||
Assertions.assertEquals(bean.getAddresses().size(), deserBean.getAddresses().size());
|
||||
Assertions.assertEquals(bean.getAddresses().entrySet().iterator().next().getKey(),
|
||||
deserBean.getAddresses().entrySet().iterator().next().getKey());
|
||||
Assert.assertEquals(bean.getAddresses().entrySet().iterator().next().getValue().getClass(),
|
||||
Assertions.assertEquals(bean.getAddresses().entrySet().iterator().next().getValue().getClass(),
|
||||
deserBean.getAddresses().entrySet().iterator().next().getValue().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSerializeJavaBeanDescriptor() throws Exception {
|
||||
public void testSerializeJavaBeanDescriptor() {
|
||||
JavaBeanDescriptor descriptor = new JavaBeanDescriptor();
|
||||
JavaBeanDescriptor result = JavaBeanSerializeUtil.serialize(descriptor);
|
||||
Assert.assertTrue(descriptor == result);
|
||||
Assertions.assertTrue(descriptor == result);
|
||||
|
||||
Map map = new HashMap();
|
||||
map.put("first", descriptor);
|
||||
result = JavaBeanSerializeUtil.serialize(map);
|
||||
Assert.assertTrue(result.isMapType());
|
||||
Assert.assertEquals(HashMap.class.getName(), result.getClassName());
|
||||
Assert.assertEquals(map.size(), result.propertySize());
|
||||
Assertions.assertTrue(result.isMapType());
|
||||
Assertions.assertEquals(HashMap.class.getName(), result.getClassName());
|
||||
Assertions.assertEquals(map.size(), result.propertySize());
|
||||
Object object = result.iterator().next().getValue();
|
||||
Assert.assertTrue(object instanceof JavaBeanDescriptor);
|
||||
Assertions.assertTrue(object instanceof JavaBeanDescriptor);
|
||||
JavaBeanDescriptor actual = (JavaBeanDescriptor) object;
|
||||
Assert.assertEquals(map.get("first"), actual);
|
||||
Assertions.assertEquals(map.get("first"), actual);
|
||||
}
|
||||
|
||||
static void assertEqualsEnum(Enum<?> expected, Object obj) {
|
||||
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) obj;
|
||||
Assert.assertTrue(descriptor.isEnumType());
|
||||
Assert.assertEquals(expected.getClass().getName(), descriptor.getClassName());
|
||||
Assert.assertEquals(expected.name(), descriptor.getEnumPropertyName());
|
||||
Assertions.assertTrue(descriptor.isEnumType());
|
||||
Assertions.assertEquals(expected.getClass().getName(), descriptor.getClassName());
|
||||
Assertions.assertEquals(expected.name(), descriptor.getEnumPropertyName());
|
||||
}
|
||||
|
||||
static void assertEqualsPrimitive(Object expected, Object obj) {
|
||||
|
|
@ -392,13 +411,13 @@ public class JavaBeanSerializeUtilTest {
|
|||
return;
|
||||
}
|
||||
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) obj;
|
||||
Assert.assertTrue(descriptor.isPrimitiveType());
|
||||
Assert.assertEquals(expected, descriptor.getPrimitiveProperty());
|
||||
Assertions.assertTrue(descriptor.isPrimitiveType());
|
||||
Assertions.assertEquals(expected, descriptor.getPrimitiveProperty());
|
||||
}
|
||||
|
||||
static void assertEqualsBigPerson(BigPerson person, Object obj) {
|
||||
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) obj;
|
||||
Assert.assertTrue(descriptor.isBeanType());
|
||||
Assertions.assertTrue(descriptor.isBeanType());
|
||||
assertEqualsPrimitive(person.getPersonId(), descriptor.getProperty("personId"));
|
||||
assertEqualsPrimitive(person.getLoginName(), descriptor.getProperty("loginName"));
|
||||
assertEqualsEnum(person.getStatus(), descriptor.getProperty("status"));
|
||||
|
|
@ -406,9 +425,9 @@ public class JavaBeanSerializeUtilTest {
|
|||
assertEqualsPrimitive(person.getPenName(), descriptor.getProperty("penName"));
|
||||
|
||||
JavaBeanDescriptor infoProfile = (JavaBeanDescriptor) descriptor.getProperty("infoProfile");
|
||||
Assert.assertTrue(infoProfile.isBeanType());
|
||||
Assertions.assertTrue(infoProfile.isBeanType());
|
||||
JavaBeanDescriptor phones = (JavaBeanDescriptor) infoProfile.getProperty("phones");
|
||||
Assert.assertTrue(phones.isCollectionType());
|
||||
Assertions.assertTrue(phones.isCollectionType());
|
||||
assertEqualsPhone(person.getInfoProfile().getPhones().get(0), phones.getProperty(0));
|
||||
assertEqualsPhone(person.getInfoProfile().getPhones().get(1), phones.getProperty(1));
|
||||
assertEqualsPhone(person.getInfoProfile().getFax(), infoProfile.getProperty("fax"));
|
||||
|
|
@ -424,7 +443,7 @@ public class JavaBeanSerializeUtilTest {
|
|||
|
||||
static void assertEqualsPhone(Phone excpected, Object obj) {
|
||||
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) obj;
|
||||
Assert.assertTrue(descriptor.isBeanType());
|
||||
Assertions.assertTrue(descriptor.isBeanType());
|
||||
if (excpected.getArea() != null) {
|
||||
assertEqualsPrimitive(excpected.getArea(), descriptor.getProperty("area"));
|
||||
}
|
||||
|
|
@ -441,7 +460,7 @@ public class JavaBeanSerializeUtilTest {
|
|||
|
||||
static void assertEqualsFullAddress(FullAddress expected, Object obj) {
|
||||
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) obj;
|
||||
Assert.assertTrue(descriptor.isBeanType());
|
||||
Assertions.assertTrue(descriptor.isBeanType());
|
||||
if (expected.getCityId() != null) {
|
||||
assertEqualsPrimitive(expected.getCityId(), descriptor.getProperty("cityId"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.bytecode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
|
@ -28,7 +27,7 @@ interface Builder<T> {
|
|||
void setName(Bean bean, T name);
|
||||
}
|
||||
|
||||
public class ClassGeneratorTest extends TestCase {
|
||||
public class ClassGeneratorTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.bytecode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MixinTest extends TestCase {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class MixinTest {
|
||||
|
||||
@Test
|
||||
public void testMain() throws Exception {
|
||||
|
|
|
|||
|
|
@ -16,32 +16,28 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.bytecode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ProxyTest extends TestCase {
|
||||
public class ProxyTest {
|
||||
|
||||
@Test
|
||||
public void testMain() throws Exception {
|
||||
Proxy proxy = Proxy.getProxy(ITest.class, ITest.class);
|
||||
ITest instance = (ITest) proxy.newInstance(new InvocationHandler() {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if ("getName".equals(method.getName())) {
|
||||
assertEquals(args.length, 0);
|
||||
} else if ("setName".equals(method.getName())) {
|
||||
assertEquals(args.length, 2);
|
||||
assertEquals(args[0], "qianlei");
|
||||
assertEquals(args[1], "hello");
|
||||
}
|
||||
return null;
|
||||
ITest instance = (ITest) proxy.newInstance((proxy1, method, args) -> {
|
||||
if ("getName".equals(method.getName())) {
|
||||
assertEquals(args.length, 0);
|
||||
} else if ("setName".equals(method.getName())) {
|
||||
assertEquals(args.length, 2);
|
||||
assertEquals(args[0], "qianlei");
|
||||
assertEquals(args[1], "hello");
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
assertNull(instance.getName());
|
||||
|
|
@ -50,27 +46,19 @@ public class ProxyTest extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testCglibProxy() throws Exception {
|
||||
ITest test = (ITest) Proxy.getProxy(ITest.class).newInstance(new InvocationHandler() {
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
System.out.println(method.getName());
|
||||
return null;
|
||||
}
|
||||
ITest test = (ITest) Proxy.getProxy(ITest.class).newInstance((proxy, method, args) -> {
|
||||
System.out.println(method.getName());
|
||||
return null;
|
||||
});
|
||||
|
||||
Enhancer enhancer = new Enhancer();
|
||||
enhancer.setSuperclass(test.getClass());
|
||||
enhancer.setCallback(new MethodInterceptor() {
|
||||
|
||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> null);
|
||||
try {
|
||||
enhancer.create();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.bytecode;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class WrapperTest {
|
||||
@Test
|
||||
|
|
@ -63,48 +63,54 @@ public class WrapperTest {
|
|||
@Test
|
||||
public void testHasMethod() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(I1.class);
|
||||
Assert.assertTrue(w.hasMethod("setName"));
|
||||
Assert.assertTrue(w.hasMethod("hello"));
|
||||
Assert.assertTrue(w.hasMethod("showInt"));
|
||||
Assert.assertTrue(w.hasMethod("getFloat"));
|
||||
Assert.assertTrue(w.hasMethod("setFloat"));
|
||||
Assert.assertFalse(w.hasMethod("setFloatXXX"));
|
||||
Assertions.assertTrue(w.hasMethod("setName"));
|
||||
Assertions.assertTrue(w.hasMethod("hello"));
|
||||
Assertions.assertTrue(w.hasMethod("showInt"));
|
||||
Assertions.assertTrue(w.hasMethod("getFloat"));
|
||||
Assertions.assertTrue(w.hasMethod("setFloat"));
|
||||
Assertions.assertFalse(w.hasMethod("setFloatXXX"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapperObject() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
Assert.assertTrue(w.getMethodNames().length == 4);
|
||||
Assert.assertTrue(w.getPropertyNames().length == 0);
|
||||
Assert.assertEquals(null, w.getPropertyType(null));
|
||||
Assertions.assertTrue(w.getMethodNames().length == 4);
|
||||
Assertions.assertTrue(w.getPropertyNames().length == 0);
|
||||
Assertions.assertEquals(null, w.getPropertyType(null));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchPropertyException.class)
|
||||
@Test
|
||||
public void testGetPropertyValue() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.getPropertyValue(null, null);
|
||||
Assertions.assertThrows(NoSuchPropertyException.class, () -> {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.getPropertyValue(null, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchPropertyException.class)
|
||||
@Test
|
||||
public void testSetPropertyValue() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.setPropertyValue(null, null, null);
|
||||
Assertions.assertThrows(NoSuchPropertyException.class, () -> {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.setPropertyValue(null, null, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWrapperObject() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
Object instance = new Object();
|
||||
Assert.assertEquals(instance.getClass(), (Class<?>) w.invokeMethod(instance, "getClass", null, null));
|
||||
Assert.assertEquals(instance.hashCode(), (int) w.invokeMethod(instance, "hashCode", null, null));
|
||||
Assert.assertEquals(instance.toString(), (String) w.invokeMethod(instance, "toString", null, null));
|
||||
Assert.assertEquals(true, (boolean) w.invokeMethod(instance, "equals", null, new Object[]{instance}));
|
||||
Assertions.assertEquals(instance.getClass(), (Class<?>) w.invokeMethod(instance, "getClass", null, null));
|
||||
Assertions.assertEquals(instance.hashCode(), (int) w.invokeMethod(instance, "hashCode", null, null));
|
||||
Assertions.assertEquals(instance.toString(), (String) w.invokeMethod(instance, "toString", null, null));
|
||||
Assertions.assertEquals(true, (boolean) w.invokeMethod(instance, "equals", null, new Object[]{instance}));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchMethodException.class)
|
||||
@Test
|
||||
public void testNoSuchMethod() throws Exception {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.invokeMethod(new Object(), "__XX__", null, null);
|
||||
Assertions.assertThrows(NoSuchMethodException.class, () -> {
|
||||
Wrapper w = Wrapper.getWrapper(Object.class);
|
||||
w.invokeMethod(new Object(), "__XX__", null, null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.compiler.support;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AdaptiveCompilerTest extends JavaCodeTest {
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ public class AdaptiveCompilerTest extends JavaCodeTest {
|
|||
AdaptiveCompiler compiler = new AdaptiveCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCode(), AdaptiveCompiler.class.getClassLoader());
|
||||
HelloService helloService = (HelloService) clazz.newInstance();
|
||||
Assert.assertEquals("Hello world!", helloService.sayHello());
|
||||
Assertions.assertEquals("Hello world!", helloService.sayHello());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,10 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.compiler.support;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -33,22 +32,22 @@ public class ClassUtilsTest {
|
|||
@Test
|
||||
public void testNewInstance() {
|
||||
HelloServiceImpl0 instance = (HelloServiceImpl0) ClassUtils.newInstance(HelloServiceImpl0.class.getName());
|
||||
Assert.assertEquals("Hello world!", instance.sayHello());
|
||||
Assertions.assertEquals("Hello world!", instance.sayHello());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testNewInstance0() {
|
||||
ClassUtils.newInstance(PrivateHelloServiceImpl.class.getName());
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance(PrivateHelloServiceImpl.class.getName()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testNewInstance1() {
|
||||
ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.HelloServiceInternalImpl");
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.HelloServiceInternalImpl"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testNewInstance2() {
|
||||
ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.NotExistsImpl");
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.NotExistsImpl"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -56,9 +55,9 @@ public class ClassUtilsTest {
|
|||
ClassUtils.forName(new String[]{"org.apache.dubbo.common.compiler.support"}, "HelloServiceImpl0");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testForName1() {
|
||||
ClassUtils.forName(new String[]{"org.apache.dubbo.common.compiler.support"}, "HelloServiceImplXX");
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.forName(new String[]{"org.apache.dubbo.common.compiler.support"}, "HelloServiceImplXX"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -83,86 +82,88 @@ public class ClassUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testGetBoxedClass() {
|
||||
Assert.assertEquals(Boolean.class, ClassUtils.getBoxedClass(boolean.class));
|
||||
Assert.assertEquals(Character.class, ClassUtils.getBoxedClass(char.class));
|
||||
Assert.assertEquals(Byte.class, ClassUtils.getBoxedClass(byte.class));
|
||||
Assert.assertEquals(Short.class, ClassUtils.getBoxedClass(short.class));
|
||||
Assert.assertEquals(Integer.class, ClassUtils.getBoxedClass(int.class));
|
||||
Assert.assertEquals(Long.class, ClassUtils.getBoxedClass(long.class));
|
||||
Assert.assertEquals(Float.class, ClassUtils.getBoxedClass(float.class));
|
||||
Assert.assertEquals(Double.class, ClassUtils.getBoxedClass(double.class));
|
||||
Assert.assertEquals(ClassUtilsTest.class, ClassUtils.getBoxedClass(ClassUtilsTest.class));
|
||||
Assertions.assertEquals(Boolean.class, ClassUtils.getBoxedClass(boolean.class));
|
||||
Assertions.assertEquals(Character.class, ClassUtils.getBoxedClass(char.class));
|
||||
Assertions.assertEquals(Byte.class, ClassUtils.getBoxedClass(byte.class));
|
||||
Assertions.assertEquals(Short.class, ClassUtils.getBoxedClass(short.class));
|
||||
Assertions.assertEquals(Integer.class, ClassUtils.getBoxedClass(int.class));
|
||||
Assertions.assertEquals(Long.class, ClassUtils.getBoxedClass(long.class));
|
||||
Assertions.assertEquals(Float.class, ClassUtils.getBoxedClass(float.class));
|
||||
Assertions.assertEquals(Double.class, ClassUtils.getBoxedClass(double.class));
|
||||
Assertions.assertEquals(ClassUtilsTest.class, ClassUtils.getBoxedClass(ClassUtilsTest.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoxedAndUnboxed() {
|
||||
Assert.assertEquals(Boolean.valueOf(true), ClassUtils.boxed(true));
|
||||
Assert.assertEquals(Character.valueOf('0'), ClassUtils.boxed('0'));
|
||||
Assert.assertEquals(Byte.valueOf((byte) 0), ClassUtils.boxed((byte) 0));
|
||||
Assert.assertEquals(Short.valueOf((short) 0), ClassUtils.boxed((short) 0));
|
||||
Assert.assertEquals(Integer.valueOf((int) 0), ClassUtils.boxed((int) 0));
|
||||
Assert.assertEquals(Long.valueOf((long) 0), ClassUtils.boxed((long) 0));
|
||||
Assert.assertEquals(Float.valueOf((float) 0), ClassUtils.boxed((float) 0));
|
||||
Assert.assertEquals(Double.valueOf((double) 0), ClassUtils.boxed((double) 0));
|
||||
Assertions.assertEquals(Boolean.valueOf(true), ClassUtils.boxed(true));
|
||||
Assertions.assertEquals(Character.valueOf('0'), ClassUtils.boxed('0'));
|
||||
Assertions.assertEquals(Byte.valueOf((byte) 0), ClassUtils.boxed((byte) 0));
|
||||
Assertions.assertEquals(Short.valueOf((short) 0), ClassUtils.boxed((short) 0));
|
||||
Assertions.assertEquals(Integer.valueOf((int) 0), ClassUtils.boxed((int) 0));
|
||||
Assertions.assertEquals(Long.valueOf((long) 0), ClassUtils.boxed((long) 0));
|
||||
Assertions.assertEquals(Float.valueOf((float) 0), ClassUtils.boxed((float) 0));
|
||||
Assertions.assertEquals(Double.valueOf((double) 0), ClassUtils.boxed((double) 0));
|
||||
|
||||
Assert.assertEquals(true, ClassUtils.unboxed(Boolean.valueOf(true)));
|
||||
Assert.assertEquals('0', ClassUtils.unboxed(Character.valueOf('0')));
|
||||
Assert.assertEquals((byte) 0, ClassUtils.unboxed(Byte.valueOf((byte) 0)));
|
||||
Assert.assertEquals((short) 0, ClassUtils.unboxed(Short.valueOf((short) 0)));
|
||||
Assert.assertEquals(0, ClassUtils.unboxed(Integer.valueOf((int) 0)));
|
||||
Assert.assertEquals((long) 0, ClassUtils.unboxed(Long.valueOf((long) 0)));
|
||||
Assert.assertEquals((float) 0, ClassUtils.unboxed(Float.valueOf((float) 0)), ((float)0));
|
||||
Assert.assertEquals((double) 0, ClassUtils.unboxed(Double.valueOf((double) 0)), ((double)0));
|
||||
Assertions.assertEquals(true, ClassUtils.unboxed(Boolean.valueOf(true)));
|
||||
Assertions.assertEquals('0', ClassUtils.unboxed(Character.valueOf('0')));
|
||||
Assertions.assertEquals((byte) 0, ClassUtils.unboxed(Byte.valueOf((byte) 0)));
|
||||
Assertions.assertEquals((short) 0, ClassUtils.unboxed(Short.valueOf((short) 0)));
|
||||
Assertions.assertEquals(0, ClassUtils.unboxed(Integer.valueOf((int) 0)));
|
||||
Assertions.assertEquals((long) 0, ClassUtils.unboxed(Long.valueOf((long) 0)));
|
||||
// Assertions.assertEquals((float) 0, ClassUtils.unboxed(Float.valueOf((float) 0)), ((float) 0));
|
||||
// Assertions.assertEquals((double) 0, ClassUtils.unboxed(Double.valueOf((double) 0)), ((double) 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSize(){
|
||||
Assert.assertEquals(0, ClassUtils.getSize(null));
|
||||
List<Integer> list = new ArrayList<>();list.add(1);
|
||||
Assert.assertEquals(1, ClassUtils.getSize(list));
|
||||
Map map = new HashMap(); map.put(1, 1);
|
||||
Assert.assertEquals(1, ClassUtils.getSize(map));
|
||||
public void testGetSize() {
|
||||
Assertions.assertEquals(0, ClassUtils.getSize(null));
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.add(1);
|
||||
Assertions.assertEquals(1, ClassUtils.getSize(list));
|
||||
Map map = new HashMap();
|
||||
map.put(1, 1);
|
||||
Assertions.assertEquals(1, ClassUtils.getSize(map));
|
||||
int[] array = new int[1];
|
||||
Assert.assertEquals(1, ClassUtils.getSize(array));
|
||||
Assert.assertEquals(-1, ClassUtils.getSize(new Object()));
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testToUri(){
|
||||
ClassUtils.toURI("#xx_abc#hello");
|
||||
Assertions.assertEquals(1, ClassUtils.getSize(array));
|
||||
Assertions.assertEquals(-1, ClassUtils.getSize(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGenericClass(){
|
||||
Assert.assertTrue(TypeVariable.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass.class)));
|
||||
Assert.assertTrue(String.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass0.class)));
|
||||
Assert.assertTrue(Collection.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass1.class)));
|
||||
Assert.assertTrue(TypeVariable.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass2.class)));
|
||||
Assert.assertTrue(GenericArrayType.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass3.class)));
|
||||
public void testToUri() {
|
||||
Assertions.assertThrows(RuntimeException.class, () -> ClassUtils.toURI("#xx_abc#hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSizeMethod(){
|
||||
Assert.assertEquals("getLength()", ClassUtils.getSizeMethod(GenericClass3.class));
|
||||
public void testGetGenericClass() {
|
||||
Assertions.assertTrue(TypeVariable.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass.class)));
|
||||
Assertions.assertTrue(String.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass0.class)));
|
||||
Assertions.assertTrue(Collection.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass1.class)));
|
||||
Assertions.assertTrue(TypeVariable.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass2.class)));
|
||||
Assertions.assertTrue(GenericArrayType.class.isAssignableFrom(ClassUtils.getGenericClass(GenericClass3.class)));
|
||||
}
|
||||
|
||||
private interface GenericInterface<T>{
|
||||
@Test
|
||||
public void testGetSizeMethod() {
|
||||
Assertions.assertEquals("getLength()", ClassUtils.getSizeMethod(GenericClass3.class));
|
||||
}
|
||||
|
||||
private class GenericClass<T> implements GenericInterface<T>{
|
||||
private interface GenericInterface<T> {
|
||||
}
|
||||
|
||||
private class GenericClass0 implements GenericInterface<String>{
|
||||
private class GenericClass<T> implements GenericInterface<T> {
|
||||
}
|
||||
|
||||
private class GenericClass1 implements GenericInterface<Collection<String>>{
|
||||
private class GenericClass0 implements GenericInterface<String> {
|
||||
}
|
||||
|
||||
private class GenericClass2<T> implements GenericInterface<T[]>{
|
||||
private class GenericClass1 implements GenericInterface<Collection<String>> {
|
||||
}
|
||||
|
||||
private class GenericClass3<T> implements GenericInterface<T[][]>{
|
||||
public int getLength(){
|
||||
private class GenericClass2<T> implements GenericInterface<T[]> {
|
||||
}
|
||||
|
||||
private class GenericClass3<T> implements GenericInterface<T[][]> {
|
||||
public int getLength() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.compiler.support;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ public class JavassistCompilerTest extends JavaCodeTest {
|
|||
// Because javassist compiles using the caller class loader, we should't use HelloService directly
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,16 +42,18 @@ public class JavassistCompilerTest extends JavaCodeTest {
|
|||
Class<?> clazz = compiler.compile(getSimpleCodeWithoutPackage(), JavassistCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testCompileJavaClass1() throws Exception {
|
||||
JavassistCompiler compiler = new JavassistCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithSyntax0(), JavassistCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JavassistCompiler compiler = new JavassistCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithSyntax0(), JavassistCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -60,7 +62,7 @@ public class JavassistCompilerTest extends JavaCodeTest {
|
|||
Class<?> clazz = compiler.compile(getSimpleCodeWithImports(), JavassistCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -69,6 +71,6 @@ public class JavassistCompilerTest extends JavaCodeTest {
|
|||
Class<?> clazz = compiler.compile(getSimpleCodeWithWithExtends(), JavassistCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world3!", sayHello.invoke(instance));
|
||||
Assertions.assertEquals("Hello world3!", sayHello.invoke(instance));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.compiler.support;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class JdkCompilerTest extends JavaCodeTest{
|
||||
public class JdkCompilerTest extends JavaCodeTest {
|
||||
|
||||
@Test
|
||||
public void test_compileJavaClass() throws Exception {
|
||||
|
|
@ -29,24 +29,28 @@ public class JdkCompilerTest extends JavaCodeTest{
|
|||
Class<?> clazz = compiler.compile(getSimpleCode(), JdkCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void test_compileJavaClass0() throws Exception {
|
||||
JdkCompiler compiler = new JdkCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithoutPackage(), JdkCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JdkCompiler compiler = new JdkCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithoutPackage(), JdkCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void test_compileJavaClass1() throws Exception {
|
||||
JdkCompiler compiler = new JdkCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithSyntax(), JdkCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assert.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
JdkCompiler compiler = new JdkCompiler();
|
||||
Class<?> clazz = compiler.compile(getSimpleCodeWithSyntax(), JdkCompiler.class.getClassLoader());
|
||||
Object instance = clazz.newInstance();
|
||||
Method sayHello = instance.getClass().getMethod("sayHello");
|
||||
Assertions.assertEquals("Hello world!", sayHello.invoke(instance));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.dubbo.common.concurrent;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
|
@ -33,7 +33,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class CompletableFutureTaskTest {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.concurrent;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
|
|
@ -31,14 +32,14 @@ import static org.mockito.Mockito.verify;
|
|||
public class ExecutionListTest {
|
||||
private ExecutionList executionList;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.executionList = new ExecutionList();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testAddNullRunnable() {
|
||||
this.executionList.add(null, mock(Executor.class));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> this.executionList.add(null, mock(Executor.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -49,8 +49,9 @@ import org.apache.dubbo.common.extension.ext9_empty.Ext9Empty;
|
|||
import org.apache.dubbo.common.extension.ext9_empty.impl.Ext9EmptyImpl;
|
||||
import org.apache.dubbo.common.extension.injection.InjectExt;
|
||||
import org.apache.dubbo.common.extension.injection.impl.InjectExtImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -59,13 +60,13 @@ import java.util.Set;
|
|||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ExtensionLoaderTest {
|
||||
@Test
|
||||
|
|
@ -371,22 +372,22 @@ public class ExtensionLoaderTest {
|
|||
URL url = URL.valueOf("test://localhost/test");
|
||||
List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "default_group");
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
|
||||
Assertions.assertEquals(1, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
|
||||
|
||||
// test group
|
||||
url = url.addParameter(Constants.GROUP_KEY, "group1");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "group1");
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class);
|
||||
Assertions.assertEquals(1, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class);
|
||||
|
||||
// test old @Activate group
|
||||
url = url.addParameter(Constants.GROUP_KEY, "old_group");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "old_group");
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == OldActivateExt1Impl2.class
|
||||
Assertions.assertEquals(2, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == OldActivateExt1Impl2.class
|
||||
|| list.get(0).getClass() == OldActivateExt1Impl3.class);
|
||||
|
||||
// test value
|
||||
|
|
@ -395,17 +396,17 @@ public class ExtensionLoaderTest {
|
|||
url = url.addParameter("value", "value");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "value");
|
||||
Assert.assertEquals(1, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == ValueActivateExtImpl.class);
|
||||
Assertions.assertEquals(1, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == ValueActivateExtImpl.class);
|
||||
|
||||
// test order
|
||||
url = URL.valueOf("test://localhost/test");
|
||||
url = url.addParameter(Constants.GROUP_KEY, "order");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "order");
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
|
||||
Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl2.class);
|
||||
Assertions.assertEquals(2, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
|
||||
Assertions.assertTrue(list.get(1).getClass() == OrderActivateExtImpl2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -414,16 +415,16 @@ public class ExtensionLoaderTest {
|
|||
URL url = URL.valueOf("test://localhost/test?ext=order1,default");
|
||||
List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, "ext", "default_group");
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
|
||||
Assert.assertTrue(list.get(1).getClass() == ActivateExt1Impl1.class);
|
||||
Assertions.assertEquals(2, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
|
||||
Assertions.assertTrue(list.get(1).getClass() == ActivateExt1Impl1.class);
|
||||
|
||||
url = URL.valueOf("test://localhost/test?ext=default,order1");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, "ext", "default_group");
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
|
||||
Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl1.class);
|
||||
Assertions.assertEquals(2, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
|
||||
Assertions.assertTrue(list.get(1).getClass() == OrderActivateExtImpl1.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -431,9 +432,9 @@ public class ExtensionLoaderTest {
|
|||
// test default
|
||||
InjectExt injectExt = ExtensionLoader.getExtensionLoader(InjectExt.class).getExtension("injection");
|
||||
InjectExtImpl injectExtImpl = (InjectExtImpl) injectExt;
|
||||
Assert.assertNotNull(injectExtImpl.getSimpleExt());
|
||||
Assert.assertNull(injectExtImpl.getSimpleExt1());
|
||||
Assert.assertNull(injectExtImpl.getGenericType());
|
||||
Assertions.assertNotNull(injectExtImpl.getSimpleExt());
|
||||
Assertions.assertNull(injectExtImpl.getSimpleExt1());
|
||||
Assertions.assertNull(injectExtImpl.getGenericType());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,19 +29,19 @@ import org.apache.dubbo.common.extension.ext6_inject.Ext6;
|
|||
import org.apache.dubbo.common.extension.ext6_inject.impl.Ext6Impl2;
|
||||
import org.apache.dubbo.common.utils.LogUtil;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ExtensionLoader_Adaptive_Test {
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ public class ExtensionLoader_Adaptive_Test {
|
|||
|
||||
assertEquals("Ext6Impl1-echo-Ext1Impl1-echo", ext.echo(url, "ha"));
|
||||
|
||||
Assert.assertTrue("can not find error.", LogUtil.checkNoError());
|
||||
Assertions.assertTrue(LogUtil.checkNoError(), "can not find error.");
|
||||
LogUtil.stop();
|
||||
|
||||
url = url.addParameters("simple.ext", "impl2");
|
||||
|
|
|
|||
|
|
@ -18,16 +18,16 @@ package org.apache.dubbo.common.extension;
|
|||
|
||||
import org.apache.dubbo.common.compiler.support.AdaptiveCompiler;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public class ExtensionLoader_Adaptive_UseJdkCompiler_Test extends ExtensionLoader_Adaptive_Test {
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
AdaptiveCompiler.setDefaultCompiler("jdk");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void tearDown() throws Exception {
|
||||
AdaptiveCompiler.setDefaultCompiler("javassist");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ import org.apache.dubbo.common.extension.compatible.CompatibleExt;
|
|||
import org.apache.dubbo.common.extension.compatible.impl.CompatibleExtImpl1;
|
||||
import org.apache.dubbo.common.extension.compatible.impl.CompatibleExtImpl2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ExtensionLoader_Compatible_Test {
|
||||
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ import org.apache.dubbo.common.extension.ext1.SimpleExt;
|
|||
import org.apache.dubbo.common.extension.ext6_inject.Dao;
|
||||
import org.apache.dubbo.common.extension.ext6_inject.Ext6;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
public class Ext6Impl1 implements Ext6 {
|
||||
public Dao obj;
|
||||
SimpleExt ext1;
|
||||
|
||||
public void setDao(Dao obj) {
|
||||
Assert.assertNotNull("inject extension instance can not be null", obj);
|
||||
Assert.fail();
|
||||
Assertions.assertNotNull(obj, "inject extension instance can not be null");
|
||||
Assertions.fail();
|
||||
}
|
||||
|
||||
public void setExt1(SimpleExt ext1) {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package org.apache.dubbo.common.extension.support;
|
||||
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -42,10 +42,10 @@ public class ActivateComparatorTest {
|
|||
|
||||
Collections.sort(filters, ActivateComparator.COMPARATOR);
|
||||
|
||||
Assert.assertEquals(f4, filters.get(0));
|
||||
Assert.assertEquals(f5, filters.get(1));
|
||||
Assert.assertEquals(f3, filters.get(2));
|
||||
Assert.assertEquals(f2, filters.get(3));
|
||||
Assert.assertEquals(f1, filters.get(4));
|
||||
Assertions.assertEquals(f4, filters.get(0));
|
||||
Assertions.assertEquals(f5, filters.get(1));
|
||||
Assertions.assertEquals(f3, filters.get(2));
|
||||
Assertions.assertEquals(f2, filters.get(3));
|
||||
Assertions.assertEquals(f1, filters.get(4));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class BytesTest {
|
||||
private final byte[] b1 = "adpfioha;eoh;aldfadl;kfadslkfdajfio123431241235123davas;odvwe;lmzcoqpwoewqogineopwqihwqetup\n\tejqf;lajsfd中文字符0da0gsaofdsf==adfasdfs".getBytes();
|
||||
|
|
@ -58,24 +59,24 @@ public class BytesTest {
|
|||
assertThat(bytesWithC64, is(bytes));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWrongBase64Code() {
|
||||
Bytes.bytes2base64("dubbo".getBytes(), 0, 1, new char[]{'a'});
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Bytes.bytes2base64("dubbo".getBytes(), 0, 1, new char[]{'a'}));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWrongOffSet() {
|
||||
Bytes.bytes2base64("dubbo".getBytes(), -1, 1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> Bytes.bytes2base64("dubbo".getBytes(), -1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testLargeLength() {
|
||||
Bytes.bytes2base64("dubbo".getBytes(), 0, 100000);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> Bytes.bytes2base64("dubbo".getBytes(), 0, 100000));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testSmallLength() {
|
||||
Bytes.bytes2base64("dubbo".getBytes(), 0, -1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> Bytes.bytes2base64("dubbo".getBytes(), 0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -115,14 +116,14 @@ public class BytesTest {
|
|||
assertThat(unzip, is(s.getBytes()));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testBytes2HexWithWrongOffset() {
|
||||
Bytes.bytes2hex("hello".getBytes(), -1, 1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> Bytes.bytes2hex("hello".getBytes(), -1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testBytes2HexWithWrongLength() {
|
||||
Bytes.bytes2hex("hello".getBytes(), 0, 6);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> Bytes.bytes2hex("hello".getBytes(), 0, 6));
|
||||
}
|
||||
|
||||
private byte[] int2bytes(int x) {
|
||||
|
|
|
|||
|
|
@ -16,16 +16,17 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class StreamUtilsTest {
|
||||
|
||||
|
|
@ -117,23 +118,25 @@ public class StreamUtilsTest {
|
|||
is.close();
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void testMarkInputSupport() throws IOException {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.markSupportedInputStream(new PushbackInputStream(is), 1);
|
||||
@Test
|
||||
public void testMarkInputSupport() {
|
||||
Assertions.assertThrows(IOException.class, () -> {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.markSupportedInputStream(new PushbackInputStream(is), 1);
|
||||
|
||||
is.mark(1);
|
||||
int read = is.read();
|
||||
assertThat(read, is((int) '0'));
|
||||
is.mark(1);
|
||||
int read = is.read();
|
||||
assertThat(read, is((int) '0'));
|
||||
|
||||
is.skip(1);
|
||||
is.read();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
is.skip(1);
|
||||
is.read();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -145,29 +148,33 @@ public class StreamUtilsTest {
|
|||
is.close();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testReadEmptyByteArray() throws IOException {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.limitedInputStream(is, 2);
|
||||
is.read(null, 0, 1);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
@Test
|
||||
public void testReadEmptyByteArray() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.limitedInputStream(is, 2);
|
||||
is.read(null, 0, 1);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testReadWithWrongOffset() throws IOException {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.limitedInputStream(is, 2);
|
||||
is.read(new byte[1], -1, 1);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
@Test
|
||||
public void testReadWithWrongOffset() {
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
InputStream is = StreamUtilsTest.class.getResourceAsStream("/StreamUtilsTest.txt");
|
||||
try {
|
||||
is = StreamUtils.limitedInputStream(is, 2);
|
||||
is.read(new byte[1], -1, 1);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class UnsafeByteArrayInputStreamTest {
|
||||
@Test
|
||||
|
|
@ -58,22 +59,28 @@ public class UnsafeByteArrayInputStreamTest {
|
|||
assertThat(stream.read(), is((int) 'b'));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWrongLength() {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(new byte[1], 0, 100);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(new byte[1], 0, 100);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWrongOffset() {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(new byte[1], -1, 1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(new byte[1], -1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void testReadEmptyByteArray() {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(null, 0, 1);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
UnsafeByteArrayInputStream stream = new UnsafeByteArrayInputStream("abc".getBytes());
|
||||
stream.read(null, 0, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -24,16 +25,16 @@ import java.io.OutputStream;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class UnsafeByteArrayOutputStreamTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testWrongSize() {
|
||||
new UnsafeByteArrayOutputStream(-1);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new UnsafeByteArrayOutputStream(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class UnsafeStringReaderTest {
|
||||
@Test
|
||||
|
|
@ -63,10 +64,12 @@ public class UnsafeStringReaderTest {
|
|||
assertThat(skip, is(0L));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWrongLength() throws IOException {
|
||||
UnsafeStringReader reader = new UnsafeStringReader("abc");
|
||||
char[] chars = new char[1];
|
||||
reader.read(chars, 0, 2);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
UnsafeStringReader reader = new UnsafeStringReader("abc");
|
||||
char[] chars = new char[1];
|
||||
reader.read(chars, 0, 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class UnsafeStringWriterTest {
|
||||
@Test
|
||||
|
|
@ -36,9 +37,11 @@ public class UnsafeStringWriterTest {
|
|||
assertThat(writer.toString(), is("abc"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNegativeSize() {
|
||||
new UnsafeStringWriter(-1);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
new UnsafeStringWriter(-1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,17 +81,21 @@ public class UnsafeStringWriterTest {
|
|||
assertThat(writer.toString(), is("aba"));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWriteCharWithWrongLength() throws IOException {
|
||||
UnsafeStringWriter writer = new UnsafeStringWriter();
|
||||
char[] chars = new char[0];
|
||||
writer.write(chars, 0, 1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
UnsafeStringWriter writer = new UnsafeStringWriter();
|
||||
char[] chars = new char[0];
|
||||
writer.write(chars, 0, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testWriteCharWithWrongCombineLength() throws IOException {
|
||||
UnsafeStringWriter writer = new UnsafeStringWriter();
|
||||
char[] chars = new char[1];
|
||||
writer.write(chars, 1, 1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
UnsafeStringWriter writer = new UnsafeStringWriter();
|
||||
char[] chars = new char[1];
|
||||
writer.write(chars, 1, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package org.apache.dubbo.common.json;
|
|||
|
||||
import org.apache.dubbo.common.io.UnsafeStringReader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class JSONReaderTest extends TestCase {
|
||||
public class JSONReaderTest {
|
||||
public void testMain() throws Exception {
|
||||
String json = "{ name: 'name', friends: [ 1, null, 3.2, ] }";
|
||||
JSONReader reader = new JSONReader(new UnsafeStringReader(json));
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
|
@ -27,7 +27,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Deprecated
|
||||
public class JSONTest {
|
||||
|
|
@ -42,12 +42,12 @@ public class JSONTest {
|
|||
JSON.json(e, writer);
|
||||
String json = writer.getBuffer().toString();
|
||||
System.out.println(json);
|
||||
// Assert.assertEquals("{\"code\":\"001\",\"message\":\"AAAAAAAA\"}", json);
|
||||
// Assertions.assertEquals("{\"code\":\"001\",\"message\":\"AAAAAAAA\"}", json);
|
||||
|
||||
StringReader reader = new StringReader(json);
|
||||
MyException result = JSON.parse(reader, MyException.class);
|
||||
Assert.assertEquals("001", result.getCode());
|
||||
Assert.assertEquals("AAAAAAAA", result.getMessage());
|
||||
Assertions.assertEquals("001", result.getCode());
|
||||
Assertions.assertEquals("AAAAAAAA", result.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -59,11 +59,11 @@ public class JSONTest {
|
|||
StringWriter writer = new StringWriter();
|
||||
JSON.json(map, writer);
|
||||
String json = writer.getBuffer().toString();
|
||||
Assert.assertEquals("{\"aaa\":\"bbb\"}", json);
|
||||
Assertions.assertEquals("{\"aaa\":\"bbb\"}", json);
|
||||
|
||||
StringReader reader = new StringReader(json);
|
||||
Map<String, String> result = JSON.parse(reader, Map.class);
|
||||
Assert.assertEquals("bbb", result.get("aaa"));
|
||||
Assertions.assertEquals("bbb", result.get("aaa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -75,12 +75,12 @@ public class JSONTest {
|
|||
StringWriter writer = new StringWriter();
|
||||
JSON.json(new Object[]{map}, writer); // args
|
||||
String json = writer.getBuffer().toString();
|
||||
Assert.assertEquals("[{\"aaa\":\"bbb\"}]", json);
|
||||
Assertions.assertEquals("[{\"aaa\":\"bbb\"}]", json);
|
||||
|
||||
StringReader reader = new StringReader(json);
|
||||
Object[] result = JSON.parse(reader, new Class<?>[]{Map.class});
|
||||
Assert.assertEquals(1, result.length);
|
||||
Assert.assertEquals("bbb", ((Map<String, String>) result[0]).get("aaa"));
|
||||
Assertions.assertEquals(1, result.length);
|
||||
Assertions.assertEquals("bbb", ((Map<String, String>) result[0]).get("aaa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -92,11 +92,11 @@ public class JSONTest {
|
|||
StringWriter writer = new StringWriter();
|
||||
JSON.json(map, writer);
|
||||
String json = writer.getBuffer().toString();
|
||||
Assert.assertEquals("{\"aaa\":\"bbb\"}", json);
|
||||
Assertions.assertEquals("{\"aaa\":\"bbb\"}", json);
|
||||
|
||||
StringReader reader = new StringReader(json);
|
||||
LinkedHashMap<String, String> result = JSON.parse(reader, LinkedHashMap.class);
|
||||
Assert.assertEquals("bbb", result.get("aaa"));
|
||||
Assertions.assertEquals("bbb", result.get("aaa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class JSONWriterTest extends TestCase {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class JSONWriterTest {
|
||||
public void testWriteJson() throws Exception {
|
||||
StringWriter w = new StringWriter();
|
||||
JSONWriter writer = new JSONWriter(w);
|
||||
|
|
|
|||
|
|
@ -26,51 +26,45 @@ import org.apache.dubbo.common.logger.log4j2.Log4j2Logger;
|
|||
import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
|
||||
import org.apache.dubbo.common.logger.slf4j.Slf4jLogger;
|
||||
import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class LoggerAdapterTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{JclLoggerAdapter.class, JclLogger.class},
|
||||
{JdkLoggerAdapter.class, JdkLogger.class},
|
||||
{Log4jLoggerAdapter.class, Log4jLogger.class},
|
||||
{Slf4jLoggerAdapter.class, Slf4jLogger.class},
|
||||
{Log4j2LoggerAdapter.class, Log4j2Logger.class},
|
||||
});
|
||||
static Stream<Arguments> data() {
|
||||
return Stream.of(
|
||||
Arguments.of(JclLoggerAdapter.class, JclLogger.class),
|
||||
Arguments.of(JdkLoggerAdapter.class, JdkLogger.class),
|
||||
Arguments.of(Log4jLoggerAdapter.class, Log4jLogger.class),
|
||||
Arguments.of(Slf4jLoggerAdapter.class, Slf4jLogger.class),
|
||||
Arguments.of(Log4j2LoggerAdapter.class, Log4j2Logger.class)
|
||||
);
|
||||
}
|
||||
|
||||
private Class loggerClass;
|
||||
private LoggerAdapter loggerAdapter;
|
||||
|
||||
public LoggerAdapterTest(Class<? extends LoggerAdapter> loggerAdapterClass, Class<? extends Logger> loggerClass) throws Exception {
|
||||
this.loggerClass = loggerClass;
|
||||
this.loggerAdapter = loggerAdapterClass.newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLogger() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testGetLogger(Class<? extends LoggerAdapter> loggerAdapterClass, Class<? extends Logger> loggerClass) throws IllegalAccessException, InstantiationException {
|
||||
LoggerAdapter loggerAdapter = loggerAdapterClass.newInstance();
|
||||
Logger logger = loggerAdapter.getLogger(this.getClass());
|
||||
assertThat(logger.getClass().isAssignableFrom(this.loggerClass), is(true));
|
||||
assertThat(logger.getClass().isAssignableFrom(loggerClass), is(true));
|
||||
|
||||
logger = loggerAdapter.getLogger(this.getClass().getSimpleName());
|
||||
assertThat(logger.getClass().isAssignableFrom(this.loggerClass), is(true));
|
||||
assertThat(logger.getClass().isAssignableFrom(loggerClass), is(true));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLevel() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testLevel(Class<? extends LoggerAdapter> loggerAdapterClass) throws IllegalAccessException, InstantiationException {
|
||||
LoggerAdapter loggerAdapter = loggerAdapterClass.newInstance();
|
||||
for (Level targetLevel : Level.values()) {
|
||||
loggerAdapter.setLevel(targetLevel);
|
||||
|
||||
assertThat(loggerAdapter.getLevel(), is(targetLevel));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.logger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class LoggerFactoryTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -19,41 +19,38 @@ package org.apache.dubbo.common.logger;
|
|||
import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter;
|
||||
import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter;
|
||||
import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter;
|
||||
import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
|
||||
import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class LoggerTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{JclLoggerAdapter.class},
|
||||
{JdkLoggerAdapter.class},
|
||||
{Log4jLoggerAdapter.class},
|
||||
{Slf4jLoggerAdapter.class}
|
||||
});
|
||||
|
||||
static Stream<Arguments> data() {
|
||||
return Stream.of(
|
||||
Arguments.of(JclLoggerAdapter.class),
|
||||
Arguments.of(JdkLoggerAdapter.class),
|
||||
Arguments.of(Log4jLoggerAdapter.class),
|
||||
Arguments.of(Slf4jLoggerAdapter.class),
|
||||
Arguments.of(Log4j2LoggerAdapter.class)
|
||||
);
|
||||
}
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public LoggerTest(Class<? extends LoggerAdapter> loggerAdapter) throws Exception {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testAllLogMethod(Class<? extends LoggerAdapter> loggerAdapter) throws Exception {
|
||||
LoggerAdapter adapter = loggerAdapter.newInstance();
|
||||
adapter.setLevel(Level.ALL);
|
||||
this.logger = adapter.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllLogMethod() {
|
||||
Logger logger = adapter.getLogger(this.getClass());
|
||||
logger.error("error");
|
||||
logger.warn("warn");
|
||||
logger.info("info");
|
||||
|
|
@ -73,8 +70,12 @@ public class LoggerTest {
|
|||
logger.trace("trace", new Exception("trace"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLevelEnable() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testLevelEnable(Class<? extends LoggerAdapter> loggerAdapter) throws IllegalAccessException, InstantiationException {
|
||||
LoggerAdapter adapter = loggerAdapter.newInstance();
|
||||
adapter.setLevel(Level.ALL);
|
||||
Logger logger = adapter.getLogger(this.getClass());
|
||||
assertThat(logger.isWarnEnabled(), not(nullValue()));
|
||||
assertThat(logger.isTraceEnabled(), not(nullValue()));
|
||||
assertThat(logger.isErrorEnabled(), not(nullValue()));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.logger.slf4j;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
package org.apache.dubbo.common.logger.support;
|
||||
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
|
@ -91,12 +93,14 @@ public class FailsafeLoggerTest {
|
|||
failsafeLogger.trace("trace", new Exception("trace"));
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
@Test
|
||||
public void testGetLogger() {
|
||||
Logger failLogger = mock(Logger.class);
|
||||
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
|
||||
Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
Logger failLogger = mock(Logger.class);
|
||||
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
|
||||
|
||||
doThrow(new RuntimeException()).when(failLogger).error(anyString());
|
||||
failsafeLogger.getLogger().error("should get error");
|
||||
doThrow(new RuntimeException()).when(failLogger).error(anyString());
|
||||
failsafeLogger.getLogger().error("should get error");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
package org.apache.dubbo.common.status;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.status.Status.Level.OK;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class StatusTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ package org.apache.dubbo.common.status.support;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class LoadStatusCheckerTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(LoadStatusCheckerTest.class);
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ package org.apache.dubbo.common.status.support;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.status.Status.Level.OK;
|
||||
import static org.apache.dubbo.common.status.Status.Level.WARN;
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class MemoryStatusCheckerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MemoryStatusCheckerTest.class);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.dubbo.common.status.support;
|
||||
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -27,7 +27,7 @@ import static org.hamcrest.Matchers.containsString;
|
|||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class StatusUtilsTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.store.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SimpleDataStoreTest {
|
||||
private SimpleDataStore dataStore = new SimpleDataStore();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.dubbo.common.threadlocal;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -60,26 +60,26 @@ public class InternalThreadLocalTest {
|
|||
public void testRemoveAll() throws InterruptedException {
|
||||
final InternalThreadLocal<Integer> internalThreadLocal = new InternalThreadLocal<Integer>();
|
||||
internalThreadLocal.set(1);
|
||||
Assert.assertTrue("set failed", internalThreadLocal.get() == 1);
|
||||
Assertions.assertTrue(internalThreadLocal.get() == 1, "set failed");
|
||||
|
||||
final InternalThreadLocal<String> internalThreadLocalString = new InternalThreadLocal<String>();
|
||||
internalThreadLocalString.set("value");
|
||||
Assert.assertTrue("set failed", "value".equals(internalThreadLocalString.get()));
|
||||
Assertions.assertTrue("value".equals(internalThreadLocalString.get()), "set failed");
|
||||
|
||||
InternalThreadLocal.removeAll();
|
||||
Assert.assertTrue("removeAll failed!", internalThreadLocal.get() == null);
|
||||
Assert.assertTrue("removeAll failed!", internalThreadLocalString.get() == null);
|
||||
Assertions.assertTrue(internalThreadLocal.get() == null, "removeAll failed!");
|
||||
Assertions.assertTrue(internalThreadLocalString.get() == null, "removeAll failed!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() throws InterruptedException {
|
||||
final InternalThreadLocal<Integer> internalThreadLocal = new InternalThreadLocal<Integer>();
|
||||
internalThreadLocal.set(1);
|
||||
Assert.assertTrue("size method is wrong!", InternalThreadLocal.size() == 1);
|
||||
Assertions.assertTrue(InternalThreadLocal.size() == 1, "size method is wrong!");
|
||||
|
||||
final InternalThreadLocal<String> internalThreadLocalString = new InternalThreadLocal<String>();
|
||||
internalThreadLocalString.set("value");
|
||||
Assert.assertTrue("size method is wrong!", InternalThreadLocal.size() == 2);
|
||||
Assertions.assertTrue(InternalThreadLocal.size() == 2, "size method is wrong!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -87,18 +87,18 @@ public class InternalThreadLocalTest {
|
|||
final Integer testVal = 10;
|
||||
final InternalThreadLocal<Integer> internalThreadLocal = new InternalThreadLocal<Integer>();
|
||||
internalThreadLocal.set(testVal);
|
||||
Assert.assertTrue("set is not equals get",
|
||||
Objects.equals(testVal, internalThreadLocal.get()));
|
||||
Assertions.assertTrue(
|
||||
Objects.equals(testVal, internalThreadLocal.get()), "set is not equals get");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
final InternalThreadLocal<Integer> internalThreadLocal = new InternalThreadLocal<Integer>();
|
||||
internalThreadLocal.set(1);
|
||||
Assert.assertTrue("get method false!", internalThreadLocal.get() == 1);
|
||||
Assertions.assertTrue(internalThreadLocal.get() == 1, "get method false!");
|
||||
|
||||
internalThreadLocal.remove();
|
||||
Assert.assertTrue("remove failed!", internalThreadLocal.get() == null);
|
||||
Assertions.assertTrue(internalThreadLocal.get() == null, "remove failed!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -112,10 +112,10 @@ public class InternalThreadLocalTest {
|
|||
}
|
||||
};
|
||||
internalThreadLocal.set(1);
|
||||
Assert.assertTrue("get method false!", internalThreadLocal.get() == 1);
|
||||
Assertions.assertTrue(internalThreadLocal.get() == 1, "get method false!");
|
||||
|
||||
internalThreadLocal.remove();
|
||||
Assert.assertTrue("onRemove method failed!", valueToRemove[0] == 2);
|
||||
Assertions.assertTrue(valueToRemove[0] == 2, "onRemove method failed!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -129,8 +129,8 @@ public class InternalThreadLocalTest {
|
|||
public void run() {
|
||||
|
||||
internalThreadLocal.set(testVal1);
|
||||
Assert.assertTrue("set is not equals get",
|
||||
Objects.equals(testVal1, internalThreadLocal.get()));
|
||||
Assertions.assertTrue(
|
||||
Objects.equals(testVal1, internalThreadLocal.get()), "set is not equals get");
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
|
@ -140,8 +140,8 @@ public class InternalThreadLocalTest {
|
|||
@Override
|
||||
public void run() {
|
||||
internalThreadLocal.set(testVal2);
|
||||
Assert.assertTrue("set is not equals get",
|
||||
Objects.equals(testVal2, internalThreadLocal.get()));
|
||||
Assertions.assertTrue(
|
||||
Objects.equals(testVal2, internalThreadLocal.get()), "set is not equals get");
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.dubbo.common.threadlocal;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class NamedInternalThreadFactoryTest {
|
||||
|
||||
|
|
@ -31,6 +31,6 @@ public class NamedInternalThreadFactoryTest {
|
|||
|
||||
}
|
||||
});
|
||||
Assert.assertTrue("thread is not InternalThread", t.getClass().equals(InternalThread.class));
|
||||
Assertions.assertTrue(t.getClass().equals(InternalThread.class), "thread is not InternalThread");
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ package org.apache.dubbo.common.threadpool.support;
|
|||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import org.apache.dubbo.common.threadlocal.InternalThread;
|
|||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class CachedThreadPoolTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import org.apache.dubbo.common.threadpool.ThreadPool;
|
|||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -90,7 +90,7 @@ public class EagerThreadPoolExecutorTest {
|
|||
}
|
||||
Thread.sleep(5000);
|
||||
// cores theads are all alive.
|
||||
Assert.assertTrue("more than cores threads alive!", executor.getPoolSize() == cores);
|
||||
Assertions.assertTrue(executor.getPoolSize() == cores, "more than cores threads alive!");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -98,9 +98,9 @@ public class EagerThreadPoolExecutorTest {
|
|||
ExecutorService executorService = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class)
|
||||
.getExtension("eager")
|
||||
.getExecutor(URL);
|
||||
Assert.assertTrue("test spi fail!",
|
||||
Assertions.assertTrue(
|
||||
executorService.getClass()
|
||||
.getSimpleName()
|
||||
.equals("EagerThreadPoolExecutor"));
|
||||
.equals("EagerThreadPoolExecutor"), "test spi fail!");
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ import org.apache.dubbo.common.threadlocal.InternalThread;
|
|||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class EagerThreadPoolTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,22 +17,25 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.eager;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class TaskQueueTest {
|
||||
|
||||
@Test(expected = RejectedExecutionException.class)
|
||||
@Test
|
||||
public void testOffer1() throws Exception {
|
||||
TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1);
|
||||
queue.offer(mock(Runnable.class));
|
||||
Assertions.assertThrows(RejectedExecutionException.class, () -> {
|
||||
TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1);
|
||||
queue.offer(mock(Runnable.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -67,13 +70,15 @@ public class TaskQueueTest {
|
|||
assertThat(queue.offer(mock(Runnable.class)), is(true));
|
||||
}
|
||||
|
||||
@Test(expected = RejectedExecutionException.class)
|
||||
@Test
|
||||
public void testRetryOffer1() throws Exception {
|
||||
TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1);
|
||||
EagerThreadPoolExecutor executor = mock(EagerThreadPoolExecutor.class);
|
||||
Mockito.when(executor.isShutdown()).thenReturn(true);
|
||||
queue.setExecutor(executor);
|
||||
queue.retryOffer(mock(Runnable.class), 1000, TimeUnit.MILLISECONDS);
|
||||
Assertions.assertThrows(RejectedExecutionException.class, () -> {
|
||||
TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1);
|
||||
EagerThreadPoolExecutor executor = mock(EagerThreadPoolExecutor.class);
|
||||
Mockito.when(executor.isShutdown()).thenReturn(true);
|
||||
queue.setExecutor(executor);
|
||||
queue.retryOffer(mock(Runnable.class), 1000, TimeUnit.MILLISECONDS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import org.apache.dubbo.common.threadpool.ThreadPool;
|
|||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.apache.dubbo.common.threadpool.support.limited.LimitedThreadPool;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class FixedThreadPoolTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import org.apache.dubbo.common.threadlocal.InternalThread;
|
|||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class LimitedThreadPoolTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.dubbo.common.timer;
|
||||
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ArrayUtilsTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -17,43 +17,45 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.utils.Assert.notNull;
|
||||
import static org.apache.dubbo.common.utils.Assert.notEmptyString;
|
||||
import static org.apache.dubbo.common.utils.Assert.notNull;
|
||||
|
||||
public class AssertTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotNull1() throws Exception {
|
||||
notNull(null, "null object");
|
||||
@Test
|
||||
public void testNotNull1() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> notNull(null, "null object"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testNotNull2() throws Exception {
|
||||
notNull(null, new IllegalStateException("null object"));
|
||||
@Test
|
||||
public void testNotNull2() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> notNull(null, new IllegalStateException("null object")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullWhenInputNotNull1() {
|
||||
notNull(new Object(),"null object");
|
||||
notNull(new Object(), "null object");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullWhenInputNotNull2() {
|
||||
notNull(new Object(),new IllegalStateException("null object"));
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotNullString() {
|
||||
notEmptyString(null,"Message can't be null");
|
||||
notNull(new Object(), new IllegalStateException("null object"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNotNullString() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> notEmptyString(null, "Message can't be null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEmptyString() {
|
||||
notEmptyString("","Message can't be null or empty");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> notEmptyString("", "Message can't be null or empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullNotEmptyString() {
|
||||
notEmptyString("abcd","Message can'be null or empty");
|
||||
notEmptyString("abcd", "Message can'be null or empty");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,15 +16,16 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class AtomicPositiveIntegerTest {
|
||||
private AtomicPositiveInteger i1 = new AtomicPositiveInteger();
|
||||
|
|
@ -159,24 +160,28 @@ public class AtomicPositiveIntegerTest {
|
|||
assertEquals(2, i3.get());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCompareAndSet1() throws Exception {
|
||||
i1.compareAndSet(i1.get(), -1);
|
||||
@Test
|
||||
public void testCompareAndSet1() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
i1.compareAndSet(i1.get(), -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareAndSet2() throws Exception {
|
||||
public void testCompareAndSet2() {
|
||||
assertThat(i1.compareAndSet(i1.get(), 2), is(true));
|
||||
assertThat(i1.get(), is(2));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWeakCompareAndSet1() throws Exception {
|
||||
i1.weakCompareAndSet(i1.get(), -1);
|
||||
@Test
|
||||
public void testWeakCompareAndSet1() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
i1.weakCompareAndSet(i1.get(), -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWeakCompareAndSet2() throws Exception {
|
||||
public void testWeakCompareAndSet2() {
|
||||
assertThat(i1.weakCompareAndSet(i1.get(), 2), is(true));
|
||||
assertThat(i1.get(), is(2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.apache.dubbo.common.utils.ClassHelper.forName;
|
||||
|
|
@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class ClassHelperTest {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -34,11 +35,11 @@ import static java.util.Collections.emptyList;
|
|||
import static java.util.Collections.singleton;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CollectionUtilsTest {
|
||||
@Test
|
||||
|
|
@ -161,9 +162,9 @@ public class CollectionUtilsTest {
|
|||
assertThat(toStringMap("key", "value"), equalTo(Collections.singletonMap("key", "value")));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testStringMap2() throws Exception {
|
||||
toStringMap("key", "value", "odd");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> toStringMap("key", "value", "odd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,9 +179,9 @@ public class CollectionUtilsTest {
|
|||
assertEquals(expected, CollectionUtils.toMap("a", 1, "b", 2, "c", 3));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testToMap2() throws Exception {
|
||||
toMap("a", "b", "c");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> toMap("a", "b", "c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
|
@ -28,10 +28,10 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class CompatibleTypeUtilsTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ package org.apache.dubbo.common.utils;
|
|||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -33,16 +33,16 @@ import static org.hamcrest.Matchers.containsString;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class ConfigUtilsTest {
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
ConfigUtils.setProperties(null);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
ConfigUtils.setProperties(null);
|
||||
}
|
||||
|
|
@ -228,12 +228,12 @@ public class ConfigUtilsTest {
|
|||
}
|
||||
|
||||
|
||||
@Ignore("see http://code.alibabatech.com/jira/browse/DUBBO-133")
|
||||
@Disabled("see http://code.alibabatech.com/jira/browse/DUBBO-133")
|
||||
@Test
|
||||
public void testLoadPropertiesMultiFileNotRootPathException() throws Exception {
|
||||
try {
|
||||
ConfigUtils.loadProperties("META-INF/services/org.apache.dubbo.common.status.StatusChecker", false);
|
||||
Assert.fail();
|
||||
Assertions.fail();
|
||||
} catch (IllegalStateException expected) {
|
||||
assertThat(expected.getMessage(), containsString("only 1 META-INF/services/org.apache.dubbo.common.status.StatusChecker file is expected, but 2 dubbo.properties files found on class path:"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,20 +20,20 @@ package org.apache.dubbo.common.utils;
|
|||
import org.apache.log4j.Category;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class DubboAppenderTest {
|
||||
private LoggingEvent event;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
Level level = Mockito.mock(Level.class);
|
||||
Category category = Mockito.mock(Category.class);
|
||||
|
|
@ -44,7 +44,7 @@ public class DubboAppenderTest {
|
|||
Mockito.when(event.getMessage()).thenReturn("message");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
DubboAppender.clear();
|
||||
DubboAppender.doStop();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package org.apache.dubbo.common.utils;
|
|||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
|
@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class HolderTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.support.io.TempDirectory;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -32,13 +33,13 @@ import java.io.Reader;
|
|||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
public class IOUtilsTest {
|
||||
@Rule
|
||||
public TemporaryFolder tmpDir = new TemporaryFolder();
|
||||
|
||||
private static String TEXT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
|
||||
private InputStream is;
|
||||
|
|
@ -46,7 +47,7 @@ public class IOUtilsTest {
|
|||
private Reader reader;
|
||||
private Writer writer;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
is = new ByteArrayInputStream(TEXT.getBytes("UTF-8"));
|
||||
os = new ByteArrayOutputStream();
|
||||
|
|
@ -54,7 +55,7 @@ public class IOUtilsTest {
|
|||
writer = new StringWriter();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
is.close();
|
||||
os.close();
|
||||
|
|
@ -88,12 +89,13 @@ public class IOUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLines() throws Exception {
|
||||
File file = tmpDir.newFile();
|
||||
public void testLines(@TempDirectory.TempDir Path tmpDir) throws Exception {
|
||||
File file = tmpDir.getFileName().toAbsolutePath().toFile();
|
||||
IOUtils.writeLines(file, new String[]{TEXT});
|
||||
String[] lines = IOUtils.readLines(file);
|
||||
assertThat(lines.length, equalTo(1));
|
||||
assertThat(lines[0], equalTo(TEXT));
|
||||
tmpDir.getFileName().toAbsolutePath().toFile().delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -116,13 +118,14 @@ public class IOUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAppendLines() throws Exception {
|
||||
File file = tmpDir.newFile();
|
||||
public void testAppendLines(@TempDirectory.TempDir Path tmpDir) throws Exception {
|
||||
File file = tmpDir.getFileName().toAbsolutePath().toFile();
|
||||
IOUtils.appendLines(file, new String[]{"a", "b", "c"});
|
||||
String[] lines = IOUtils.readLines(file);
|
||||
assertThat(lines.length, equalTo(3));
|
||||
assertThat(lines[0], equalTo("a"));
|
||||
assertThat(lines[1], equalTo("b"));
|
||||
assertThat(lines[2], equalTo("c"));
|
||||
tmpDir.getFileName().toAbsolutePath().toFile().delete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class LRUCacheTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class LogTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,17 +18,17 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LogUtilTest {
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
DubboAppender.logList.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,15 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NamedThreadFactoryTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,22 +17,22 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ public class NetUtilsTest {
|
|||
* But enable it will cause other UT to fail.
|
||||
* Therefore currently disabling this UT.
|
||||
*/
|
||||
@Ignore
|
||||
@Disabled
|
||||
@Test
|
||||
public void testNormalizeV6Address() {
|
||||
Inet6Address address = mock(Inet6Address.class);
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParametersTest extends TestCase {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ParametersTest {
|
||||
final String ServiceName = "org.apache.dubbo.rpc.service.GenericService";
|
||||
final String ServiceVersion = "1.0.15";
|
||||
final String LoadBalance = "lcr";
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import org.apache.dubbo.common.model.person.FullAddress;
|
|||
import org.apache.dubbo.common.model.person.PersonInfo;
|
||||
import org.apache.dubbo.common.model.person.PersonStatus;
|
||||
import org.apache.dubbo.common.model.person.Phone;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -40,13 +40,13 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PojoUtilsTest {
|
||||
|
||||
|
|
@ -533,11 +533,11 @@ public class PojoUtilsTest {
|
|||
child.setParent(parent);
|
||||
Object obj = PojoUtils.generalize(parent);
|
||||
Parent realizedParent = (Parent) PojoUtils.realize(obj, Parent.class);
|
||||
Assert.assertEquals(parent.gender, realizedParent.gender);
|
||||
Assert.assertEquals(child.gender, parent.getChild().gender);
|
||||
Assert.assertEquals(child.age, realizedParent.getChild().getAge());
|
||||
Assert.assertEquals(parent.getEmail(), realizedParent.getEmail());
|
||||
Assert.assertNull(realizedParent.email);
|
||||
Assertions.assertEquals(parent.gender, realizedParent.gender);
|
||||
Assertions.assertEquals(child.gender, parent.getChild().gender);
|
||||
Assertions.assertEquals(child.age, realizedParent.getChild().getAge());
|
||||
Assertions.assertEquals(parent.getEmail(), realizedParent.getEmail());
|
||||
Assertions.assertNull(realizedParent.email);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -553,24 +553,24 @@ public class PojoUtilsTest {
|
|||
data.setList(Arrays.asList(newChild("forth", 4)));
|
||||
|
||||
Object obj = PojoUtils.generalize(data);
|
||||
Assert.assertEquals(3, data.getChildren().size());
|
||||
Assertions.assertEquals(3, data.getChildren().size());
|
||||
assertTrue(data.getChildren().get("first").getClass() == Child.class);
|
||||
Assert.assertEquals(1, data.getList().size());
|
||||
Assertions.assertEquals(1, data.getList().size());
|
||||
assertTrue(data.getList().get(0).getClass() == Child.class);
|
||||
|
||||
TestData realizadData = (TestData) PojoUtils.realize(obj, TestData.class);
|
||||
Assert.assertEquals(data.getChildren().size(), realizadData.getChildren().size());
|
||||
Assert.assertEquals(data.getChildren().keySet(), realizadData.getChildren().keySet());
|
||||
Assertions.assertEquals(data.getChildren().size(), realizadData.getChildren().size());
|
||||
Assertions.assertEquals(data.getChildren().keySet(), realizadData.getChildren().keySet());
|
||||
for (Map.Entry<String, Child> entry : data.getChildren().entrySet()) {
|
||||
Child c = realizadData.getChildren().get(entry.getKey());
|
||||
Assert.assertNotNull(c);
|
||||
Assert.assertEquals(entry.getValue().getName(), c.getName());
|
||||
Assert.assertEquals(entry.getValue().getAge(), c.getAge());
|
||||
Assertions.assertNotNull(c);
|
||||
Assertions.assertEquals(entry.getValue().getName(), c.getName());
|
||||
Assertions.assertEquals(entry.getValue().getAge(), c.getAge());
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, realizadData.getList().size());
|
||||
Assert.assertEquals(data.getList().get(0).getName(), realizadData.getList().get(0).getName());
|
||||
Assert.assertEquals(data.getList().get(0).getAge(), realizadData.getList().get(0).getAge());
|
||||
Assertions.assertEquals(1, realizadData.getList().size());
|
||||
Assertions.assertEquals(data.getList().get(0).getName(), realizadData.getList().get(0).getName());
|
||||
Assertions.assertEquals(data.getList().get(0).getAge(), realizadData.getList().get(0).getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -617,8 +617,8 @@ public class PojoUtilsTest {
|
|||
assertTrue(l.size() == 1);
|
||||
assertTrue(l.get(0) instanceof Parent);
|
||||
Parent realizeParent = (Parent) l.get(0);
|
||||
Assert.assertEquals(parent.getName(), realizeParent.getName());
|
||||
Assert.assertEquals(parent.getAge(), realizeParent.getAge());
|
||||
Assertions.assertEquals(parent.getName(), realizeParent.getName());
|
||||
Assertions.assertEquals(parent.getAge(), realizeParent.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -638,14 +638,14 @@ public class PojoUtilsTest {
|
|||
assertTrue(realizeObject instanceof ListResult);
|
||||
ListResult realizeList = (ListResult) realizeObject;
|
||||
List realizeInnerList = realizeList.getResult();
|
||||
Assert.assertEquals(1, realizeInnerList.size());
|
||||
Assertions.assertEquals(1, realizeInnerList.size());
|
||||
assertTrue(realizeInnerList.get(0) instanceof InnerPojo);
|
||||
InnerPojo realizeParentList = (InnerPojo) realizeInnerList.get(0);
|
||||
Assert.assertEquals(1, realizeParentList.getList().size());
|
||||
Assertions.assertEquals(1, realizeParentList.getList().size());
|
||||
assertTrue(realizeParentList.getList().get(0) instanceof Parent);
|
||||
Parent realizeParent = (Parent) realizeParentList.getList().get(0);
|
||||
Assert.assertEquals(parent.getName(), realizeParent.getName());
|
||||
Assert.assertEquals(parent.getAge(), realizeParent.getAge());
|
||||
Assertions.assertEquals(parent.getName(), realizeParent.getName());
|
||||
Assertions.assertEquals(parent.getAge(), realizeParent.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -28,18 +29,18 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ReflectUtilsTest {
|
||||
@Test
|
||||
|
|
@ -189,9 +190,12 @@ public class ReflectUtilsTest {
|
|||
assertNotNull(ReflectUtils.findMethodByMethodName(Foo.class, "hello"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testFindMethodByMethodName2() throws Exception {
|
||||
ReflectUtils.findMethodByMethodName(Foo2.class, "hello");
|
||||
@Test
|
||||
public void testFindMethodByMethodName2() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
ReflectUtils.findMethodByMethodName(Foo2.class, "hello");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -390,9 +394,11 @@ public class ReflectUtilsTest {
|
|||
assertThat(ReflectUtils.forName(ReflectUtils.class.getName()), sameInstance(ReflectUtils.class));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testForName2() throws Exception {
|
||||
ReflectUtils.forName("a.c.d.e.F");
|
||||
@Test
|
||||
public void testForName2() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
ReflectUtils.forName("a.c.d.e.F");
|
||||
});
|
||||
}
|
||||
|
||||
public static class EmptyClass {
|
||||
|
|
|
|||
|
|
@ -17,13 +17,14 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class StackTest {
|
||||
@Test
|
||||
|
|
@ -57,33 +58,43 @@ public class StackTest {
|
|||
assertThat(stack.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test(expected = EmptyStackException.class)
|
||||
@Test
|
||||
public void testIllegalPop() throws Exception {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.pop();
|
||||
Assertions.assertThrows(EmptyStackException.class, () -> {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.pop();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = EmptyStackException.class)
|
||||
@Test
|
||||
public void testIllegalPeek() throws Exception {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.peek();
|
||||
Assertions.assertThrows(EmptyStackException.class, () -> {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.peek();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testIllegalGet() throws Exception {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.get(1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.get(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testIllegalSet() throws Exception {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.set(1, "illegal");
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.set(1, "illegal");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testIllegalRemove() throws Exception {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.remove(1);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.remove(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -26,15 +26,15 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class StringUtilsTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package org.apache.dubbo.common.utils;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -29,11 +29,11 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class UrlUtilsTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,20 +19,20 @@ package org.apache.dubbo.common.version;
|
|||
|
||||
import org.apache.dubbo.common.Version;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class VersionTest {
|
||||
|
||||
@Test
|
||||
public void testGetProtocolVersion() {
|
||||
Assert.assertEquals(Version.getProtocolVersion(), Version.DEFAULT_DUBBO_PROTOCOL_VERSION);
|
||||
Assertions.assertEquals(Version.getProtocolVersion(), Version.DEFAULT_DUBBO_PROTOCOL_VERSION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportResponseAttachment() {
|
||||
Assert.assertTrue(Version.isSupportResponseAttachment("2.0.2"));
|
||||
Assert.assertTrue(Version.isSupportResponseAttachment("2.0.3"));
|
||||
Assert.assertFalse(Version.isSupportResponseAttachment("2.0.0"));
|
||||
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.2"));
|
||||
Assertions.assertTrue(Version.isSupportResponseAttachment("2.0.3"));
|
||||
Assertions.assertFalse(Version.isSupportResponseAttachment("2.0.0"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import com.alibaba.dubbo.common.URL;
|
|||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ public class CacheTest {
|
|||
org.apache.dubbo.rpc.Invocation inv = new RpcInvocation();
|
||||
org.apache.dubbo.cache.Cache c = factory.getCache(u, inv);
|
||||
String v = (String) c.get("testKey");
|
||||
Assert.assertEquals("testValue", v);
|
||||
Assertions.assertEquals("testValue", v);
|
||||
}
|
||||
|
||||
static class NullInvocation implements Invocation {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue