mirror of https://github.com/longtai-cn/hippo4j
parent
d2e569d188
commit
b3b27204a7
@ -0,0 +1,17 @@
|
|||||||
|
package cn.hippo4j.rpc.discovery;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.test.context.TestComponent;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TestComponent
|
||||||
|
public class InstanceModel {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package cn.hippo4j.rpc.discovery;
|
||||||
|
|
||||||
|
public interface InstanceServerLoader {
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.hippo4j.rpc.discovery;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.test.context.TestComponent;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class InstanceServerLoaderImpl implements InstanceServerLoader {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package cn.hippo4j.rpc.discovery;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.config.ApplicationContextHolder;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
classes = {InstanceModel.class, ApplicationContextHolder.class})
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
public class SpringContextInstanceTest {
|
||||||
|
|
||||||
|
Instance instance = new SpringContextInstance();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInstance() {
|
||||||
|
Object obj = instance.getInstance(InstanceModel.class);
|
||||||
|
Assert.assertNotNull(obj);
|
||||||
|
Assert.assertEquals(obj.getClass(), InstanceModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetInstance() {
|
||||||
|
Object obj = instance.getInstance("instanceModel");
|
||||||
|
Assert.assertNotNull(obj);
|
||||||
|
Assert.assertEquals(obj.getClass(), InstanceModel.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package cn.hippo4j.rpc.handler;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class NettyClientPoolHandlerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetHandlerEntity(){
|
||||||
|
TestHandler handler = new TestHandler();
|
||||||
|
long order = 0;
|
||||||
|
String name = "Test";
|
||||||
|
NettyClientPoolHandler poolHandler = new NettyClientPoolHandler();
|
||||||
|
HandlerManager.HandlerEntity<ChannelHandler> entity = poolHandler.getHandlerEntity(order, handler, name);
|
||||||
|
Assert.assertEquals(entity.getName(),name);
|
||||||
|
Assert.assertEquals(entity.getOrder(),order);
|
||||||
|
Assert.assertEquals(entity.getHandler(),handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompareTo(){
|
||||||
|
TestHandler handler = new TestHandler();
|
||||||
|
long order = 0;
|
||||||
|
String name = "Test";
|
||||||
|
TestHandler handler1 = new TestHandler();
|
||||||
|
long order1 = 1;
|
||||||
|
String name1 = "Test1";
|
||||||
|
NettyClientPoolHandler poolHandler = new NettyClientPoolHandler();
|
||||||
|
HandlerManager.HandlerEntity<ChannelHandler> entity = poolHandler.getHandlerEntity(order, handler, name);
|
||||||
|
HandlerManager.HandlerEntity<ChannelHandler> entity1 = poolHandler.getHandlerEntity(order1, handler1, name1);
|
||||||
|
int compare = entity.compareTo(entity1);
|
||||||
|
Assert.assertTrue(compare < 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addLast() {
|
||||||
|
NettyClientPoolHandler handler = new NettyClientPoolHandler();
|
||||||
|
Assert.assertTrue(handler.isEmpty());
|
||||||
|
handler.addLast(new TestHandler());
|
||||||
|
Assert.assertFalse(handler.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addFirst() {
|
||||||
|
NettyClientPoolHandler handler = new NettyClientPoolHandler();
|
||||||
|
Assert.assertTrue(handler.isEmpty());
|
||||||
|
handler.addFirst(new TestHandler());
|
||||||
|
Assert.assertFalse(handler.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddLast() {
|
||||||
|
NettyClientPoolHandler handler = new NettyClientPoolHandler();
|
||||||
|
Assert.assertTrue(handler.isEmpty());
|
||||||
|
handler.addLast("Test", new TestHandler());
|
||||||
|
Assert.assertFalse(handler.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddFirst() {
|
||||||
|
NettyClientPoolHandler handler = new NettyClientPoolHandler();
|
||||||
|
Assert.assertTrue(handler.isEmpty());
|
||||||
|
handler.addFirst("Test", new TestHandler());
|
||||||
|
Assert.assertFalse(handler.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package cn.hippo4j.rpc.handler;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
|
public class TestHandler 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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package cn.hippo4j.rpc.server;
|
||||||
|
|
||||||
|
import cn.hippo4j.rpc.handler.TestHandler;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class NettyServerConnectionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addLast() {
|
||||||
|
NettyServerConnection connection = new NettyServerConnection();
|
||||||
|
Assert.assertTrue(connection.isEmpty());
|
||||||
|
connection.addLast(new TestHandler());
|
||||||
|
Assert.assertFalse(connection.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addFirst() {
|
||||||
|
NettyServerConnection connection = new NettyServerConnection();
|
||||||
|
Assert.assertTrue(connection.isEmpty());
|
||||||
|
connection.addFirst(new TestHandler());
|
||||||
|
Assert.assertFalse(connection.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddLast() {
|
||||||
|
NettyServerConnection connection = new NettyServerConnection();
|
||||||
|
Assert.assertTrue(connection.isEmpty());
|
||||||
|
connection.addLast("Test", new TestHandler());
|
||||||
|
Assert.assertFalse(connection.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddFirst() {
|
||||||
|
NettyServerConnection connection = new NettyServerConnection();
|
||||||
|
Assert.assertTrue(connection.isEmpty());
|
||||||
|
connection.addFirst("Test", new TestHandler());
|
||||||
|
Assert.assertFalse(connection.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
cn.hippo4j.rpc.discovery.InstanceServerLoaderImpl
|
Loading…
Reference in new issue