use of io.dingodb.net.NetServiceProvider in project dingo by dingodb.
the class NetServiceTest method hello.
// @Test
public void hello() throws Exception {
String hello = "hello";
Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
NettyNetService netService = (NettyNetService) loader.iterator().next().get();
netService.listenPort(19199);
netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> assertThat(new String(msg.toBytes())).isEqualTo(hello));
netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(String.format("%s %s %s", new String(msg.toBytes()), ((ConnectionSubChannel) ch).channelId(), StackTraces.stack(2))));
Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(19199).build());
Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
channel.send(helloMsg);
Thread.sleep(100000);
}
use of io.dingodb.net.NetServiceProvider in project dingo by dingodb.
the class NetServiceTest method server.
// @Test
public void server() throws Exception {
Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
String hello = "hello";
ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
NettyNetService netService = (NettyNetService) loader.iterator().next().get();
netService.listenPort(26535);
Thread.sleep(5000);
netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(new String(msg.toBytes())));
for (int i = 0; i < 100; i++) {
Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(26536).build());
Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
channel.send(helloMsg);
}
Thread.sleep(10000000);
}
use of io.dingodb.net.NetServiceProvider in project dingo by dingodb.
the class NetServiceTest method client.
// @Test
public void client() throws Exception {
Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
String hello = "hello";
ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
NettyNetService netService = (NettyNetService) loader.iterator().next().get();
netService.listenPort(26536);
Thread.sleep(5000);
netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(new String(msg.toBytes())));
for (int i = 0; i < 100; i++) {
Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(26535).build());
Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
channel.send(helloMsg);
}
Thread.sleep(100000);
}
Aggregations