felix.Wang 4 years ago
parent
commit
9e6715f1b7
  1. 116
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java

116
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java

@ -39,6 +39,7 @@ import org.springframework.context.ApplicationContext;
@PrepareForTest({TaskExecuteThread.class}) @PrepareForTest({TaskExecuteThread.class})
public class TaskExecuteThreadTest { public class TaskExecuteThreadTest {
TaskExecutionContext taskExecutionContext;
TaskCallbackService taskCallbackService; TaskCallbackService taskCallbackService;
@ -50,7 +51,7 @@ public class TaskExecuteThreadTest {
@Before @Before
public void init() throws Exception { public void init() throws Exception {
taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class);
taskCallbackService = PowerMockito.mock(TaskCallbackService.class); taskCallbackService = PowerMockito.mock(TaskCallbackService.class);
applicationContext = PowerMockito.mock(ApplicationContext.class); applicationContext = PowerMockito.mock(ApplicationContext.class);
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); SpringApplicationContext springApplicationContext = new SpringApplicationContext();
@ -62,7 +63,6 @@ public class TaskExecuteThreadTest {
@Test @Test
public void testTaskClearExecPath() throws Exception { public void testTaskClearExecPath() throws Exception {
processService = mock(ProcessService.class); processService = mock(ProcessService.class);
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); SpringApplicationContext springApplicationContext = new SpringApplicationContext();
springApplicationContext.setApplicationContext(applicationContext); springApplicationContext.setApplicationContext(applicationContext);
@ -77,128 +77,42 @@ public class TaskExecuteThreadTest {
@Test @Test
public void testClearTaskExecPath() { public void testClearTaskExecPath() {
String taskJson = "{\n"
+ " \"conditionResult\": {\n"
+ " \"failedNode\": [\n"
+ " \"\"\n"
+ " ],\n"
+ " \"successNode\": [\n"
+ " \"\"\n"
+ " ]\n"
+ " },\n"
+ " \"delayTime\": 0,\n"
+ " \"depList\": [\n"
+ " \"testlog1\"\n"
+ " ],\n"
+ " \"dependence\": {},\n"
+ " \"desc\": null,\n"
+ " \"extras\": null,\n"
+ " \"id\": \"tasks-31779\",\n"
+ " \"loc\": null,\n"
+ " \"maxRetryTimes\": 0,\n"
+ " \"name\": \"testlog2\",\n"
+ " \"params\": {\n"
+ " \"localParams\": [],\n"
+ " \"rawScript\": \"echo \\\"123123\\\"\",\n"
+ " \"resourceList\": []\n"
+ " },\n"
+ " \"preTasks\": [\n"
+ " \"testlog1\"\n"
+ " ],\n"
+ " \"retryInterval\": 1,\n"
+ " \"runFlag\": \"NORMAL\",\n"
+ " \"taskInstancePriority\": \"MEDIUM\",\n"
+ " \"timeout\": {\n"
+ " \"enable\": false,\n"
+ " \"interval\": null,\n"
+ " \"strategy\": \"\"\n"
+ " },\n"
+ " \"type\": \"SHELL\",\n"
+ " \"workerGroup\": \"default\",\n"
+ " \"workerGroupId\": null\n"
+ "}";
TaskExecutionContext taskExecutionContext = new TaskExecutionContext();
taskExecutionContext.setTaskJson(taskJson);
TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService); TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService);
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false);
Mockito.when(taskExecutionContext.getTaskJson()).thenThrow(new RuntimeException("测试异常后finally执行"));
try { try {
taskExecuteThread.run(); taskExecuteThread.run();
} catch (Exception ignore) { } catch (Exception ignored) {
//ignore //ignored
} }
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false);
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null); Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null);
try { try {
taskExecuteThread.run(); taskExecuteThread.run();
} catch (Exception ignore) { } catch (Exception ignored) {
//ignore //ignored
} }
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/"); Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/");
try { try {
taskExecuteThread.run(); taskExecuteThread.run();
} catch (Exception ignore) { } catch (Exception ignored) {
//ignore //ignored
} }
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath"); Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath");
try { try {
taskExecuteThread.run(); taskExecuteThread.run();
} catch (Exception ignore) { } catch (Exception ignored) {
//ignore //ignored
} }
} }
@Test @Test
public void testNotClearTaskExecPath() { public void testNotClearTaskExecPath() {
String taskJson = "{\n"
+ " \"conditionResult\": {\n"
+ " \"failedNode\": [\n"
+ " \"\"\n"
+ " ],\n"
+ " \"successNode\": [\n"
+ " \"\"\n"
+ " ]\n"
+ " },\n"
+ " \"delayTime\": 0,\n"
+ " \"depList\": [\n"
+ " \"testlog1\"\n"
+ " ],\n"
+ " \"dependence\": {},\n"
+ " \"desc\": null,\n"
+ " \"extras\": null,\n"
+ " \"id\": \"tasks-31779\",\n"
+ " \"loc\": null,\n"
+ " \"maxRetryTimes\": 0,\n"
+ " \"name\": \"testlog2\",\n"
+ " \"params\": {\n"
+ " \"localParams\": [],\n"
+ " \"rawScript\": \"echo \\\"123123\\\"\",\n"
+ " \"resourceList\": []\n"
+ " },\n"
+ " \"preTasks\": [\n"
+ " \"testlog1\"\n"
+ " ],\n"
+ " \"retryInterval\": 1,\n"
+ " \"runFlag\": \"NORMAL\",\n"
+ " \"taskInstancePriority\": \"MEDIUM\",\n"
+ " \"timeout\": {\n"
+ " \"enable\": false,\n"
+ " \"interval\": null,\n"
+ " \"strategy\": \"\"\n"
+ " },\n"
+ " \"type\": \"SHELL\",\n"
+ " \"workerGroup\": \"default\",\n"
+ " \"workerGroupId\": null\n"
+ "}";
TaskExecutionContext taskExecutionContext = new TaskExecutionContext();
taskExecutionContext.setTaskJson(taskJson);
TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService); TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService);
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(true); Mockito.when(CommonUtils.isDevelopMode()).thenReturn(true);
try { taskExecuteThread.run();
taskExecuteThread.run();
} catch (Exception ignore) {
//ignore
}
} }
} }

Loading…
Cancel
Save