|
|
@ -17,66 +17,75 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.server.master.runner; |
|
|
|
package org.apache.dolphinscheduler.server.master.runner; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
import org.apache.dolphinscheduler.server.master.consumer.TaskPriorityQueueConsumer; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.master.dispatch.ExecutorDispatcher; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.master.dispatch.executor.NettyExecutorManager; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.registry.DependencyConfig; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperNodeManager; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter; |
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter; |
|
|
|
import org.apache.dolphinscheduler.server.zk.SpringZKServer; |
|
|
|
|
|
|
|
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.apache.dolphinscheduler.service.zk.CuratorZookeeperClient; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; |
|
|
|
import org.junit.Before; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
|
|
|
|
import org.powermock.api.mockito.PowerMockito; |
|
|
|
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
|
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import com.google.common.collect.Sets; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
|
|
@RunWith(MockitoJUnitRunner.Silent.class) |
|
|
|
@ContextConfiguration(classes={DependencyConfig.class, SpringApplicationContext.class, SpringZKServer.class, |
|
|
|
@PrepareForTest(MasterTaskExecThread.class) |
|
|
|
NettyExecutorManager.class, ExecutorDispatcher.class, ZookeeperRegistryCenter.class, TaskPriorityQueueConsumer.class, |
|
|
|
|
|
|
|
ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, CuratorZookeeperClient.class}) |
|
|
|
|
|
|
|
public class MasterTaskExecThreadTest { |
|
|
|
public class MasterTaskExecThreadTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MasterTaskExecThread masterTaskExecThread; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SpringApplicationContext springApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ZookeeperRegistryCenter zookeeperRegistryCenter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
|
|
public void setUp() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationContext applicationContext = PowerMockito.mock(ApplicationContext.class); |
|
|
|
|
|
|
|
this.springApplicationContext = new SpringApplicationContext(); |
|
|
|
|
|
|
|
springApplicationContext.setApplicationContext(applicationContext); |
|
|
|
|
|
|
|
this.zookeeperRegistryCenter = PowerMockito.mock(ZookeeperRegistryCenter.class); |
|
|
|
|
|
|
|
PowerMockito.when(SpringApplicationContext.getBean(ZookeeperRegistryCenter.class)) |
|
|
|
|
|
|
|
.thenReturn(this.zookeeperRegistryCenter); |
|
|
|
|
|
|
|
this.masterTaskExecThread = new MasterTaskExecThread(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testExistsValidWorkerGroup1(){ |
|
|
|
public void testExistsValidWorkerGroup1(){ |
|
|
|
ZookeeperRegistryCenter zookeeperRegistryCenter = Mockito.mock(ZookeeperRegistryCenter.class); |
|
|
|
|
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(null); |
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(Sets.newHashSet()); |
|
|
|
MasterTaskExecThread masterTaskExecThread = new MasterTaskExecThread(null); |
|
|
|
boolean b = masterTaskExecThread.existsValidWorkerGroup("default"); |
|
|
|
masterTaskExecThread.existsValidWorkerGroup("default"); |
|
|
|
Assert.assertFalse(b); |
|
|
|
} |
|
|
|
} |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testExistsValidWorkerGroup2(){ |
|
|
|
public void testExistsValidWorkerGroup2(){ |
|
|
|
ZookeeperRegistryCenter zookeeperRegistryCenter = Mockito.mock(ZookeeperRegistryCenter.class); |
|
|
|
|
|
|
|
Set<String> workerGorups = new HashSet<>(); |
|
|
|
Set<String> workerGorups = new HashSet<>(); |
|
|
|
workerGorups.add("test1"); |
|
|
|
workerGorups.add("test1"); |
|
|
|
workerGorups.add("test2"); |
|
|
|
workerGorups.add("test2"); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(workerGorups); |
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(workerGorups); |
|
|
|
MasterTaskExecThread masterTaskExecThread = new MasterTaskExecThread(null); |
|
|
|
boolean b = masterTaskExecThread.existsValidWorkerGroup("default"); |
|
|
|
masterTaskExecThread.existsValidWorkerGroup("default"); |
|
|
|
Assert.assertFalse(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testExistsValidWorkerGroup3(){ |
|
|
|
public void testExistsValidWorkerGroup3(){ |
|
|
|
ZookeeperRegistryCenter zookeeperRegistryCenter = Mockito.mock(ZookeeperRegistryCenter.class); |
|
|
|
|
|
|
|
Set<String> workerGorups = new HashSet<>(); |
|
|
|
Set<String> workerGorups = new HashSet<>(); |
|
|
|
workerGorups.add("test1"); |
|
|
|
workerGorups.add("test1"); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(workerGorups); |
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupDirectly()).thenReturn(workerGorups); |
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupNodesDirectly("test1")).thenReturn(workerGorups); |
|
|
|
Mockito.when(zookeeperRegistryCenter.getWorkerGroupNodesDirectly("test1")).thenReturn(workerGorups); |
|
|
|
MasterTaskExecThread masterTaskExecThread = new MasterTaskExecThread(null); |
|
|
|
boolean b = masterTaskExecThread.existsValidWorkerGroup("test1"); |
|
|
|
masterTaskExecThread.existsValidWorkerGroup("test1"); |
|
|
|
Assert.assertTrue(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -84,10 +93,8 @@ public class MasterTaskExecThreadTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProcessService processService = Mockito.mock(ProcessService.class); |
|
|
|
ProcessService processService = Mockito.mock(ProcessService.class); |
|
|
|
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); |
|
|
|
Mockito.when(this.springApplicationContext.getBean(ProcessService.class)) |
|
|
|
SpringApplicationContext springApplicationContext = new SpringApplicationContext(); |
|
|
|
.thenReturn(processService); |
|
|
|
springApplicationContext.setApplicationContext(applicationContext); |
|
|
|
|
|
|
|
Mockito.when(applicationContext.getBean(ProcessService.class)).thenReturn(processService); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaskInstance taskInstance = getTaskInstance(); |
|
|
|
TaskInstance taskInstance = getTaskInstance(); |
|
|
|
Mockito.when(processService.findTaskInstanceById(252612)) |
|
|
|
Mockito.when(processService.findTaskInstanceById(252612)) |
|
|
|