From e2f15522bd7ee359e1bd08ec637fefb44649c5d5 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 3 Nov 2011 09:18:31 -0700 Subject: [PATCH] Fixing junit test cases affected by close status code changes --- .../jetty/websocket/WebSocketClientTest.java | 16 ++++++++++------ .../jetty/websocket/WebSocketMessageD13Test.java | 10 +++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java index 0e65c889941..811f82ef9a9 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketClientTest.java @@ -26,7 +26,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; public class WebSocketClientTest @@ -419,6 +418,7 @@ public class WebSocketClientTest final AtomicInteger close = new AtomicInteger(); final CountDownLatch _latch = new CountDownLatch(1); final BlockingQueue queue = new BlockingArrayQueue(); + final StringBuilder closeMessage = new StringBuilder(); Future future=client.open(new URI("ws://127.0.0.1:"+_serverPort+"/"),new WebSocket.OnTextMessage() { public void onOpen(Connection connection) @@ -429,6 +429,7 @@ public class WebSocketClientTest public void onClose(int closeCode, String message) { close.set(closeCode); + closeMessage.append(message); _latch.countDown(); } @@ -477,8 +478,8 @@ public class WebSocketClientTest _latch.await(10,TimeUnit.SECONDS); Assert.assertTrue(System.currentTimeMillis()-start<5000); - Assert.assertEquals(1111,close.get()); - + Assert.assertEquals(1002,close.get()); + Assert.assertEquals("Invalid close control status code 1111", closeMessage.toString()); } @@ -522,6 +523,7 @@ public class WebSocketClientTest Thread consumer = new Thread() { + @Override public void run() { try @@ -585,6 +587,7 @@ public class WebSocketClientTest final AtomicBoolean open = new AtomicBoolean(); final AtomicInteger close = new AtomicInteger(); final CountDownLatch _latch = new CountDownLatch(1); + final StringBuilder closeMessage = new StringBuilder(); final Exchanger exchanger = new Exchanger(); Future future=client.open(new URI("ws://127.0.0.1:"+_serverPort+"/"),new WebSocket.OnTextMessage() { @@ -595,8 +598,8 @@ public class WebSocketClientTest public void onClose(int closeCode, String message) { - //System.err.println("CLOSE "+closeCode+" "+message); close.set(closeCode); + closeMessage.append(message); _latch.countDown(); } @@ -632,6 +635,7 @@ public class WebSocketClientTest // Set up a consumer of received messages that waits a while before consuming Thread consumer = new Thread() { + @Override public void run() { try @@ -689,8 +693,8 @@ public class WebSocketClientTest _latch.await(10,TimeUnit.SECONDS); Assert.assertTrue(System.currentTimeMillis()-start<5000); - Assert.assertEquals(1111,close.get()); - + Assert.assertEquals(1002,close.get()); + Assert.assertEquals("Invalid close control status code 1111", closeMessage.toString()); } private void respondToClient(Socket connection, String serverResponse) throws IOException diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD13Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD13Test.java index e48885c2f01..4f8fcdca036 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD13Test.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD13Test.java @@ -1,8 +1,6 @@ package org.eclipse.jetty.websocket; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.EOFException; import java.io.IOException; @@ -461,6 +459,7 @@ public class WebSocketMessageD13Test // unblock the latch in 4s new Thread() { + @Override public void run() { try @@ -544,6 +543,7 @@ public class WebSocketMessageD13Test final AtomicLong totalB=new AtomicLong(); new Thread() { + @Override public void run() { try @@ -950,9 +950,9 @@ public class WebSocketMessageD13Test output.flush(); assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read()); - assertEquals(2,input.read()); + assertEquals(41,input.read()); int code=(0xff&input.read())*0x100+(0xff&input.read()); - assertEquals(0x81FF,code); + assertEquals(1002,code); // Invalid code 0x81FF } @Test