|
|
@ -17,21 +17,26 @@ |
|
|
|
package org.apache.dolphinscheduler.server.worker.processor; |
|
|
|
package org.apache.dolphinscheduler.server.worker.processor; |
|
|
|
|
|
|
|
|
|
|
|
import io.netty.channel.Channel; |
|
|
|
import io.netty.channel.Channel; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.thread.Stopper; |
|
|
|
import org.apache.dolphinscheduler.remote.NettyRemotingClient; |
|
|
|
import org.apache.dolphinscheduler.remote.NettyRemotingClient; |
|
|
|
import org.apache.dolphinscheduler.remote.NettyRemotingServer; |
|
|
|
import org.apache.dolphinscheduler.remote.NettyRemotingServer; |
|
|
|
import org.apache.dolphinscheduler.remote.command.CommandType; |
|
|
|
import org.apache.dolphinscheduler.remote.command.CommandType; |
|
|
|
import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand; |
|
|
|
import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.remote.command.TaskExecuteResponseCommand; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyClientConfig; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyClientConfig; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyServerConfig; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyServerConfig; |
|
|
|
import org.apache.dolphinscheduler.remote.utils.Host; |
|
|
|
import org.apache.dolphinscheduler.remote.utils.Host; |
|
|
|
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
|
|
|
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
|
|
|
import org.apache.dolphinscheduler.server.master.processor.TaskAckProcessor; |
|
|
|
import org.apache.dolphinscheduler.server.master.processor.TaskAckProcessor; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.master.processor.TaskResponseProcessor; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.server.master.processor.queue.TaskResponseService; |
|
|
|
import org.apache.dolphinscheduler.server.master.registry.MasterRegistry; |
|
|
|
import org.apache.dolphinscheduler.server.master.registry.MasterRegistry; |
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperNodeManager; |
|
|
|
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.worker.config.WorkerConfig; |
|
|
|
import org.apache.dolphinscheduler.server.worker.config.WorkerConfig; |
|
|
|
import org.apache.dolphinscheduler.server.worker.registry.WorkerRegistry; |
|
|
|
import org.apache.dolphinscheduler.server.worker.registry.WorkerRegistry; |
|
|
|
import org.apache.dolphinscheduler.server.zk.SpringZKServer; |
|
|
|
import org.apache.dolphinscheduler.server.zk.SpringZKServer; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
@ -47,9 +52,10 @@ import java.util.Date; |
|
|
|
* test task call back service |
|
|
|
* test task call back service |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
|
|
@ContextConfiguration(classes={TaskCallbackServiceTestConfig.class, SpringZKServer.class, MasterRegistry.class, WorkerRegistry.class, |
|
|
|
@ContextConfiguration(classes={TaskCallbackServiceTestConfig.class, SpringZKServer.class, SpringApplicationContext.class, MasterRegistry.class, WorkerRegistry.class, |
|
|
|
ZookeeperRegistryCenter.class, MasterConfig.class, WorkerConfig.class, |
|
|
|
ZookeeperRegistryCenter.class, MasterConfig.class, WorkerConfig.class, |
|
|
|
ZookeeperCachedOperator.class, ZookeeperConfig.class, ZookeeperNodeManager.class, TaskCallbackService.class}) |
|
|
|
ZookeeperCachedOperator.class, ZookeeperConfig.class, ZookeeperNodeManager.class, TaskCallbackService.class, |
|
|
|
|
|
|
|
TaskResponseService.class, TaskAckProcessor.class,TaskResponseProcessor.class}) |
|
|
|
public class TaskCallbackServiceTest { |
|
|
|
public class TaskCallbackServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -58,12 +64,22 @@ public class TaskCallbackServiceTest { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private MasterRegistry masterRegistry; |
|
|
|
private MasterRegistry masterRegistry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private TaskAckProcessor taskAckProcessor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private TaskResponseProcessor taskResponseProcessor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* send ack test |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSendAck(){ |
|
|
|
public void testSendAck() throws Exception{ |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, Mockito.mock(TaskAckProcessor.class)); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, taskAckProcessor); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
|
|
|
|
|
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
@ -75,22 +91,64 @@ public class TaskCallbackServiceTest { |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stopper.stop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
|
|
|
|
nettyRemotingServer.close(); |
|
|
|
nettyRemotingServer.close(); |
|
|
|
nettyRemotingClient.close(); |
|
|
|
nettyRemotingClient.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* send result test |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testSendResult() throws Exception{ |
|
|
|
|
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
|
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
|
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
|
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_RESPONSE, taskResponseProcessor); |
|
|
|
|
|
|
|
nettyRemotingServer.start(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
|
|
|
|
NettyRemotingClient nettyRemotingClient = new NettyRemotingClient(clientConfig); |
|
|
|
|
|
|
|
Channel channel = nettyRemotingClient.getChannel(Host.of("localhost:30000")); |
|
|
|
|
|
|
|
taskCallbackService.addRemoteChannel(1, new NettyRemoteChannel(channel, 1)); |
|
|
|
|
|
|
|
TaskExecuteResponseCommand responseCommand = new TaskExecuteResponseCommand(); |
|
|
|
|
|
|
|
responseCommand.setTaskInstanceId(1); |
|
|
|
|
|
|
|
responseCommand.setEndTime(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
taskCallbackService.sendResult(1, responseCommand.convert2Command()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stopper.stop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nettyRemotingServer.close(); |
|
|
|
|
|
|
|
nettyRemotingClient.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
public void testSendAckWithIllegalArgumentException(){ |
|
|
|
public void testSendAckWithIllegalArgumentException(){ |
|
|
|
TaskExecuteAckCommand ackCommand = Mockito.mock(TaskExecuteAckCommand.class); |
|
|
|
TaskExecuteAckCommand ackCommand = Mockito.mock(TaskExecuteAckCommand.class); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
|
|
|
|
Stopper.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class) |
|
|
|
@Test(expected = IllegalStateException.class) |
|
|
|
public void testSendAckWithIllegalStateException1(){ |
|
|
|
public void testSendAckWithIllegalStateException1(){ |
|
|
|
|
|
|
|
masterRegistry.registry(); |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, Mockito.mock(TaskAckProcessor.class)); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, taskAckProcessor); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
|
|
|
|
|
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
@ -103,7 +161,21 @@ public class TaskCallbackServiceTest { |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
nettyRemotingServer.close(); |
|
|
|
nettyRemotingServer.close(); |
|
|
|
|
|
|
|
|
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stopper.stop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalStateException.class) |
|
|
|
@Test(expected = IllegalStateException.class) |
|
|
@ -112,7 +184,7 @@ public class TaskCallbackServiceTest { |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
final NettyServerConfig serverConfig = new NettyServerConfig(); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
serverConfig.setListenPort(30000); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, Mockito.mock(TaskAckProcessor.class)); |
|
|
|
nettyRemotingServer.registerProcessor(CommandType.TASK_EXECUTE_ACK, taskAckProcessor); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
|
|
|
|
|
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
final NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
@ -125,6 +197,20 @@ public class TaskCallbackServiceTest { |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
ackCommand.setStartTime(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
nettyRemotingServer.close(); |
|
|
|
nettyRemotingServer.close(); |
|
|
|
|
|
|
|
|
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
taskCallbackService.sendAck(1, ackCommand.convert2Command()); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Stopper.stop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|