felix.Wang 4 years ago
parent
commit
23d7c72703
  1. 5
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java
  2. 63
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThreadTest.java

5
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java

@ -18,6 +18,8 @@ package org.apache.dolphinscheduler.server.worker.runner;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.dolphinscheduler.common.enums.Event; import org.apache.dolphinscheduler.common.enums.Event;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
@ -155,7 +157,8 @@ public class TaskExecuteThread implements Runnable {
/** /**
* when task finish, clear execute path. * when task finish, clear execute path.
*/ */
private void clearTaskExecPath() { @VisibleForTesting
/*private*/ void clearTaskExecPath() {
logger.info("develop mode is: {}", CommonUtils.isDevelopMode()); logger.info("develop mode is: {}", CommonUtils.isDevelopMode());
if (!CommonUtils.isDevelopMode()) { if (!CommonUtils.isDevelopMode()) {

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

@ -17,29 +17,86 @@
package org.apache.dolphinscheduler.server.worker.runner; package org.apache.dolphinscheduler.server.worker.runner;
import static org.powermock.api.mockito.PowerMockito.mock;
import org.apache.dolphinscheduler.common.utils.CommonUtils;
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; import org.apache.dolphinscheduler.server.entity.TaskExecutionContext;
import org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContextCacheManagerImpl;
import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService; import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@RunWith(PowerMockRunner.class)
@PrepareForTest({TaskExecuteThread.class})
public class TaskExecuteThreadTest { public class TaskExecuteThreadTest {
TaskExecutionContext taskExecutionContext;
TaskCallbackService taskCallbackService;
ApplicationContext applicationContext;
TaskExecutionContextCacheManagerImpl taskExecutionContextCacheManager;
private ProcessService processService;
@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();
springApplicationContext.setApplicationContext(applicationContext);
taskExecutionContextCacheManager = new TaskExecutionContextCacheManagerImpl();
Mockito.when(applicationContext.getBean(TaskExecutionContextCacheManagerImpl.class)).thenReturn(taskExecutionContextCacheManager);
}
@Test @Test
public void testTaskClearExecPath() throws Exception { public void testTaskClearExecPath() throws Exception {
ProcessService processService = Mockito.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);
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService); Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService);
TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class); TaskExecutionContext taskExecutionContext = Mockito.mock(TaskExecutionContext.class);
TaskCallbackService taskCallbackService = Mockito.mock(TaskCallbackService.class); TaskCallbackService taskCallbackService = Mockito.mock(TaskCallbackService.class);
TaskExecuteThread taskExecuteThread = PowerMockito.spy(new TaskExecuteThread(taskExecutionContext, taskCallbackService)); TaskExecuteThread taskExecuteThread = PowerMockito.spy(new TaskExecuteThread(taskExecutionContext, taskCallbackService));
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/"); Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/");
PowerMockito.when(taskExecuteThread, "clearTaskExecPath");
}
@Test
public void testClearTaskExecPath() {
TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService);
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(false);
;
taskExecuteThread.clearTaskExecPath();
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn(null);
taskExecuteThread.clearTaskExecPath();
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/");
taskExecuteThread.clearTaskExecPath();
Mockito.when(taskExecutionContext.getExecutePath()).thenReturn("/data/test-testClearTaskExecPath");
taskExecuteThread.clearTaskExecPath();
}
@Test
public void testNotClearTaskExecPath() {
TaskExecuteThread taskExecuteThread = new TaskExecuteThread(taskExecutionContext, taskCallbackService);
Mockito.when(CommonUtils.isDevelopMode()).thenReturn(true);
;
taskExecuteThread.clearTaskExecPath();
} }
} }

Loading…
Cancel
Save