From 01bc9d3835b6d32e4c7149c367498a7918b43cd3 Mon Sep 17 00:00:00 2001 From: lachan-roberts Date: Thu, 7 Mar 2019 14:19:35 +1100 Subject: [PATCH] Issue #3406 - fix SessionTracker and JettyWebSocketFrameHandlerTest Signed-off-by: lachan-roberts --- .../websocket/javax/common/SessionTracker.java | 3 ++- .../jetty/websocket/common/EventQueue.java | 16 +++++++++++++--- .../common/JettyWebSocketFrameHandlerTest.java | 7 ++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java index e2ee48a731d..dd76efa0b95 100644 --- a/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java +++ b/jetty-websocket/javax-websocket-common/src/main/java/org/eclipse/jetty/websocket/javax/common/SessionTracker.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.javax.common; import java.util.Collections; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; + import javax.websocket.Session; import org.eclipse.jetty.util.component.AbstractLifeCycle; @@ -44,7 +45,7 @@ public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketS @Override public void onJavaxWebSocketSessionClosed(JavaxWebSocketSession session) { - sessions.remove(sessions); + sessions.remove(session); } @Override diff --git a/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/EventQueue.java b/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/EventQueue.java index ec2423b3a96..4b0d3d7832f 100644 --- a/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/EventQueue.java +++ b/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/EventQueue.java @@ -19,10 +19,12 @@ package org.eclipse.jetty.websocket.common; import java.util.Iterator; +import java.util.NoSuchElementException; import java.util.concurrent.LinkedBlockingDeque; import static org.eclipse.jetty.toolchain.test.matchers.RegexMatcher.matchesPattern; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class EventQueue extends LinkedBlockingDeque { @@ -33,10 +35,18 @@ public class EventQueue extends LinkedBlockingDeque public void assertEvents(String... regexEvents) { - Iterator capturedIterator = iterator(); - for (int i = 0; i < regexEvents.length; i++) + int i = 0; + try { - assertThat("Event [" + i + "]", capturedIterator.next(), matchesPattern(regexEvents[i])); + Iterator capturedIterator = iterator(); + for (i = 0; i < regexEvents.length; i++) + { + assertThat("Event [" + i + "]", capturedIterator.next(), matchesPattern(regexEvents[i])); + } + } + catch (NoSuchElementException e) + { + fail("Event [" + (i) + "] not found: " + regexEvents[i]); } } } diff --git a/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java b/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java index eaf3a37fbf5..ca93b5af759 100644 --- a/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java +++ b/jetty-websocket/jetty-websocket-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java @@ -121,7 +121,7 @@ public class JettyWebSocketFrameHandlerTest // Trigger Events localEndpoint.onOpen(channel, Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.TEXT).setPayload("Hello?").setFin(true), Callback.NOOP); - localEndpoint.onFrame(CloseStatus.toFrame(StatusCode.NORMAL, "Normal"), Callback.NOOP); + localEndpoint.onClosed(new CloseStatus(StatusCode.NORMAL, "Normal"), Callback.NOOP); // Validate Events socket.events.assertEvents( @@ -216,6 +216,7 @@ public class JettyWebSocketFrameHandlerTest localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload(" the ").setFin(false), Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload("Pig").setFin(true), Callback.NOOP); localEndpoint.onFrame(CloseStatus.toFrame(StatusCode.NORMAL), Callback.NOOP); + localEndpoint.onClosed(CloseStatus.NORMAL_STATUS, Callback.NOOP); // Validate Events socket.events.assertEvents( @@ -245,7 +246,7 @@ public class JettyWebSocketFrameHandlerTest localEndpoint.onFrame(new Frame(OpCode.BINARY).setPayload("Save").setFin(false), Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload(" the ").setFin(false), Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload("Pig").setFin(true), Callback.NOOP); - localEndpoint.onFrame(CloseStatus.toFrame(StatusCode.NORMAL, "Normal"), Callback.NOOP); + localEndpoint.onClosed(new CloseStatus(StatusCode.NORMAL, "Normal"), Callback.NOOP); // Validate Events socket.events.assertEvents( @@ -323,7 +324,7 @@ public class JettyWebSocketFrameHandlerTest localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload(" the ").setFin(false), Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.PONG).setPayload("You there?"), Callback.NOOP); localEndpoint.onFrame(new Frame(OpCode.CONTINUATION).setPayload("Pig").setFin(true), Callback.NOOP); - localEndpoint.onFrame(CloseStatus.toFrame(StatusCode.NORMAL, "Normal"), Callback.NOOP); + localEndpoint.onClosed(new CloseStatus(StatusCode.NORMAL, "Normal"), Callback.NOOP); // Validate Events socket.events.assertEvents(