fix : Supplementary unit tests for RPC modules (#1187) (#812)

pull/1206/head
pizihao 2 years ago
parent d705ed5fd7
commit 18999970db

@ -17,6 +17,8 @@
package cn.hippo4j.rpc.client;
import cn.hippo4j.common.toolkit.ThreadUtil;
public class CallManager {
public int call() {
@ -27,4 +29,10 @@ public class CallManager {
return a + b;
}
public int callTestTimeout() {
// thread sleep for 10 seconds
ThreadUtil.sleep(10000);
return 1;
}
}

@ -22,9 +22,7 @@ import cn.hippo4j.rpc.discovery.ClassRegistry;
import cn.hippo4j.rpc.discovery.DefaultInstance;
import cn.hippo4j.rpc.discovery.Instance;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
import cn.hippo4j.rpc.handler.NettyServerTakeHandler;
import cn.hippo4j.rpc.handler.*;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
@ -109,19 +107,53 @@ public class RPCClientTest {
rpcServer.close();
}
@Test(expected = Exception.class)
public void responseNullExceptionTest() throws IOException {
Class<CallManager> cls = CallManager.class;
String className = cls.getName();
ClassRegistry.put(className, cls);
// The mode connection was denied when the server was started on the specified port
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
ServerConnection connection = new NettyServerConnection(handler);
RPCServer rpcServer = new RPCServer(connection, port);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
}
InetSocketAddress address = InetSocketAddress.createUnresolved(host, port.getPort());
ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler());
ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler);
clientConnection.setTimeout(300L);
try (RPCClient rpcClient = new RPCClient(clientConnection)) {
Request request = new DefaultRequest("127.0.0.18888", className, "callTestTimeout", null, null);
Response response = rpcClient.connection(request);
Assert.assertNotNull(response.getErrMsg());
Assert.assertNotNull(response.getThrowable());
} catch (IOException e) {
// no something
} finally {
rpcServer.close();
}
}
static class TestServerPort implements ServerPort {
int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return 8888;
return port;
}
}
static class TestPortServerPort implements ServerPort {
int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return 8889;
return port;
}
}
}

