|
|
@ -17,12 +17,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.extract.base.client; |
|
|
|
package org.apache.dolphinscheduler.extract.base.client; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.extract.base.NettyRemotingServer; |
|
|
|
import org.apache.dolphinscheduler.extract.base.NettyRemotingServer; |
|
|
|
import org.apache.dolphinscheduler.extract.base.RpcMethod; |
|
|
|
import org.apache.dolphinscheduler.extract.base.RpcMethod; |
|
|
|
import org.apache.dolphinscheduler.extract.base.RpcService; |
|
|
|
import org.apache.dolphinscheduler.extract.base.RpcService; |
|
|
|
import org.apache.dolphinscheduler.extract.base.config.NettyServerConfig; |
|
|
|
import org.apache.dolphinscheduler.extract.base.config.NettyServerConfig; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.extract.base.exception.MethodInvocationException; |
|
|
|
import org.apache.dolphinscheduler.extract.base.server.SpringServerMethodInvokerDiscovery; |
|
|
|
import org.apache.dolphinscheduler.extract.base.server.SpringServerMethodInvokerDiscovery; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.RandomUtils; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
@ -32,12 +39,18 @@ public class SingletonJdkDynamicRpcClientProxyFactoryTest { |
|
|
|
|
|
|
|
|
|
|
|
private NettyRemotingServer nettyRemotingServer; |
|
|
|
private NettyRemotingServer nettyRemotingServer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String serverAddress; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
@BeforeEach |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
nettyRemotingServer = |
|
|
|
int listenPort = RandomUtils.nextInt(10000, 20000); |
|
|
|
new NettyRemotingServer(NettyServerConfig.builder().serverName("ApiServer").listenPort(12345).build()); |
|
|
|
NettyServerConfig nettyServerConfig = NettyServerConfig.builder() |
|
|
|
|
|
|
|
.serverName("ApiServer") |
|
|
|
|
|
|
|
.listenPort(listenPort) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
nettyRemotingServer = new NettyRemotingServer(nettyServerConfig); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
nettyRemotingServer.start(); |
|
|
|
|
|
|
|
serverAddress = "localhost:" + listenPort; |
|
|
|
new SpringServerMethodInvokerDiscovery(nettyRemotingServer) |
|
|
|
new SpringServerMethodInvokerDiscovery(nettyRemotingServer) |
|
|
|
.postProcessAfterInitialization(new IServiceImpl(), "iServiceImpl"); |
|
|
|
.postProcessAfterInitialization(new IServiceImpl(), "iServiceImpl"); |
|
|
|
} |
|
|
|
} |
|
|
@ -45,23 +58,26 @@ public class SingletonJdkDynamicRpcClientProxyFactoryTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getProxyClient() { |
|
|
|
public void getProxyClient() { |
|
|
|
IService proxyClient = |
|
|
|
IService proxyClient = |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient("localhost:12345", IService.class); |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient(serverAddress, IService.class); |
|
|
|
Assertions.assertNotNull(proxyClient); |
|
|
|
Assertions.assertNotNull(proxyClient); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPing() { |
|
|
|
public void testPing() { |
|
|
|
IService proxyClient = |
|
|
|
IService proxyClient = |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient("localhost:12345", IService.class); |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient(serverAddress, IService.class); |
|
|
|
String ping = proxyClient.ping("ping"); |
|
|
|
assertEquals("pong", proxyClient.ping("ping")); |
|
|
|
Assertions.assertEquals("pong", ping); |
|
|
|
|
|
|
|
|
|
|
|
MethodInvocationException methodInvocationException = |
|
|
|
|
|
|
|
Assertions.assertThrows(MethodInvocationException.class, () -> proxyClient.ping(null)); |
|
|
|
|
|
|
|
assertEquals("ping: null is illegal", methodInvocationException.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testVoid() { |
|
|
|
public void testVoid() { |
|
|
|
IService proxyClient = |
|
|
|
IService proxyClient = |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient("localhost:12345", IService.class); |
|
|
|
SingletonJdkDynamicRpcClientProxyFactory.getProxyClient(serverAddress, IService.class); |
|
|
|
Assertions.assertDoesNotThrow(proxyClient::voidMethod); |
|
|
|
assertDoesNotThrow(proxyClient::voidMethod); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@AfterEach |
|
|
|
@AfterEach |
|
|
@ -83,6 +99,9 @@ public class SingletonJdkDynamicRpcClientProxyFactoryTest { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String ping(String ping) { |
|
|
|
public String ping(String ping) { |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(ping)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("ping: " + ping + " is illegal"); |
|
|
|
|
|
|
|
} |
|
|
|
return "pong"; |
|
|
|
return "pong"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|