Skip to content

Commit

Permalink
Merge pull request #1690 from lvydra/UNDERTOW-2505
Browse files Browse the repository at this point in the history
[UNDERTOW-2505] Review anonymous classes in Undertow io.undertow.websockets.jsr.test.suspendresume
  • Loading branch information
ropalka authored Oct 23, 2024
2 parents e454886 + 2b098ae commit 73e7147
Showing 1 changed file with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,7 @@ public void testConnectionWaitsForMessageEnd() throws Exception {
final AtomicReference<String> message = new AtomicReference<>();
WebSocketChannel channel = WebSocketClient.connectionBuilder(DefaultServer.getWorker(), DefaultServer.getBufferPool(), new URI(DefaultServer.getDefaultServerURL() + "/"))
.connect().get();
channel.getReceiveSetter().set(new AbstractReceiveListener() {
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage msg) {
message.set(msg.getData());
done.countDown();
}

@Override
protected void onError(WebSocketChannel channel, Throwable error) {
error.printStackTrace();
message.set("error");
done.countDown();
}

@Override
protected void onFullCloseMessage(WebSocketChannel channel, BufferedBinaryMessage message) {
message.getData().free();
done.countDown();
}
});
channel.getReceiveSetter().set(new ReceiveListener(message, done));
channel.resumeReceives();
Assert.assertTrue(channel.isOpen());
WebSockets.sendText("Hello World", channel, null);
Expand Down Expand Up @@ -194,4 +175,33 @@ public void testRejectWhenSuspended() throws Exception {
}

}

private static class ReceiveListener extends AbstractReceiveListener {
private final CountDownLatch done;
private final AtomicReference<String> message;

ReceiveListener(AtomicReference<String> message, CountDownLatch done) {
this.message = message;
this.done = done;
}

@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage msg) {
message.set(msg.getData());
done.countDown();
}

@Override
protected void onError(WebSocketChannel channel, Throwable error) {
error.printStackTrace();
message.set("error");
done.countDown();
}

@Override
protected void onFullCloseMessage(WebSocketChannel channel, BufferedBinaryMessage message) {
message.getData().free();
done.countDown();
}
}
}

0 comments on commit 73e7147

Please sign in to comment.