use of org.eclipse.jetty.websocket.common.frames.PongFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_4.
/**
* Ping with 125 byte binary payload
* @throws Exception on test failure
*/
@Test
public void testCase2_4() throws Exception {
byte[] payload = new byte[125];
Arrays.fill(payload, (byte) 0xFE);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame().setPayload(copyOf(payload)));
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.frames.PongFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_6.
/**
* Ping with 125 byte binary payload (slow send)
* @throws Exception on test failure
*/
@Test
public void testCase2_6() throws Exception {
byte[] payload = new byte[125];
Arrays.fill(payload, (byte) '6');
List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL, "Test 2.6").asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame().setPayload(copyOf(payload)));
expect.add(new CloseInfo(StatusCode.NORMAL, "Test 2.6").asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
fuzzer.setSlowSendSegmentSize(1);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.PongFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_10.
/**
* 10 pings
* @throws Exception on test failure
*/
@Test
public void testCase2_10() throws Exception {
// send 10 pings each with unique payload
// send close
// expect 10 pongs with our unique payload
// expect close
int pingCount = 10;
List<WebSocketFrame> send = new ArrayList<>();
List<WebSocketFrame> expect = new ArrayList<>();
for (int i = 0; i < pingCount; i++) {
String payload = String.format("ping-%d[%X]", i, i);
send.add(new PingFrame().setPayload(payload));
expect.add(new PongFrame().setPayload(payload));
}
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
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.frames.PongFrame in project jetty.project by eclipse.
the class TestABCase2 method testCase2_2.
/**
* Ping with small text payload
* @throws Exception on test failure
*/
@Test
public void testCase2_2() throws Exception {
byte[] payload = StringUtil.getUtf8Bytes("Hello world");
List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame().setPayload(copyOf(payload)));
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.frames.PongFrame in project jetty.project by eclipse.
the class WebSocketFrame method copy.
public static WebSocketFrame copy(Frame original) {
WebSocketFrame copy;
switch(original.getOpCode()) {
case OpCode.BINARY:
copy = new BinaryFrame();
break;
case OpCode.TEXT:
copy = new TextFrame();
break;
case OpCode.CLOSE:
copy = new CloseFrame();
break;
case OpCode.CONTINUATION:
copy = new ContinuationFrame();
break;
case OpCode.PING:
copy = new PingFrame();
break;
case OpCode.PONG:
copy = new PongFrame();
break;
default:
throw new IllegalArgumentException("Cannot copy frame with opcode " + original.getOpCode() + " - " + original);
}
copy.copyHeaders(original);
ByteBuffer payload = original.getPayload();
if (payload != null) {
ByteBuffer payloadCopy = ByteBuffer.allocate(payload.remaining());
payloadCopy.put(payload.slice()).flip();
copy.setPayload(payloadCopy);
}
return copy;
}
Aggregations