From cd62de968dc037f05e1f188db734da6e57fd014a Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Tue, 28 Jun 2022 14:21:51 +0800 Subject: [PATCH] Add JDK11 on unit-test (#10364) --- .github/workflows/backend.yml | 16 +++++-- .github/workflows/unit-test.yml | 7 ++- .../datasource/api/utils/CommonUtilsTest.java | 47 +++++++++++++------ dolphinscheduler-registry/pom.xml | 1 - 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index d86837f6df..101bba8633 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -56,18 +56,26 @@ jobs: needs: paths-filter if: ${{ (needs.paths-filter.outputs.not-ignore == 'true') || (github.event_name == 'push') }} runs-on: ubuntu-latest + strategy: + matrix: + java: [ '8', '11' ] timeout-minutes: 30 steps: - uses: actions/checkout@v2 with: submodules: true + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'adopt' - name: Sanity Check uses: ./.github/actions/sanity-check - uses: actions/cache@v3 with: path: ~/.m2/repository key: ${{ runner.os }}-maven - - name: Build and Package + - name: Build and Package on ${{ matrix.java }} run: | ./mvnw -B clean install \ -Prelease,docker \ @@ -79,9 +87,10 @@ jobs: - name: Check dependency license run: tools/dependencies/check-LICENSE.sh - uses: actions/upload-artifact@v2 + if: ${{ matrix.java == '8' }} name: Upload Binary Package with: - name: binary-package + name: binary-package-${{ matrix.java }} path: ./dolphinscheduler-dist/target/apache-dolphinscheduler-dev-SNAPSHOT-bin.tar.gz retention-days: 1 cluster-test: @@ -103,7 +112,8 @@ jobs: - uses: actions/download-artifact@v2 name: Download Binary Package with: - name: binary-package + # Only run cluster test on jdk8 + name: binary-package-8 path: ./ - name: Running cluster test run: | diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 71cd27e1e5..01146c0466 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -53,6 +53,9 @@ jobs: needs: paths-filter if: ${{ (needs.paths-filter.outputs.not-ignore == 'true') || (github.event_name == 'push') }} runs-on: ubuntu-latest + strategy: + matrix: + java: ['8', '11'] timeout-minutes: 30 steps: - uses: actions/checkout@v2 @@ -60,10 +63,10 @@ jobs: submodules: true - name: Sanity Check uses: ./.github/actions/sanity-check - - name: Set up JDK 1.8 + - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v2 with: - java-version: 8 + java-version: ${{ matrix.java }} distribution: 'adopt' - uses: actions/cache@v3 with: diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtilsTest.java index 7be1a8acb7..ab32a12a69 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtilsTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtilsTest.java @@ -28,26 +28,32 @@ import org.apache.hadoop.security.UserGroupInformation; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor("org.apache.dolphinscheduler.spi.utils.PropertyUtils") +@SuppressStaticInitializationFor( + value = {"org.apache.dolphinscheduler.spi.utils.PropertyUtils", "org.apache.hadoop.security.UserGroupInformation"} +) @PrepareForTest(value = {PropertyUtils.class, UserGroupInformation.class, CommonUtils.class, PasswordUtils.class}) +@PowerMockIgnore({"jdk.xml.*", "org.apache.hadoop.security.*"}) public class CommonUtilsTest { @Test public void testGetKerberosStartupState() { PowerMockito.mockStatic(CommonUtils.class); - PowerMockito.when(CommonUtils.getKerberosStartupState()).thenReturn(false); + PowerMockito.when(CommonUtils.getKerberosStartupState()).thenAnswer((Answer) invocation -> false); boolean kerberosStartupState = CommonUtils.getKerberosStartupState(); Assert.assertFalse(kerberosStartupState); PowerMockito.mockStatic(PropertyUtils.class); - PowerMockito.when(PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE)).thenReturn("HDFS"); - PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, true)).thenReturn(Boolean.TRUE); + PowerMockito.when(PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE)).thenAnswer((Answer) invocation -> "HDFS"); + PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, true)) + .thenAnswer((Answer) invocation -> Boolean.TRUE); kerberosStartupState = CommonUtils.getKerberosStartupState(); Assert.assertFalse(kerberosStartupState); } @@ -56,34 +62,43 @@ public class CommonUtilsTest { public void testLoadKerberosConf() { try { PowerMockito.mockStatic(PropertyUtils.class); - PowerMockito.when(PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE)).thenReturn("HDFS"); - PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)).thenReturn(Boolean.TRUE); - PowerMockito.when(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)).thenReturn("/opt/krb5.conf"); - PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)).thenReturn("hdfs-mycluster@ESZ.COM"); - PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)).thenReturn("/opt/hdfs.headless.keytab"); + PowerMockito.when(PropertyUtils.getUpperCaseString(Constants.RESOURCE_STORAGE_TYPE)).thenAnswer((Answer) invocation -> "HDFS"); + PowerMockito.when(PropertyUtils.getBoolean(Constants.HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false)) + .thenAnswer((Answer) invocation -> Boolean.TRUE); + PowerMockito.when(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)) + .thenAnswer((Answer) invocation -> "/opt/krb5.conf"); + PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)) + .thenAnswer((Answer) invocation -> "hdfs-mycluster@ESZ.COM"); + PowerMockito.when(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)) + .thenAnswer((Answer) invocation -> "/opt/hdfs.headless.keytab"); PowerMockito.mockStatic(UserGroupInformation.class); - boolean result = CommonUtils.loadKerberosConf(new Configuration()); + Configuration configuration = PowerMockito.mock(Configuration.class); + PowerMockito.whenNew(Configuration.class).withNoArguments().thenReturn(configuration); + + boolean result = CommonUtils.loadKerberosConf(configuration); Assert.assertTrue(result); CommonUtils.loadKerberosConf(null, null, null); } catch (Exception e) { - Assert.fail("load Kerberos Conf failed"); + Assert.fail("load Kerberos Conf failed" + e.getMessage()); } } @Test public void encodePassword() { PowerMockito.mockStatic(PropertyUtils.class); - PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)).thenReturn(Boolean.TRUE); + PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)) + .thenAnswer((Answer) invocation -> Boolean.TRUE); Assert.assertEquals("", PasswordUtils.encodePassword("")); Assert.assertEquals("bnVsbE1USXpORFUy", PasswordUtils.encodePassword("123456")); Assert.assertEquals("bnVsbElWRkJXbGhUVjBBPQ==", PasswordUtils.encodePassword("!QAZXSW@")); Assert.assertEquals("bnVsbE5XUm1aMlZ5S0VBPQ==", PasswordUtils.encodePassword("5dfger(@")); - PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)).thenReturn(Boolean.FALSE); + PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)) + .thenAnswer((Answer) invocation -> Boolean.FALSE); Assert.assertEquals("", PasswordUtils.encodePassword("")); Assert.assertEquals("123456", PasswordUtils.encodePassword("123456")); @@ -95,7 +110,8 @@ public class CommonUtilsTest { @Test public void decodePassword() { PowerMockito.mockStatic(PropertyUtils.class); - PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)).thenReturn(Boolean.TRUE); + PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)) + .thenAnswer((Answer) invocation -> Boolean.TRUE); PropertyUtils.setValue(DATASOURCE_ENCRYPTION_ENABLE, "true"); @@ -109,7 +125,8 @@ public class CommonUtilsTest { Assert.assertEquals("!QAZXSW@", PasswordUtils.decodePassword("bnVsbElWRkJXbGhUVjBBPQ==")); Assert.assertEquals("5dfger(@", PasswordUtils.decodePassword("bnVsbE5XUm1aMlZ5S0VBPQ==")); - PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)).thenReturn(Boolean.FALSE); + PowerMockito.when(PropertyUtils.getBoolean(DATASOURCE_ENCRYPTION_ENABLE, false)) + .thenAnswer((Answer) invocation -> Boolean.FALSE); PowerMockito.when(PasswordUtils.decodePassword("123456")).thenReturn("123456"); PowerMockito.when(PasswordUtils.decodePassword("!QAZXSW@")).thenReturn("!QAZXSW@"); diff --git a/dolphinscheduler-registry/pom.xml b/dolphinscheduler-registry/pom.xml index 89e0565924..b8f08b49c1 100644 --- a/dolphinscheduler-registry/pom.xml +++ b/dolphinscheduler-registry/pom.xml @@ -41,7 +41,6 @@ javax.annotation javax.annotation-api - provided