Skip to content

Commit

Permalink
Upgrade junt to junit5 (apache#3149)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lovepoem authored and khanimteyaz committed Jan 18, 2019
1 parent 0378ea0 commit c966137
Show file tree
Hide file tree
Showing 336 changed files with 4,613 additions and 4,293 deletions.
13 changes: 9 additions & 4 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
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;
Expand All @@ -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();
Expand All @@ -77,34 +77,34 @@ public void setUp() throws Exception {
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
public void testMethodsSticky() {
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);
}
}

Expand All @@ -129,7 +129,7 @@ public int testSticky(String methodName, boolean check) {

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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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
Expand All @@ -34,35 +34,35 @@ public void testOverrideApplication() {
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
public void testOverrideHost() {
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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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
Expand All @@ -34,35 +34,35 @@ public void testOverride_Application() {
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
public void testOverride_Host() {
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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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;
Expand All @@ -44,7 +44,7 @@ private String streamToString(InputStream stream) throws IOException {

@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);
Expand All @@ -59,109 +59,111 @@ public void snakeYamlBasicTest() throws IOException {

@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));
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(expected = IllegalStateException.class)
public void parseConfiguratorsServiceNoRuleTest() throws IOException {
try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) {
ConfigParser.parseConfigurators(streamToString(yamlStream));
Assert.fail();
}
@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");
}
}

Expand Down
Loading

0 comments on commit c966137

Please sign in to comment.