|
|
|
@ -39,7 +39,6 @@ import org.springframework.context.ApplicationContext;
|
|
|
|
|
@PrepareForTest({TaskExecuteThread.class}) |
|
|
|
|
public class TaskExecuteThreadTest { |
|
|
|
|
|
|
|
|
|
TaskExecutionContext taskExecutionContext; |
|
|
|
|
|
|
|
|
|
TaskCallbackService taskCallbackService; |
|
|
|
|
|
|
|
|
@ -51,7 +50,7 @@ public class TaskExecuteThreadTest {
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void init() throws Exception { |
|
|
|
|
taskExecutionContext = PowerMockito.mock(TaskExecutionContext.class); |
|
|
|
|
|
|
|
|
|
taskCallbackService = PowerMockito.mock(TaskCallbackService.class); |
|
|
|
|
applicationContext = PowerMockito.mock(ApplicationContext.class); |
|
|
|
|
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); |
|
|
|
@ -63,6 +62,7 @@ public class TaskExecuteThreadTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testTaskClearExecPath() throws Exception { |
|
|
|
|
processService = mock(ProcessService.class); |
|
|
|
|
|
|
|
|
|
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); |
|
|
|
|
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); |
|
|
|
|
springApplicationContext.setApplicationContext(applicationContext); |
|
|
|
@ -77,22 +77,128 @@ public class TaskExecuteThreadTest {
|
|
|
|
|
@Test |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
//ignore
|
|
|
|
|
} |
|
|
|
|
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false); |
|
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
|
|
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null); |
|
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
try { |
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
//ignore
|
|
|
|
|
} |
|
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/"); |
|
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
try { |
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
//ignore
|
|
|
|
|
} |
|
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath"); |
|
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
try { |
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
//ignore
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
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); |
|
|
|
|
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(true); |
|
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
try { |
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
//ignore
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|