Fixing junit test cases affected by close status code changes

This commit is contained in:
Joakim Erdfelt 2011-11-03 09:18:31 -07:00
parent c1d681551b
commit e2f15522bd
2 changed files with 15 additions and 11 deletions

View File

@ -26,7 +26,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
public class WebSocketClientTest public class WebSocketClientTest
@ -419,6 +418,7 @@ public class WebSocketClientTest
final AtomicInteger close = new AtomicInteger(); final AtomicInteger close = new AtomicInteger();
final CountDownLatch _latch = new CountDownLatch(1); final CountDownLatch _latch = new CountDownLatch(1);
final BlockingQueue<String> queue = new BlockingArrayQueue<String>(); final BlockingQueue<String> queue = new BlockingArrayQueue<String>();
final StringBuilder closeMessage = new StringBuilder();
Future<WebSocket.Connection> future=client.open(new URI("ws://127.0.0.1:"+_serverPort+"/"),new WebSocket.OnTextMessage() Future<WebSocket.Connection> future=client.open(new URI("ws://127.0.0.1:"+_serverPort+"/"),new WebSocket.OnTextMessage()
{ {
public void onOpen(Connection connection) public void onOpen(Connection connection)
@ -429,6 +429,7 @@ public class WebSocketClientTest
public void onClose(int closeCode, String message) public void onClose(int closeCode, String message)
{ {
close.set(closeCode); close.set(closeCode);
closeMessage.append(message);
_latch.countDown(); _latch.countDown();
} }
@ -477,8 +478,8 @@ public class WebSocketClientTest
_latch.await(10,TimeUnit.SECONDS); _latch.await(10,TimeUnit.SECONDS);
Assert.assertTrue(System.currentTimeMillis()-start<5000); 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() Thread consumer = new Thread()
{ {
@Override
public void run() public void run()
{ {
try try
@ -585,6 +587,7 @@ public class WebSocketClientTest
final AtomicBoolean open = new AtomicBoolean(); final AtomicBoolean open = new AtomicBoolean();
final AtomicInteger close = new AtomicInteger(); final AtomicInteger close = new AtomicInteger();
final CountDownLatch _latch = new CountDownLatch(1); final CountDownLatch _latch = new CountDownLatch(1);
final StringBuilder closeMessage = new StringBuilder();
final Exchanger<String> exchanger = new Exchanger<String>(); final Exchanger<String> exchanger = new Exchanger<String>();
Future<WebSocket.Connection> future=client.open(new URI("ws://127.0.0.1:"+_serverPort+"/"),new WebSocket.OnTextMessage() Future<WebSocket.Connection> 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) public void onClose(int closeCode, String message)
{ {
//System.err.println("CLOSE "+closeCode+" "+message);
close.set(closeCode); close.set(closeCode);
closeMessage.append(message);
_latch.countDown(); _latch.countDown();
} }
@ -632,6 +635,7 @@ public class WebSocketClientTest
// Set up a consumer of received messages that waits a while before consuming // Set up a consumer of received messages that waits a while before consuming
Thread consumer = new Thread() Thread consumer = new Thread()
{ {
@Override
public void run() public void run()
{ {
try try
@ -689,8 +693,8 @@ public class WebSocketClientTest
_latch.await(10,TimeUnit.SECONDS); _latch.await(10,TimeUnit.SECONDS);
Assert.assertTrue(System.currentTimeMillis()-start<5000); 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 private void respondToClient(Socket connection, String serverResponse) throws IOException

View File

@ -1,8 +1,6 @@
package org.eclipse.jetty.websocket; package org.eclipse.jetty.websocket;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
@ -461,6 +459,7 @@ public class WebSocketMessageD13Test
// unblock the latch in 4s // unblock the latch in 4s
new Thread() new Thread()
{ {
@Override
public void run() public void run()
{ {
try try
@ -544,6 +543,7 @@ public class WebSocketMessageD13Test
final AtomicLong totalB=new AtomicLong(); final AtomicLong totalB=new AtomicLong();
new Thread() new Thread()
{ {
@Override
public void run() public void run()
{ {
try try
@ -950,9 +950,9 @@ public class WebSocketMessageD13Test
output.flush(); output.flush();
assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read()); assertEquals(0x80|WebSocketConnectionD13.OP_CLOSE,input.read());
assertEquals(2,input.read()); assertEquals(41,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read()); int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(0x81FF,code); assertEquals(1002,code); // Invalid code 0x81FF
} }
@Test @Test