use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.
the class TestABCase9 method assertSlowFrameEcho.
private void assertSlowFrameEcho(byte opcode, int overallMsgSize, int segmentSize) throws Exception {
byte[] msg = new byte[overallMsgSize];
Arrays.fill(msg, (byte) 'M');
ByteBuffer buf = ByteBuffer.wrap(msg);
List<WebSocketFrame> send = new ArrayList<>();
send.add(toDataFrame(opcode).setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(toDataFrame(opcode).setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
fuzzer.setSlowSendSegmentSize(segmentSize);
fuzzer.send(send);
fuzzer.expect(expect, 8, TimeUnit.SECONDS);
}
}
use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.
the class TestABCase9 method testCase9_2_2.
/**
* Echo 256KB binary message (1 frame)
* @throws Exception on test failure
*/
@Test
public void testCase9_2_2() throws Exception {
byte[] data = new byte[256 * KBYTE];
Arrays.fill(data, (byte) 0x22);
ByteBuffer buf = ByteBuffer.wrap(data);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new BinaryFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new BinaryFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.
the class TestABCase9 method testCase9_1_2.
/**
* Echo 256KB text message (1 frame)
* @throws Exception on test failure
*/
@Test
public void testCase9_1_2() throws Exception {
byte[] utf = new byte[256 * KBYTE];
Arrays.fill(utf, (byte) 'y');
ByteBuffer buf = ByteBuffer.wrap(utf);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.
the class TestABCase9 method assertMultiFrameEcho.
private void assertMultiFrameEcho(byte opcode, int overallMsgSize, int fragmentSize) throws Exception {
byte[] msg = new byte[overallMsgSize];
Arrays.fill(msg, (byte) 'M');
List<WebSocketFrame> send = new ArrayList<>();
byte[] frag;
int remaining = msg.length;
int offset = 0;
boolean fin;
ByteBuffer buf;
;
byte op = opcode;
while (remaining > 0) {
int len = Math.min(remaining, fragmentSize);
frag = new byte[len];
System.arraycopy(msg, offset, frag, 0, len);
remaining -= len;
fin = (remaining <= 0);
buf = ByteBuffer.wrap(frag);
send.add(toDataFrame(op).setPayload(buf).setFin(fin));
offset += len;
op = OpCode.CONTINUATION;
}
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(toDataFrame(opcode).setPayload(copyOf(msg)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect, 8, TimeUnit.SECONDS);
}
}
use of org.eclipse.jetty.websocket.common.test.Fuzzer in project jetty.project by eclipse.
the class TestABCase9 method testCase9_1_4.
/**
* Echo 4MB text message (1 frame)
* @throws Exception on test failure
*/
@Test
public void testCase9_1_4() throws Exception {
byte[] utf = new byte[4 * MBYTE];
Arrays.fill(utf, (byte) 'y');
ByteBuffer buf = ByteBuffer.wrap(utf);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect, 8, TimeUnit.SECONDS);
}
}
Aggregations