|
|
@ -39,7 +39,6 @@ import org.springframework.context.ApplicationContext; |
|
|
|
@PrepareForTest({TaskExecuteThread.class}) |
|
|
|
@PrepareForTest({TaskExecuteThread.class}) |
|
|
|
public class TaskExecuteThreadTest { |
|
|
|
public class TaskExecuteThreadTest { |
|
|
|
|
|
|
|
|
|
|
|
TaskExecutionContext taskExecutionContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaskCallbackService taskCallbackService; |
|
|
|
TaskCallbackService taskCallbackService; |
|
|
|
|
|
|
|
|
|
|
@ -51,7 +50,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(); |
|
|
@ -63,6 +62,7 @@ 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,22 +77,128 @@ 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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
//ignore
|
|
|
|
|
|
|
|
} |
|
|
|
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false); |
|
|
|
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false); |
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
|
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null); |
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null); |
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
try { |
|
|
|
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
//ignore
|
|
|
|
|
|
|
|
} |
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/"); |
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/"); |
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
try { |
|
|
|
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
//ignore
|
|
|
|
|
|
|
|
} |
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath"); |
|
|
|
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath"); |
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
try { |
|
|
|
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
//ignore
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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); |
|
|
|
taskExecuteThread.clearTaskExecPath(); |
|
|
|
try { |
|
|
|
|
|
|
|
taskExecuteThread.run(); |
|
|
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
//ignore
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|