From e8c7b7ae629deecc8c5982701b2506f1d5bdc326 Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Sat, 6 Aug 2022 18:27:32 +0800 Subject: [PATCH 1/8] [Improvement][UT] Upgrade jUnit to 5.+ (#10976) --- pom.xml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0efadbdb7fa5..af5736bb4a6b 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ UTF-8 2.6.1 1.8 - 4.13.1 + 4.13.2 3.1.12 3.3 3.3.0 @@ -309,6 +309,13 @@ dolphinscheduler-tools ${project.version} + + org.junit + junit-bom + 5.9.0 + pom + import + @@ -320,12 +327,33 @@ For example: annotation processors, test dependencies that are used by most of the submodules. --> + + + + + + + + org.junit.jupiter + junit-jupiter-api + test + junit junit ${junit.version} test + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine + test + org.jacoco org.jacoco.agent From 580cad7ba11fc9bf8dee1cd6977bd8fe8d9b815f Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Mon, 8 Aug 2022 14:49:04 +0800 Subject: [PATCH 2/8] Refactor AlertServerTest with jUnit-5 as an example --- .../dolphinscheduler-alert-server/pom.xml | 13 +++-- .../alert/AlertServerTest.java | 50 +++++++++---------- pom.xml | 34 +++++++------ 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml index 587619f9f110..5faf9e05cb78 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml @@ -26,7 +26,6 @@ dolphinscheduler-alert-server jar ${project.artifactId} - @@ -73,17 +72,17 @@ org.apache.dolphinscheduler dolphinscheduler-alert-webexteams - + org.apache.dolphinscheduler dolphinscheduler-alert-telegram - + org.apache.dolphinscheduler dolphinscheduler-dao - + com.google.guava guava @@ -103,14 +102,14 @@ mockito-core test - + org.mockito mockito-inline test - + @@ -144,7 +143,7 @@ - + docker diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java index e739ff4d03e7..63381a2619ed 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -17,57 +17,53 @@ package org.apache.dolphinscheduler.alert; -import junit.framework.TestCase; -import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.PluginDao; -import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.remote.NettyRemotingServer; import org.apache.dolphinscheduler.remote.config.NettyServerConfig; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.powermock.reflect.Whitebox; -import java.util.ArrayList; -import java.util.List; +@ExtendWith(MockitoExtension.class) +public class AlertServerTest { - -@RunWith(MockitoJUnitRunner.class) -public class AlertServerTest extends TestCase { - - @InjectMocks - private AlertServer alertServer; - @Mock private PluginDao pluginDao; - + @Mock private AlertConfig alertConfig; @Mock private AlertSenderService alertSenderService; - - @Test - public void testStart() { - Mockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); + @InjectMocks + private AlertServer alertServer; + + @BeforeEach + void init() { + Mockito.lenient().when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); - Mockito.when(alertConfig.getPort()).thenReturn(50052); + Mockito.lenient().when(alertConfig.getPort()).thenReturn(50052); Mockito.doNothing().when(alertSenderService).start(); + } + @Test + public void alertServerStartSuccessfully() { + alertServer.run(null); - + NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "nettyRemotingServer"); - + NettyServerConfig nettyServerConfig = Whitebox.getInternalState(nettyRemotingServer, "serverConfig"); - - Assert.assertEquals(50052, nettyServerConfig.getListenPort()); + + Assertions.assertEquals(50052, nettyServerConfig.getListenPort()); } } diff --git a/pom.xml b/pom.xml index af5736bb4a6b..a125d258170d 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ 2.5.3 2.10.3 2.4 - 2.22.1 + 3.0.0-M6 3.1.1 3.2.1 2.2.0 @@ -327,12 +327,6 @@ For example: annotation processors, test dependencies that are used by most of the submodules. --> - - - - - - org.junit.jupiter junit-jupiter-api @@ -354,6 +348,18 @@ junit-vintage-engine test + + org.mockito + mockito-core + 2.21.0 + test + + + org.mockito + mockito-junit-jupiter + 2.23.0 + test + org.jacoco org.jacoco.agent @@ -609,13 +615,13 @@ ${project.build.directory}/jacoco.exec - - - org.apache.maven.surefire - surefire-junit4 - ${maven-surefire-plugin.version} - - + + + + + + + From a4223be477260c85b17f05fd5e426dc7c538a2ee Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Mon, 8 Aug 2022 22:43:27 +0800 Subject: [PATCH 3/8] Resolve dependency conflicts --- dolphinscheduler-api/pom.xml | 39 ++++++++++--------- .../TaskInstanceControllerTest.java | 3 ++ pom.xml | 4 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/dolphinscheduler-api/pom.xml b/dolphinscheduler-api/pom.xml index 6b8fc764f061..51b73e1c15f3 100644 --- a/dolphinscheduler-api/pom.xml +++ b/dolphinscheduler-api/pom.xml @@ -26,7 +26,6 @@ dolphinscheduler-api jar ${project.artifactId} - @@ -38,7 +37,6 @@ - @@ -55,18 +53,18 @@ org.apache.dolphinscheduler dolphinscheduler-meter - + org.apache.dolphinscheduler dolphinscheduler-datasource-all ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-task-all - + org.apache.dolphinscheduler dolphinscheduler-ui @@ -79,7 +77,7 @@ org.apache.dolphinscheduler dolphinscheduler-scheduler-quartz - + org.codehaus.janino janino @@ -103,7 +101,7 @@ - + org.springframework.boot @@ -119,7 +117,7 @@ - + org.springframework.boot spring-boot-starter-aop @@ -130,34 +128,40 @@ - + org.springframework spring-context - + io.springfox springfox-boot-starter - + org.hibernate.validator hibernate-validator - + io.fabric8 kubernetes-client - + org.springframework.boot spring-boot-starter-test test - + + + org.mockito + mockito-core + test + + org.apache.curator curator-test @@ -169,13 +173,13 @@ - + net.sf.py4j py4j - + org.springframework.ldap spring-ldap-core @@ -192,7 +196,6 @@ test - @@ -237,7 +240,7 @@ - + docker diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java index 7090a2f3727e..a9a908b21afa 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java @@ -43,14 +43,17 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +@RunWith(MockitoJUnitRunner.class) public class TaskInstanceControllerTest extends AbstractControllerTest { @InjectMocks diff --git a/pom.xml b/pom.xml index a125d258170d..c72e39a92bd2 100644 --- a/pom.xml +++ b/pom.xml @@ -351,13 +351,13 @@ org.mockito mockito-core - 2.21.0 + 3.9.0 test org.mockito mockito-junit-jupiter - 2.23.0 + 3.9.0 test From 83ec375c3caff77747b57ea0abc228635e789baf Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Mon, 8 Aug 2022 22:48:55 +0800 Subject: [PATCH 4/8] Remove redundant commented code --- pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index c72e39a92bd2..0d0cd219e0c1 100644 --- a/pom.xml +++ b/pom.xml @@ -615,13 +615,6 @@ ${project.build.directory}/jacoco.exec - - - - - - - From 03311d63c81825233fb14126304be59898de833f Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Mon, 8 Aug 2022 23:50:32 +0800 Subject: [PATCH 5/8] Fix code style --- dolphinscheduler-api/pom.xml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/dolphinscheduler-api/pom.xml b/dolphinscheduler-api/pom.xml index 51b73e1c15f3..efaac0b7d53c 100644 --- a/dolphinscheduler-api/pom.xml +++ b/dolphinscheduler-api/pom.xml @@ -53,18 +53,18 @@ org.apache.dolphinscheduler dolphinscheduler-meter - + org.apache.dolphinscheduler dolphinscheduler-datasource-all ${project.version} - + org.apache.dolphinscheduler dolphinscheduler-task-all - + org.apache.dolphinscheduler dolphinscheduler-ui @@ -77,7 +77,7 @@ org.apache.dolphinscheduler dolphinscheduler-scheduler-quartz - + org.codehaus.janino janino @@ -101,7 +101,7 @@ - + org.springframework.boot @@ -117,7 +117,7 @@ - + org.springframework.boot spring-boot-starter-aop @@ -128,40 +128,40 @@ - + org.springframework spring-context - + io.springfox springfox-boot-starter - + org.hibernate.validator hibernate-validator - + io.fabric8 kubernetes-client - + org.springframework.boot spring-boot-starter-test test - + org.mockito mockito-core test - + org.apache.curator curator-test @@ -173,13 +173,13 @@ - + net.sf.py4j py4j - + org.springframework.ldap spring-ldap-core @@ -240,7 +240,7 @@ - + docker From b8aa973fb83c9e7daba36cc1a7242cc1b03da5eb Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Wed, 10 Aug 2022 22:30:29 +0800 Subject: [PATCH 6/8] Remove jUnit4 dependency --- .../dolphinscheduler-alert-server/pom.xml | 12 +++---- .../TaskInstanceControllerTest.java | 15 ++++----- pom.xml | 32 +++++++++++-------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml index 5faf9e05cb78..eed7bf8a49c7 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml @@ -72,17 +72,17 @@ org.apache.dolphinscheduler dolphinscheduler-alert-webexteams - + org.apache.dolphinscheduler dolphinscheduler-alert-telegram - + org.apache.dolphinscheduler dolphinscheduler-dao - + com.google.guava guava @@ -102,14 +102,14 @@ mockito-core test - + org.mockito mockito-inline test - + @@ -143,7 +143,7 @@ - + docker diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java index a9a908b21afa..b73a21302d8b 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java @@ -43,17 +43,14 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -@RunWith(MockitoJUnitRunner.class) public class TaskInstanceControllerTest extends AbstractControllerTest { @InjectMocks @@ -74,9 +71,11 @@ public void testQueryTaskListPaging() { result.setMsg(Status.SUCCESS.getMsg()); when(taskInstanceService.queryTaskListPaging(any(), eq(1L), eq(1), eq(""), eq(""), eq(""), eq(""), any(), any(), - eq(""), Mockito.any(), eq("192.168.xx.xx"), eq(TaskExecuteType.BATCH), any(), any())).thenReturn(result); + eq(""), Mockito.any(), eq("192.168.xx.xx"), eq(TaskExecuteType.BATCH), any(), any())) + .thenReturn(result); Result taskResult = taskInstanceController.queryTaskListPaging(null, 1L, 1, "", "", "", - "", "", TaskExecutionStatus.SUCCESS, "192.168.xx.xx", "2020-01-01 00:00:00", "2020-01-02 00:00:00", TaskExecuteType.BATCH, pageNo, pageSize); + "", "", TaskExecutionStatus.SUCCESS, "192.168.xx.xx", "2020-01-01 00:00:00", "2020-01-02 00:00:00", + TaskExecuteType.BATCH, pageNo, pageSize); Assert.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), taskResult.getCode()); } @@ -94,9 +93,9 @@ public void testForceTaskSuccess() throws Exception { MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/task-instance/force-success", "cxc_1113") .header(SESSION_ID, sessionId) .params(paramsMap)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); diff --git a/pom.xml b/pom.xml index 0d0cd219e0c1..5544a140559f 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,9 @@ UTF-8 2.6.1 1.8 - 4.13.2 + 5.9.0 + + 3.9.0 3.1.12 3.3 3.3.0 @@ -312,7 +314,7 @@ org.junit junit-bom - 5.9.0 + ${junit.version} pom import @@ -330,34 +332,36 @@ org.junit.jupiter junit-jupiter-api - test - - - junit - junit ${junit.version} test - - org.junit.jupiter - junit-jupiter-engine - test - org.junit.vintage junit-vintage-engine + ${junit.version} test + + + + + + + + + + + org.mockito mockito-core - 3.9.0 + ${mockito.version} test org.mockito mockito-junit-jupiter - 3.9.0 + ${mockito.version} test From 1bdfea5d200f75738d980fe6b650acbf5ceeecfa Mon Sep 17 00:00:00 2001 From: EricGao888 Date: Thu, 11 Aug 2022 00:47:03 +0800 Subject: [PATCH 7/8] Fix transitive dependency bug --- pom.xml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pom.xml b/pom.xml index 5544a140559f..ef784156f71c 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,6 @@ 2.6.1 1.8 5.9.0 - 3.9.0 3.1.12 3.3 @@ -332,26 +331,13 @@ org.junit.jupiter junit-jupiter-api - ${junit.version} test org.junit.vintage junit-vintage-engine - ${junit.version} test - - - - - - - - - - - org.mockito mockito-core From ae6dd2e275e8f77a937e8d1013901496f506375e Mon Sep 17 00:00:00 2001 From: Eric Gao Date: Sat, 13 Aug 2022 10:05:03 +0800 Subject: [PATCH 8/8] [Feature][Style] Enable spotless to manage imports (#11458) --- dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml index eed7bf8a49c7..b044e9488131 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml @@ -157,4 +157,5 @@ +