Skip to content
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

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

akolosov-n
Copy link
Collaborator

No description provided.

@akolosov-n akolosov-n requested a review from szysas August 27, 2024 10:51
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.14%. Comparing base (a94d3c9) to head (a4f571d).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Comment on lines 234 to 286
@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);
}
Copy link
Collaborator

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,

@akolosov-n akolosov-n requested a review from szysas August 27, 2024 11:32
@akolosov-n akolosov-n merged commit 6b29a92 into master Aug 27, 2024
6 checks passed
@akolosov-n akolosov-n deleted the alko/test-multiple-servers branch August 27, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants