You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/05/05 01:46:21 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2474] (task 1) Java17 Test paas on foundation module (#2813)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 188693094 [SCB-2474] (task 1) Java17 Test paas on foundation module (#2813)
188693094 is described below
commit 188693094fbe1a95b28fe46b9977bd55979a7eb8
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Thu May 5 09:46:14 2022 +0800
[SCB-2474] (task 1) Java17 Test paas on foundation module (#2813)
---
.../src/test/java/TestNoPackageMain.java | 9 +++++---
.../foundation/common/utils/TestJvmUtils.java | 2 ++
.../common/utils/TestLambdaMetafactoryUtils.java | 13 ++++++-----
.../common/utils/TestSPIServiceUtils.java | 26 +++++++++++++---------
.../foundation/ssl/KeyStoreUtilTest.java | 13 +++++++----
pom.xml | 20 +++++++++++++++--
6 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/foundations/foundation-common/src/test/java/TestNoPackageMain.java b/foundations/foundation-common/src/test/java/TestNoPackageMain.java
index 75fe87893..22b57e48b 100644
--- a/foundations/foundation-common/src/test/java/TestNoPackageMain.java
+++ b/foundations/foundation-common/src/test/java/TestNoPackageMain.java
@@ -17,13 +17,16 @@
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.JvmUtils;
-import org.junit.Assert;
-import org.junit.Test;
import mockit.Expectations;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
public class TestNoPackageMain {
@Test
+ @EnabledOnJre(JRE.JAVA_8)
public void prepareServiceCombScanPackage_mainNoPackage() {
System.clearProperty(BeanUtils.SCB_SCAN_PACKAGE);
new Expectations(JvmUtils.class) {
@@ -37,6 +40,6 @@ public class TestNoPackageMain {
BeanUtils.prepareServiceCombScanPackage();
- Assert.assertEquals("org.apache.servicecomb", System.getProperty(BeanUtils.SCB_SCAN_PACKAGE));
+ Assertions.assertEquals("org.apache.servicecomb", System.getProperty(BeanUtils.SCB_SCAN_PACKAGE));
}
}
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
index 890ea21da..8f6bb1d0d 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
@@ -30,12 +30,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({JvmUtils.class})
+@PowerMockIgnore("jdk.internal.reflect.*")
public class TestJvmUtils {
static String orgCmd = System.getProperty(JvmUtils.SUN_JAVA_COMMAND);
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
index 11b7a04cb..39647ba3d 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
@@ -35,13 +35,16 @@ import org.apache.servicecomb.foundation.common.utils.bean.IntSetter;
import org.apache.servicecomb.foundation.common.utils.bean.Setter;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
-import org.junit.Test;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
+@EnabledOnJre(JRE.JAVA_8)
public class TestLambdaMetafactoryUtils {
public static class Model {
public int f1;
@@ -80,7 +83,7 @@ public class TestLambdaMetafactoryUtils {
setter.accept(1);
int f1 = (int) getter.get();
- Assert.assertEquals(1, f1);
+ Assertions.assertEquals(1, f1);
MatcherAssert.assertThat((List<Integer>) echo.apply(Arrays.asList(2)), Matchers.contains(2));
}
@@ -96,12 +99,12 @@ public class TestLambdaMetafactoryUtils {
setter.set(model, 1);
int f1 = getter.get(model);
- Assert.assertEquals(1, f1);
+ Assertions.assertEquals(1, f1);
MatcherAssert.assertThat((List<Integer>) echo.apply(model, Arrays.asList(2)), Matchers.contains(2));
fluentSetter.set(model, 2);
int ff1 = getter.get(model);
- Assert.assertEquals(2, ff1);
+ Assertions.assertEquals(2, ff1);
}
@Test
diff --git a/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java b/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
index 51d9d1688..4e8e38dc6 100644
--- a/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
+++ b/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
@@ -24,13 +24,15 @@ import java.util.ServiceLoader;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.mockito.Mockito;
import org.springframework.core.Ordered;
import mockit.Deencapsulation;
import mockit.Expectations;
-import mockit.Mocked;
/**
* Test SPIServiceUtils
@@ -41,30 +43,33 @@ public class TestSPIServiceUtils {
@Test
public void testGetTargetServiceNull() {
SPIServiceDef0 service = SPIServiceUtils.getTargetService(SPIServiceDef0.class);
- Assert.assertNull(service);
+ Assertions.assertNull(service);
}
@Test
public void testGetTargetServiceNotNull() {
SPIServiceDef service = SPIServiceUtils.getTargetService(SPIServiceDef.class);
- Assert.assertTrue(SPIServiceDef.class.isInstance(service));
+ Assertions.assertNotNull(service);
- Assert.assertSame(service, SPIServiceUtils.getTargetService(SPIServiceDef.class));
+ Assertions.assertSame(service, SPIServiceUtils.getTargetService(SPIServiceDef.class));
}
@Test
public void testGetTargetService_special_null() {
- Assert.assertNull(SPIServiceUtils.getTargetService(SPIServiceDef0.class, SPIServiceDef0Impl.class));
+ Assertions.assertNull(SPIServiceUtils.getTargetService(SPIServiceDef0.class, SPIServiceDef0Impl.class));
}
@Test
public void testGetTargetService_special_notNull() {
SPIServiceDef service = SPIServiceUtils.getTargetService(SPIServiceDef.class, SPIServiceDefImpl.class);
- Assert.assertTrue(SPIServiceDefImpl.class.isInstance(service));
+ Assertions.assertNotNull(service);
}
@Test
- public void testSort(@Mocked Ordered o1, @Mocked Ordered o2) {
+ @EnabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_11)
+ public void testSort() {
+ Ordered o1 = Mockito.mock(Ordered.class);
+ Ordered o2 = Mockito.mock(Ordered.class);
Map<String, Ordered> map = new LinkedHashMap<>();
map.put("a", o1);
map.put("b", o2);
@@ -92,7 +97,7 @@ public class TestSPIServiceUtils {
@Test
public void getPriorityHighestService_null() {
- Assert.assertNull(SPIServiceUtils.getPriorityHighestService(SPIServiceDef0.class));
+ Assertions.assertNull(SPIServiceUtils.getPriorityHighestService(SPIServiceDef0.class));
}
interface PriorityIntf {
@@ -131,6 +136,7 @@ public class TestSPIServiceUtils {
}
@Test
+ @EnabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_11)
public void getPriorityHighestServices() {
Map<String, PriorityIntf> instances = new LinkedHashMap<>();
instances.putIfAbsent("1", new PriorityImpl("n1", 0));
diff --git a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/KeyStoreUtilTest.java b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/KeyStoreUtilTest.java
index a4531ac6a..06f9a30ff 100644
--- a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/KeyStoreUtilTest.java
+++ b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/KeyStoreUtilTest.java
@@ -26,6 +26,7 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Collection;
+import org.apache.commons.lang3.SystemUtils;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -63,11 +64,9 @@ public class KeyStoreUtilTest {
}
}
- @SuppressWarnings("unused")
@Test
public void testCreateKeyManagersException() {
KeyStore keystore;
- char[] keyvalue;
String storename = strFilePath + "/ssl/server.p12";
String storetype = "PKCS12";
@@ -79,8 +78,14 @@ public class KeyStoreUtilTest {
try {
KeyStoreUtil.createKeyManagers(keystore, storeKeyValue);
} catch (IllegalArgumentException e) {
- Assert.assertEquals("Bad key store.Get Key failed: null",
- e.getMessage());
+ if (SystemUtils.JAVA_SPECIFICATION_VERSION.startsWith("17")) {
+ Assert.assertEquals("Bad key store.Get Key failed:"
+ + " Cannot read the array length because \"password\" is null",
+ e.getMessage());
+ } else {
+ Assert.assertEquals("Bad key store.Get Key failed: null",
+ e.getMessage());
+ }
}
}
diff --git a/pom.xml b/pom.xml
index c19abf685..a0722ebdd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -686,9 +686,25 @@
<werror.properties/>
<test.additional.args>
-Djdk.attach.allowAttachSelf
- --add-opens java.base/jdk.internal.loader=ALL-UNNAMED
- --add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
+ --add-opens java.base/java.lang=ALL-UNNAMED
+ --add-opens java.base/java.lang.reflect=ALL-UNNAMED
+ --add-opens java.base/java.net=ALL-UNNAMED
+ --add-opens java.base/java.nio=ALL-UNNAMED
+ --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED
+ --add-opens java.base/java.nio.file=ALL-UNNAMED
+ --add-opens java.base/java.util=ALL-UNNAMED
+ --add-opens java.base/java.util.concurrent=ALL-UNNAMED
+ --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED
+ --add-opens java.base/java.util.jar=ALL-UNNAMED
+ --add-opens java.base/java.util.stream=ALL-UNNAMED
+ --add-opens java.base/java.time=ALL-UNNAMED
+ --add-opens java.base/jdk.internal.loader=ALL-UNNAMED
+ --add-opens java.base/sun.net.dns=ALL-UNNAMED
+ --add-opens java.base/sun.nio.ch=ALL-UNNAMED
+ --add-opens java.base/sun.security.jca=ALL-UNNAMED
+ --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED
+ --add-reads java.base=java.desktop
</test.additional.args>
</properties>
</profile>