ByteBuffer vs byte[] array tests
This commit is contained in:
parent
9cd2f887d1
commit
70b9f7245e
|
@ -1,7 +1,11 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.samples.AdapterConnectCloseSocket;
|
||||
import org.eclipse.jetty.websocket.api.samples.AnnotatedBasicSocket;
|
||||
import org.eclipse.jetty.websocket.api.samples.AnnotatedByteArraySocket;
|
||||
import org.eclipse.jetty.websocket.api.samples.ListenerBasicSocket;
|
||||
import org.eclipse.jetty.websocket.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
import org.junit.Rule;
|
||||
|
@ -22,7 +26,7 @@ public class WebSocketEventDriverTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterConnectClose()
|
||||
public void testAdapter_ConnectClose()
|
||||
{
|
||||
AdapterConnectCloseSocket socket = new AdapterConnectCloseSocket();
|
||||
WebSocketEventDriver driver = newDriver(socket);
|
||||
|
@ -38,7 +42,43 @@ public class WebSocketEventDriverTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testListenerBasic()
|
||||
public void testAnnotated_ByteArray()
|
||||
{
|
||||
AnnotatedByteArraySocket socket = new AnnotatedByteArraySocket();
|
||||
WebSocketEventDriver driver = newDriver(socket);
|
||||
|
||||
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
|
||||
driver.setConnection(conn);
|
||||
driver.onConnect();
|
||||
driver.onFrame(new BinaryFrame("Hello World".getBytes(StringUtil.__UTF8_CHARSET)));
|
||||
driver.onFrame(new CloseFrame(StatusCode.NORMAL));
|
||||
|
||||
socket.capture.assertEventCount(3);
|
||||
socket.capture.assertEventStartsWith(0,"onConnect");
|
||||
socket.capture.assertEvent(1,"onBinary([11],0,11)");
|
||||
socket.capture.assertEventStartsWith(2,"onClose(1000,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotated_ByteBuffer()
|
||||
{
|
||||
AnnotatedBasicSocket socket = new AnnotatedBasicSocket();
|
||||
WebSocketEventDriver driver = newDriver(socket);
|
||||
|
||||
LocalWebSocketConnection conn = new LocalWebSocketConnection(testname);
|
||||
driver.setConnection(conn);
|
||||
driver.onConnect();
|
||||
driver.onFrame(new BinaryFrame("Hello World".getBytes(StringUtil.__UTF8_CHARSET)));
|
||||
driver.onFrame(new CloseFrame(StatusCode.NORMAL));
|
||||
|
||||
socket.capture.assertEventCount(3);
|
||||
socket.capture.assertEventStartsWith(0,"onConnect");
|
||||
socket.capture.assertEvent(1,"onBinary(java.nio.HeapByteBuffer[pos=0 lim=11 cap=11])");
|
||||
socket.capture.assertEventStartsWith(2,"onClose(1000,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListener_Text()
|
||||
{
|
||||
ListenerBasicSocket socket = new ListenerBasicSocket();
|
||||
WebSocketEventDriver driver = newDriver(socket);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package org.eclipse.jetty.websocket.api.samples;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketBinary;
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.EventCapture;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
|
||||
@WebSocket
|
||||
public class AnnotatedBasicSocket
|
||||
{
|
||||
public EventCapture capture = new EventCapture();
|
||||
|
||||
@OnWebSocketBinary
|
||||
public void onBinary(ByteBuffer payload)
|
||||
{
|
||||
capture.add("onBinary(%s)",payload);
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onClose(int statusCode, String reason)
|
||||
{
|
||||
capture.add("onClose(%d, %s)",statusCode,capture.q(reason));
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.eclipse.jetty.websocket.api.samples;
|
||||
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketBinary;
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.EventCapture;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
|
||||
@WebSocket
|
||||
public class AnnotatedByteArraySocket
|
||||
{
|
||||
public EventCapture capture = new EventCapture();
|
||||
|
||||
@OnWebSocketBinary
|
||||
public void onBinary(byte payload[], int offset, int length)
|
||||
{
|
||||
capture.add("onBinary([%d],%d,%d)",payload.length,offset,length);
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onClose(int statusCode, String reason)
|
||||
{
|
||||
capture.add("onClose(%d, %s)",statusCode,capture.q(reason));
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue