From f20d4034809dc11beb9359df7781731963fec7dc Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 16 Jul 2019 13:04:19 -0500 Subject: [PATCH] Issue #3876 - Additional testcase Signed-off-by: Joakim Erdfelt --- .../tests/server/PartialListenerTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java index 4fd215103c4..0a895a8c456 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java @@ -187,6 +187,68 @@ public class PartialListenerTest } } + /** + * Test to ensure that the internal state tracking the partial messages is reset after each complete message. + */ + @Test + public void testPartial_TextBinaryText() throws Exception + { + ClientUpgradeRequest request = new ClientUpgradeRequest(); + CloseTrackingEndpoint clientEndpoint = new CloseTrackingEndpoint(); + + URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/ws")); + Future futSession = client.connect(clientEndpoint, wsUri, request); + + Session session = null; + try (StacklessLogging ignore = new StacklessLogging(WebSocketSession.class)) + { + session = futSession.get(5, SECONDS); + + RemoteEndpoint clientRemote = session.getRemote(); + clientRemote.sendPartialString("hello", false); + clientRemote.sendPartialString(" ", false); + clientRemote.sendPartialString("world", true); + + clientRemote.sendPartialBytes(BufferUtil.toBuffer("greetings"), false); + clientRemote.sendPartialBytes(BufferUtil.toBuffer(" "), false); + clientRemote.sendPartialBytes(BufferUtil.toBuffer("mars"), true); + + clientRemote.sendPartialString("salutations", false); + clientRemote.sendPartialString(" ", false); + clientRemote.sendPartialString("phobos", true); + + PartialEndpoint serverEndpoint = partialCreator.partialEndpoint; + + String event; + + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload=hello, fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload= , fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload=world, fin=true]")); + + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("BINARY[payload=<<>>, fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("BINARY[payload=<<< >>>, fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("BINARY[payload=<<>>, fin=true]")); + + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload=salutations, fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload= , fin=false]")); + event = serverEndpoint.partialEvents.poll(5, SECONDS); + assertThat("Event", event, is("TEXT[payload=phobos, fin=true]")); + } + finally + { + close(session); + } + } + + public static class PartialCreator implements WebSocketCreator { public PartialEndpoint partialEndpoint;