### Question:
NettyExecutorManager extends AbstractExecutorManager<Boolean> { @Override public Boolean execute(ExecutionContext context) throws ExecuteException { LinkedList<String> allNodes = new LinkedList<>(); Set<String> nodes = getAllNodes(context); if (nodes != null) { allNodes.addAll(nodes); } Command command = context.getCommand(); String startHostAddress = context.getHost().getAddress(); allNodes.remove(startHostAddress); allNodes.addFirst(startHostAddress); boolean success = false; for (String address : allNodes) { try { Host host = Host.of(address); doExecute(host, command); success = true; context.setHost(host); break; } catch (ExecuteException ex) { logger.error("retry execute command : {} host : {}", command, address); } } if (!success) { throw new ExecuteException("fail after try all nodes"); } return success; } NettyExecutorManager(); @PostConstruct void init(); @Override Boolean execute(ExecutionContext context); @Override void executeDirectly(ExecutionContext context); NettyRemotingClient getNettyRemotingClient();  }### Answer:
@Test public void testExecute() throws ExecuteException{ final NettyServerConfig serverConfig = new NettyServerConfig(); serverConfig.setListenPort(30000); NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(serverConfig); nettyRemotingServer.registerProcessor(org.apache.dolphinscheduler.remote.command.CommandType.TASK_EXECUTE_REQUEST, new TaskExecuteProcessor()); nettyRemotingServer.start(); TaskInstance taskInstance = Mockito.mock(TaskInstance.class); ProcessDefinition processDefinition = Mockito.mock(ProcessDefinition.class); ProcessInstance processInstance = new ProcessInstance(); processInstance.setCommandType(CommandType.COMPLEMENT_DATA); taskInstance.setProcessInstance(processInstance); TaskExecutionContext context = TaskExecutionContextBuilder.get() .buildTaskInstanceRelatedInfo(taskInstance) .buildProcessInstanceRelatedInfo(processInstance) .buildProcessDefinitionRelatedInfo(processDefinition) .create(); ExecutionContext executionContext = new ExecutionContext(context.toCommand(), ExecutorType.WORKER); executionContext.setHost(Host.of(NetUtils.getHost() + ":" + serverConfig.getListenPort())); Boolean execute = nettyExecutorManager.execute(executionContext); Assert.assertTrue(execute); nettyRemotingServer.close(); }
@Test(expected = ExecuteException.class) public void testExecuteWithException() throws ExecuteException{ TaskInstance taskInstance = Mockito.mock(TaskInstance.class); ProcessDefinition processDefinition = Mockito.mock(ProcessDefinition.class); ProcessInstance processInstance = new ProcessInstance(); processInstance.setCommandType(CommandType.COMPLEMENT_DATA); taskInstance.setProcessInstance(processInstance); TaskExecutionContext context = TaskExecutionContextBuilder.get() .buildTaskInstanceRelatedInfo(taskInstance) .buildProcessInstanceRelatedInfo(processInstance) .buildProcessDefinitionRelatedInfo(processDefinition) .create(); ExecutionContext executionContext = new ExecutionContext(context.toCommand(), ExecutorType.WORKER); executionContext.setHost(Host.of(NetUtils.getHost() + ":4444")); nettyExecutorManager.execute(executionContext); }