-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement][server] WATERDROP task plug-in optimization in switch c…
…ase code cleaning. (#3652) * WATERDROP switch case code checkstyle. * add TaskManagerTest. * TaskManagerTest checkstyle. * TaskManagerTest checkstyle. * TaskManagerTest add pom maven-surefire * TaskManagerTest update.
- Loading branch information
1 parent
565b8d3
commit fad2852
Showing
4 changed files
with
141 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...-server/src/test/java/org/apache/dolphinscheduler/server/worker/task/TaskManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dolphinscheduler.server.worker.task; | ||
|
||
import org.apache.dolphinscheduler.common.utils.LoggerUtils; | ||
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; | ||
import org.apache.dolphinscheduler.server.worker.cache.impl.TaskExecutionContextCacheManagerImpl; | ||
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({SpringApplicationContext.class}) | ||
public class TaskManagerTest { | ||
|
||
private TaskExecutionContext taskExecutionContext; | ||
|
||
private Logger taskLogger; | ||
|
||
private TaskExecutionContextCacheManagerImpl taskExecutionContextCacheManager; | ||
|
||
@Before | ||
public void before() { | ||
// init task execution context, logger | ||
taskExecutionContext = new TaskExecutionContext(); | ||
taskExecutionContext.setProcessId(12345); | ||
taskExecutionContext.setProcessDefineId(1); | ||
taskExecutionContext.setProcessInstanceId(1); | ||
taskExecutionContext.setTaskInstanceId(1); | ||
taskExecutionContext.setTaskType(""); | ||
taskExecutionContext.setFirstSubmitTime(new Date()); | ||
taskExecutionContext.setDelayTime(0); | ||
taskExecutionContext.setLogPath("/tmp/test.log"); | ||
taskExecutionContext.setHost("localhost"); | ||
taskExecutionContext.setExecutePath("/tmp/dolphinscheduler/exec/process/1/2/3/4"); | ||
|
||
taskLogger = LoggerFactory.getLogger(LoggerUtils.buildTaskId( | ||
LoggerUtils.TASK_LOGGER_INFO_PREFIX, | ||
taskExecutionContext.getProcessDefineId(), | ||
taskExecutionContext.getProcessInstanceId(), | ||
taskExecutionContext.getTaskInstanceId() | ||
)); | ||
|
||
taskExecutionContextCacheManager = new TaskExecutionContextCacheManagerImpl(); | ||
taskExecutionContextCacheManager.cacheTaskExecutionContext(taskExecutionContext); | ||
|
||
PowerMockito.mockStatic(SpringApplicationContext.class); | ||
PowerMockito.when(SpringApplicationContext.getBean(TaskExecutionContextCacheManagerImpl.class)) | ||
.thenReturn(taskExecutionContextCacheManager); | ||
} | ||
|
||
@Test | ||
public void testNewTask() { | ||
|
||
taskExecutionContext.setTaskType("SHELL"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("WATERDROP"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("HTTP"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("MR"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("SPARK"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("FLINK"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("PYTHON"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("DATAX"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
taskExecutionContext.setTaskType("SQOOP"); | ||
Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
//taskExecutionContext.setTaskType(null); | ||
//Assert.assertNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
//taskExecutionContext.setTaskType("XXX"); | ||
//Assert.assertNotNull(TaskManager.newTask(taskExecutionContext,taskLogger)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters