Fixing compile issues

This commit is contained in:
Joakim Erdfelt 2012-07-06 08:49:30 -07:00
parent 4f30fe2a40
commit 89d6e8ddbf
2 changed files with 158 additions and 127 deletions

View File

@ -0,0 +1,43 @@
package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.junit.Assert;
public class ByteBufferAssert
{
public static void assertEquals(String message, byte[] expected, byte[] actual)
{
Assert.assertThat(message + " byte[].length",actual.length,is(expected.length));
int len = expected.length;
for (int i = 0; i < len; i++)
{
Assert.assertThat(message + " byte[" + i + "]",actual[i],is(expected[i]));
}
}
public static void assertEquals(String message, ByteBuffer expectedBuffer, ByteBuffer actualBuffer)
{
byte expectedBytes[] = BufferUtil.toArray(expectedBuffer);
byte actualBytes[] = BufferUtil.toArray(actualBuffer);
assertEquals(message,expectedBytes,actualBytes);
}
public static void assertEquals(String message, String expectedString, ByteBuffer actualBuffer)
{
String actualString = BufferUtil.toString(actualBuffer);
Assert.assertThat(message,expectedString,is(actualString));
}
public static void assertSize(String message, int expectedSize, ByteBuffer buffer)
{
if ((expectedSize == 0) && (buffer == null))
{
return;
}
Assert.assertThat(message + " buffer.remaining",buffer.remaining(),is(expectedSize));
}
}

View File

