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

[UNDERTOW-2505] Review anonymous classes in Undertow io.undertow.websockets.jsr.test.suspendresume #1690

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
Loading