-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test multi-threaded Netty server support #94
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #94 +/- ##
============================================
- Coverage 93.16% 93.14% -0.03%
+ Complexity 2009 2007 -2
============================================
Files 133 133
Lines 4549 4549
Branches 616 616
============================================
- Hits 4238 4237 -1
Misses 170 170
- Partials 141 142 +1 ☔ View full report in Codecov by Sentry. |
61df578
to
0acc9d5
Compare
0acc9d5
to
12a91be
Compare
@Test | ||
@EnabledOnOs(OS.LINUX) | ||
void multi_thread_server() throws Exception { | ||
int threads = 4; | ||
EventLoopGroup epollGroup = new EpollEventLoopGroup(threads, new DefaultThreadFactory("srv", true)); | ||
Bootstrap bootstrap = new Bootstrap() | ||
.group(epollGroup) | ||
.localAddress(new Random().nextInt(32000) + 32000) | ||
.channel(EpollDatagramChannel.class) | ||
.option(EpollChannelOption.SO_REUSEPORT, true) | ||
.handler(new ChannelInitializer<DatagramChannel>() { | ||
@Override | ||
protected void initChannel(DatagramChannel ch) { | ||
ch.pipeline().addFirst("DTLS", new DtlsChannelHandler(serverConf)); | ||
} | ||
}); | ||
CoapServerBuilder serverBuilder = CoapServer.builder() | ||
.executor(eventLoopGroup) | ||
.route(RouterService.builder() | ||
.get("/test", __ -> ok("OK").toFuture()) | ||
.post("/echo", req -> CompletableFuture.supplyAsync(() -> ok(req.getPayload()).build())) | ||
); | ||
List<CoapServer> servers = new ArrayList<>(); | ||
for (int i = 0; i < threads; i++) { | ||
servers.add( | ||
serverBuilder | ||
.transport(new NettyCoapTransport(bootstrap, EMPTY_RESOLVER)) | ||
.build() | ||
.start() | ||
); | ||
} | ||
|
||
List<CoapClient> clients = new ArrayList<>(); | ||
InetSocketAddress srvAddr = localhost(servers.get(0).getLocalSocketAddress().getPort()); | ||
CoapServerBuilder clientBuilder = CoapServer.builder().executor(eventLoopGroup); | ||
for (int i = 0; i < 100; i++) { | ||
clients.add( | ||
clientBuilder | ||
.transport(new NettyCoapTransport(createClientBootstrap(srvAddr), EMPTY_RESOLVER)) | ||
.buildClient(srvAddr) | ||
); | ||
} | ||
|
||
for (CoapClient client : clients) { | ||
assertEquals(ok("paska"), client.sendSync(post("/echo").payload("paska"))); | ||
client.close(); | ||
} | ||
|
||
for (CoapServer srv : servers) { | ||
srv.stop(); | ||
} | ||
epollGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets have it on separate file, anyway this does not share anything from other tests,
No description provided.