@ -2,27 +2,22 @@ package org.eclipse.jetty.websocket.server.ab;
import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.ByteBufferAssert;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.CloseFrame;
import org.eclipse.jetty.websocket.frames.FrameBuilder;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.frames.PongFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
import org.eclipse.jetty.websocket.generator.FrameGenerator;
import org.eclipse.jetty.websocket.protocol.OpCode;
import org.eclipse.jetty.websocket.server.ByteBufferAssert;
import org.eclipse.jetty.websocket.server.SimpleServletServer;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
import org.eclipse.jetty.websocket.server.WebSocketServlet;
@ -33,9 +28,6 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
public class TestABCase5
{
@ -66,14 +58,14 @@ public class TestABCase5
}
// echo the message back.
//try
// {
// getConnection().write(message);
// }
//catch (IOException e)
// {
// e.printStackTrace(System.err);
// }
// try
// {
// getConnection().write(message);
// }
// catch (IOException e)
// {
// e.printStackTrace(System.err);
// }
}
}
@ -131,11 +123,11 @@ public class TestABCase5
client.writeRaw(buf2);
// Read frame
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame", frame instanceof CloseFrame);
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
Assert.assertThat("CloseFrame.status code",((CloseFrame)frame).getStatusCode(),is(1002));
}
@ -166,9 +158,9 @@ public class TestABCase5
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame", frame instanceof CloseFrame);
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
Assert.assertThat("CloseFrame.status code",((CloseFrame)frame).getStatusCode(),is(1002));
}
@ -219,9 +211,9 @@ public class TestABCase5
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame", frame instanceof CloseFrame);
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
Assert.assertThat("CloseFrame.status code",((CloseFrame)frame).getStatusCode(),is(1002));
}
@ -231,7 +223,6 @@ public class TestABCase5
}
}
@Test
public void testCase5_2PongIn2PacketsWithBuilder() throws Exception
{
@ -256,9 +247,9 @@ public class TestABCase5
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame", frame instanceof CloseFrame);
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
Assert.assertThat("CloseFrame.status code",((CloseFrame)frame).getStatusCode(),is(1002));
}
@ -268,9 +259,8 @@ public class TestABCase5
}
}
@Test
@Ignore ("not supported in implementation yet, requires server side message aggregation")
@Ignore("not supported in implementation yet, requires server side message aggregation")
public void testCase5_3TextIn2Packets() throws Exception
{
BlockheadClient client = new BlockheadClient(server.getServerUri());
@ -309,11 +299,11 @@ public class TestABCase5
client.writeRaw(buf2);
// Read frame
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be text frame", frame instanceof TextFrame);
Assert.assertTrue("frame should be text frame",frame instanceof TextFrame);
Assert.assertThat("TextFrame.payload",((TextFrame)frame).getPayloadUTF8(),is(fragment1 + fragment2));
}
@ -324,7 +314,7 @@ public class TestABCase5
}
@Test
@Ignore ("not supported in implementation yet, requires server side message aggregation")
@Ignore("not supported in implementation yet, requires server side message aggregation")
public void testCase5_6TextPingRemainingText() throws Exception
{
BlockheadClient client = new BlockheadClient(server.getServerUri());
@ -388,17 +378,16 @@ public class TestABCase5
Queue<BaseFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Assert.assertTrue("first frame should be pong frame", frame instanceof PongFrame );
Assert.assertTrue("first frame should be pong frame",frame instanceof PongFrame);
ByteBuffer payload1 = ByteBuffer.allocate(pingPayload.length());
payload1.flip();
ByteBufferAssert.assertEquals("payloads should be equal" , payload1, ((PongFrame)frame).getPayload() );
ByteBufferAssert.assertEquals("payloads should be equal",payload1,((PongFrame)frame).getPayload());
frame = (BaseFrame)frames.remove();
Assert.assertTrue("second frame should be text frame", frame instanceof TextFrame );
frame = frames.remove();
Assert.assertTrue("second frame should be text frame",frame instanceof TextFrame);
Assert.assertThat("TextFrame.payload",((TextFrame)frame).getPayloadUTF8(),is(fragment1 + fragment2));
}
@ -408,9 +397,8 @@ public class TestABCase5
}
}
@Test
@Ignore ("not supported in implementation yet, requires server side message aggregation")
@Ignore("not supported in implementation yet, requires server side message aggregation")
public void testCase5_6TextPingRemainingTextWithBuilder() throws Exception
{
BlockheadClient client = new BlockheadClient(server.getServerUri());
@ -447,17 +435,16 @@ public class TestABCase5
Queue<BaseFrame> frames = client.readFrames(2,TimeUnit.MILLISECONDS,500);
BaseFrame frame = frames.remove();
Assert.assertTrue("first frame should be pong frame", frame instanceof PongFrame );
Assert.assertTrue("first frame should be pong frame",frame instanceof PongFrame);
ByteBuffer payload1 = ByteBuffer.allocate(pingPayload.length());
payload1.flip();
ByteBufferAssert.assertEquals("payloads should be equal" , payload1, ((PongFrame)frame).getPayload() );
ByteBufferAssert.assertEquals("payloads should be equal",payload1,((PongFrame)frame).getPayload());
frame = (BaseFrame)frames.remove();
Assert.assertTrue("second frame should be text frame", frame instanceof TextFrame );
frame = frames.remove();
Assert.assertTrue("second frame should be text frame",frame instanceof TextFrame);
Assert.assertThat("TextFrame.payload",((TextFrame)frame).getPayloadUTF8(),is(textPayload1 + textPayload2));
}
@ -468,7 +455,7 @@ public class TestABCase5
}
@Test
@Ignore ("AB tests have chop concepts currently unsupported by test...I think, also the string being returns is not Bad Continuation")
@Ignore("AB tests have chop concepts currently unsupported by test...I think, also the string being returns is not Bad Continuation")
public void testCase5_9BadContinuation() throws Exception
{
BlockheadClient client = new BlockheadClient(server.getServerUri());
@ -499,13 +486,14 @@ public class TestABCase5
// Read frame
Queue<BaseFrame> frames = client.readFrames(1,TimeUnit.MILLISECONDS,500);
BaseFrame frame = (BaseFrame)frames.remove();
BaseFrame frame = frames.remove();
Assert.assertTrue("frame should be close frame", frame instanceof CloseFrame);
Assert.assertTrue("frame should be close frame",frame instanceof CloseFrame);
Assert.assertThat("CloseFrame.status code",((CloseFrame)frame).getStatusCode(),is(1002));
Assert.assertThat("CloseFrame.reason", ((CloseFrame)frame).getReason(),is("Bad Continuation") ); // TODO put close reasons into public strings in impl someplace
Assert.assertThat("CloseFrame.reason",((CloseFrame)frame).getReason(),is("Bad Continuation")); // TODO put close reasons into public strings in impl
// someplace
}
finally