@ -0,0 +1,33 @@
/*
* 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 cn.hippo4j.rpc.client;
import java.io.IOException;
import java.net.ServerSocket;
public class RandomPort {
public static int getSafeRandomPort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@ -20,7 +20,12 @@ package cn.hippo4j.rpc.handler;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.rpc.client.NettyClientConnection;
import cn.hippo4j.rpc.client.RPCClient;
import cn.hippo4j.rpc.client.RandomPort;
import cn.hippo4j.rpc.discovery.*;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.DefaultResponse;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
import cn.hippo4j.rpc.server.NettyServerConnection;
import cn.hippo4j.rpc.server.RPCServer;
import cn.hippo4j.rpc.support.NettyProxyCenter;
@ -38,7 +43,7 @@ public class ConnectHandlerTest {
// server
Class<InstanceServerLoader> cls = InstanceServerLoader.class;
ClassRegistry.put(cls.getName(), cls);
ServerPort port = () -> 8892;
ServerPort port = new TestServerPort();
Instance instance = new DefaultInstance();
NettyServerTakeHandler serverHandler = new NettyServerTakeHandler(instance);
NettyServerConnection connection = new NettyServerConnection(serverHandler);
@ -59,4 +64,36 @@ public class ConnectHandlerTest {
rpcServer.close();
}
@Test
public void testConnectHandlerDefault() {
ConnectHandler handler = new TestConnectHandler();
Request request = new DefaultRequest("key", "className", "methodName", new Class[0], new Object[0]);
Response response = handler.sendHandler(request);
Assert.assertNull(response);
Response response1 = new DefaultResponse("key", this.getClass(), handler);
String key = response1.getKey();
Class<?> cls = response1.getCls();
Object obj = response1.getObj();
handler.handler(response1);
Assert.assertEquals(key, response1.getKey());
Assert.assertEquals(cls, response1.getCls());
Assert.assertEquals(obj, response1.getObj());
}
static class TestConnectHandler implements ConnectHandler {
}
static class TestServerPort implements ServerPort {
int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return port;
}
}
}

@ -17,10 +17,28 @@
package cn.hippo4j.rpc.handler;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.common.web.exception.IllegalException;
import cn.hippo4j.rpc.client.*;
import cn.hippo4j.rpc.discovery.ClassRegistry;
import cn.hippo4j.rpc.discovery.DefaultInstance;
import cn.hippo4j.rpc.discovery.Instance;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
import cn.hippo4j.rpc.server.NettyServerConnection;
import cn.hippo4j.rpc.server.RPCServer;
import cn.hippo4j.rpc.server.ServerConnection;
import io.netty.channel.ChannelHandler;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
public class NettyClientPoolHandlerTest {
@Test
@ -54,7 +72,7 @@ public class NettyClientPoolHandlerTest {
public void addLast() {
NettyClientPoolHandler handler = new NettyClientPoolHandler();
Assert.assertTrue(handler.isEmpty());
handler.addLast(new TestHandler());
handler.addLast(null, new TestHandler());
Assert.assertFalse(handler.isEmpty());
}
@ -62,7 +80,7 @@ public class NettyClientPoolHandlerTest {
public void addFirst() {
NettyClientPoolHandler handler = new NettyClientPoolHandler();
Assert.assertTrue(handler.isEmpty());
handler.addFirst(new TestHandler());
handler.addFirst(null, new TestHandler());
Assert.assertFalse(handler.isEmpty());
}
@ -81,4 +99,54 @@ public class NettyClientPoolHandlerTest {
handler.addFirst("Test", new TestHandler());
Assert.assertFalse(handler.isEmpty());
}
@Test(expected = IllegalException.class)
public void testGetHandlerEntityFalse() {
TestFalseHandler handler = new TestFalseHandler();
long order = 0;
String name = "Test";
NettyClientPoolHandler poolHandler = new NettyClientPoolHandler();
poolHandler.getHandlerEntity(order, handler, name);
}
@Test
public void connectionTest() throws IOException {
ServerPort port = new ServerPort() {
final int a = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return a;
}
};
Class<CallManager> cls = CallManager.class;
String className = cls.getName();
ClassRegistry.put(className, cls);
// The mode connection was denied when the server was started on the specified port
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
ServerConnection connection = new NettyServerConnection(handler);
RPCServer rpcServer = new RPCServer(connection, port);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
}
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort());
List<ChannelHandler> handlers = new ArrayList<>();
handlers.add(new NettyClientTakeHandler());
NettyClientPoolHandler channelPoolHandler = new NettyClientPoolHandler(handlers);
channelPoolHandler.addLast("test", new TestHandler());
ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler);
RPCClient rpcClient = new RPCClient(clientConnection);
Request request = new DefaultRequest("127.0.0.18888", className, "call", null, null);
for (int i = 0; i < 50; i++) {
Response response = rpcClient.connection(request);
boolean active = rpcClient.isActive();
Assert.assertTrue(active);
Assert.assertEquals(response.getObj(), 1);
}
rpcClient.close();
rpcServer.close();
}
}

@ -0,0 +1,39 @@
/*
* 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 cn.hippo4j.rpc.handler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
public class TestFalseHandler implements ChannelHandler {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
}
}

@ -59,4 +59,18 @@ public class DefaultRequestTest {
Assert.assertEquals(request1, request);
}
@Test
public void testEquals() throws NoSuchMethodException {
String key = "name";
String clsName = InstanceServerLoaderImpl.class.getName();
Method method = InstanceServerLoaderImpl.class.getMethod("setName", String.class);
String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
Object[] parameters = new Object[1];
parameters[0] = "hippo4j";
Request request = new DefaultRequest(key, clsName, methodName, parameterTypes, parameters);
Assert.assertTrue(request.equals(request));
Assert.assertFalse(request.equals(null));
}
}

@ -83,4 +83,13 @@ public class DefaultResponseTest {
Assert.assertTrue(response1.isErr());
}
@Test
public void testEquals() throws NoSuchMethodException {
String key = "name";
Object o = "obj";
Class<?> cls = String.class;
Response response = new DefaultResponse(key, cls, o);
Assert.assertTrue(response.equals(response));
Assert.assertFalse(response.equals(null));
}
}

@ -27,7 +27,7 @@ public class NettyServerConnectionTest {
public void addLast() {
NettyServerConnection connection = new NettyServerConnection();
Assert.assertTrue(connection.isEmpty());
connection.addLast(new TestHandler());
connection.addLast(null, new TestHandler());
Assert.assertFalse(connection.isEmpty());
}
@ -35,7 +35,7 @@ public class NettyServerConnectionTest {
public void addFirst() {
NettyServerConnection connection = new NettyServerConnection();
Assert.assertTrue(connection.isEmpty());
connection.addFirst(new TestHandler());
connection.addFirst(null, new TestHandler());
Assert.assertFalse(connection.isEmpty());
}

@ -18,15 +18,26 @@
package cn.hippo4j.rpc.server;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.rpc.client.*;
import cn.hippo4j.rpc.discovery.ClassRegistry;
import cn.hippo4j.rpc.discovery.DefaultInstance;
import cn.hippo4j.rpc.discovery.Instance;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
import cn.hippo4j.rpc.handler.NettyServerTakeHandler;
import cn.hippo4j.rpc.handler.TestHandler;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.pool.ChannelPoolHandler;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
public class RPCServerTest {
@ -35,7 +46,7 @@ public class RPCServerTest {
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
ServerConnection connection = new NettyServerConnection(handler);
RPCServer rpcServer = new RPCServer(connection, () -> 8893);
RPCServer rpcServer = new RPCServer(connection, RandomPort::getSafeRandomPort);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
@ -52,7 +63,7 @@ public class RPCServerTest {
EventLoopGroup worker = new NioEventLoopGroup();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
ServerConnection connection = new NettyServerConnection(leader, worker, handler);
RPCServer rpcServer = new RPCServer(connection, () -> 8894);
RPCServer rpcServer = new RPCServer(connection, RandomPort::getSafeRandomPort);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
@ -61,4 +72,57 @@ public class RPCServerTest {
Assert.assertTrue(active);
rpcServer.close();
}
@Test
public void bindPipelineTest() throws IOException {
ServerPort serverPort = new ServerPort() {
final int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return port;
}
};
Class<CallManager> cls = CallManager.class;
String className = cls.getName();
ClassRegistry.put(className, cls);
// The mode connection was denied when the server was started on the specified port
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
NettyServerConnection connection = new NettyServerConnection(handler);
connection.addLast("Test", new TestHandler());
RPCServer rpcServer = new RPCServer(connection, serverPort);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
}
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", serverPort.getPort());
ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler());
ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler);
RPCClient rpcClient = new RPCClient(clientConnection);
Request request = new DefaultRequest("127.0.0.18888", className, "call", null, null);
for (int i = 0; i < 50; i++) {
Response response = rpcClient.connection(request);
boolean active = rpcClient.isActive();
Assert.assertTrue(active);
Assert.assertEquals(response.getObj(), 1);
}
rpcClient.close();
rpcServer.close();
}
@Test
public void bindNegativeTest() {
ServerPort serverPort = () -> -1;
Class<CallManager> cls = CallManager.class;
String className = cls.getName();
ClassRegistry.put(className, cls);
// The mode connection was denied when the server was started on the specified port
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
NettyServerConnection connection = new NettyServerConnection(handler);
RPCServer rpcServer = new RPCServer(connection, serverPort);
rpcServer.bind();
}
}

@ -0,0 +1,72 @@
/*
* 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 cn.hippo4j.rpc.support;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.rpc.client.*;
import cn.hippo4j.rpc.discovery.ClassRegistry;
import cn.hippo4j.rpc.discovery.DefaultInstance;
import cn.hippo4j.rpc.discovery.Instance;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
import cn.hippo4j.rpc.handler.NettyServerTakeHandler;
import cn.hippo4j.rpc.handler.TestHandler;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
import cn.hippo4j.rpc.server.NettyServerConnection;
import cn.hippo4j.rpc.server.RPCServer;
import io.netty.channel.pool.ChannelPoolHandler;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
public class NettyClientSupportTest {
@Test
public void closeTest() throws IOException {
int port = RandomPort.getSafeRandomPort();
ServerPort serverPort = () -> port;
Class<CallManager> cls = CallManager.class;
String className = cls.getName();
ClassRegistry.put(className, cls);
// The mode connection was denied when the server was started on the specified port
Instance instance = new DefaultInstance();
NettyServerTakeHandler handler = new NettyServerTakeHandler(instance);
NettyServerConnection connection = new NettyServerConnection(handler);
connection.addLast("Test", new TestHandler());
RPCServer rpcServer = new RPCServer(connection, serverPort);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
}
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port);
ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler());
ClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler);
RPCClient rpcClient = new RPCClient(clientConnection);
NettyClientSupport.closeClient(new InetSocketAddress("localhost", port));
rpcClient.close();
rpcServer.close();
}
}

@ -17,6 +17,7 @@
package cn.hippo4j.rpc.support;
import cn.hippo4j.rpc.client.RandomPort;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
@ -78,7 +79,7 @@ public class NettyConnectPoolHolderTest {
@Override
public int getPort() {
return 8895;
return RandomPort.getSafeRandomPort();
}
}
}

@ -18,6 +18,7 @@
package cn.hippo4j.rpc.support;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.rpc.client.RandomPort;
import cn.hippo4j.rpc.discovery.DefaultInstance;
import cn.hippo4j.rpc.discovery.Instance;
import cn.hippo4j.rpc.discovery.ServerPort;
@ -112,9 +113,10 @@ public class NettyConnectPoolTest {
static class TestServerPort implements ServerPort {
int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return 8890;
return port;
}
}
}

@ -17,13 +17,19 @@
package cn.hippo4j.rpc.support;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.common.web.exception.IllegalException;
import cn.hippo4j.rpc.discovery.ServerPort;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
import cn.hippo4j.rpc.client.*;
import cn.hippo4j.rpc.discovery.*;
import cn.hippo4j.rpc.exception.ConnectionException;
import cn.hippo4j.rpc.handler.*;
import cn.hippo4j.rpc.server.NettyServerConnection;
import cn.hippo4j.rpc.server.RPCServer;
import io.netty.channel.pool.ChannelPoolHandler;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
public class NettyProxyCenterTest {
@ -42,6 +48,27 @@ public class NettyProxyCenterTest {
public void createProxy() {
ProxyInterface localhost = NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894");
Assert.assertNotNull(localhost);
NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894");
InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("localhost", 8894);
Client client = NettyClientSupport.getClient(socketAddress);
ProxyInterface proxy = NettyProxyCenter.createProxy(client, ProxyInterface.class, socketAddress);
Assert.assertNotNull(proxy);
}
@Test(expected = ConnectionException.class)
public void createProxyException() {
NettyProxyCenter.getProxy(ProxyInterface.class, "localhost8894");
}
@Test
public void removeProxy() {
NettyProxyCenter.getProxy(ProxyInterface.class, "localhost:8894");
NettyProxyCenter.removeProxy(ProxyInterface.class, "localhost:8894");
}
@Test(expected = ConnectionException.class)
public void removeProxyException() {
NettyProxyCenter.removeProxy(ProxyInterface.class, "localhost8894");
}
@Test(expected = IllegalException.class)
@ -52,6 +79,32 @@ public class NettyProxyCenterTest {
Assert.assertNotNull(localhost);
}
@Test
public void bindPipelineTest() throws IOException {
// server
Class<InstanceServerLoader> cls = InstanceServerLoader.class;
ClassRegistry.put(cls.getName(), cls);
ServerPort port = new TestServerPort();
Instance instance = new DefaultInstance();
NettyServerTakeHandler serverHandler = new NettyServerTakeHandler(instance);
NettyServerConnection connection = new NettyServerConnection(serverHandler);
RPCServer rpcServer = new RPCServer(connection, port);
rpcServer.bind();
while (!rpcServer.isActive()) {
ThreadUtil.sleep(100L);
}
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", port.getPort());
ChannelPoolHandler channelPoolHandler = new NettyClientPoolHandler(new NettyClientTakeHandler());
NettyClientConnection clientConnection = new NettyClientConnection(address, channelPoolHandler);
RPCClient rpcClient = new RPCClient(clientConnection);
InstanceServerLoader loader = NettyProxyCenter.createProxy(rpcClient, cls, address);
String name = loader.getName();
Assert.assertEquals("name", name);
rpcClient.close();
rpcServer.close();
}
interface ProxyInterface {
void hello();
@ -63,9 +116,11 @@ public class NettyProxyCenterTest {
static class TestServerPort implements ServerPort {
int port = RandomPort.getSafeRandomPort();
@Override
public int getPort() {
return 8894;
return port;
}
}
}

@ -18,17 +18,44 @@
package cn.hippo4j.rpc.support;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.rpc.discovery.InstanceServerLoader;
import cn.hippo4j.rpc.client.*;
import cn.hippo4j.rpc.discovery.*;
import cn.hippo4j.rpc.handler.NettyClientPoolHandler;
import cn.hippo4j.rpc.handler.NettyClientTakeHandler;
import cn.hippo4j.rpc.handler.NettyServerTakeHandler;
import cn.hippo4j.rpc.model.DefaultRequest;
import cn.hippo4j.rpc.model.Request;
import cn.hippo4j.rpc.model.Response;
import cn.hippo4j.rpc.server.NettyServerConnection;
import cn.hippo4j.rpc.server.RPCServer;
import cn.hippo4j.rpc.server.ServerConnection;
import io.netty.channel.pool.ChannelPoolHandler;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
public class NettyServerSupportTest {
@Test
public synchronized void bind() throws IOException {
NettyServerSupport support = new NettyServerSupport(() -> 8891, InstanceServerLoader.class);
public void bind() throws IOException {
NettyServerSupport support = new NettyServerSupport(RandomPort::getSafeRandomPort, InstanceServerLoader.class);
support.bind();
while (!support.isActive()) {
ThreadUtil.sleep(100L);
}
Assert.assertTrue(support.isActive());
support.close();
}
@Test
public void bindTest() throws IOException {
List<Class<?>> classes = new ArrayList<>();
classes.add(InstanceServerLoader.class);
NettyServerSupport support = new NettyServerSupport(RandomPort::getSafeRandomPort, classes);
support.bind();
while (!support.isActive()) {
ThreadUtil.sleep(100L);

Loading…
Cancel
Save