use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_19.
/**
* send text message fragmented in 5 frames, with 2 pings and wait between.
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase5_19() throws Exception {
// phase 1
List<WebSocketFrame> send1 = new ArrayList<>();
send1.add(new TextFrame().setPayload("f1").setFin(false));
send1.add(new ContinuationFrame().setPayload(",f2").setFin(false));
send1.add(new PingFrame().setPayload("pong-1"));
List<WebSocketFrame> expect1 = new ArrayList<>();
expect1.add(new PongFrame().setPayload("pong-1"));
// phase 2
List<WebSocketFrame> send2 = new ArrayList<>();
send2.add(new ContinuationFrame().setPayload(",f3").setFin(false));
send2.add(new ContinuationFrame().setPayload(",f4").setFin(false));
send2.add(new PingFrame().setPayload("pong-2"));
send2.add(new ContinuationFrame().setPayload(",f5").setFin(true));
send2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect2 = new ArrayList<>();
expect2.add(new PongFrame().setPayload("pong-2"));
expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
// phase 1
fuzzer.send(send1);
fuzzer.expect(expect1);
// delay
TimeUnit.SECONDS.sleep(1);
// phase 2
fuzzer.send(send2);
fuzzer.expect(expect2);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_1.
/**
* Send ping fragmented in 2 packets
* @throws Exception on test failure
*/
@Test
public void testCase5_1() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new PingFrame().setPayload("hello, ").setFin(false));
send.add(new ContinuationFrame().setPayload("world"));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class TestABCase5 method testCase5_6.
/**
* Send text fragmented in 2 packets, with ping between them
* @throws Exception on test failure
*/
@Test
public void testCase5_6() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("hello, ").setFin(false));
send.add(new PingFrame().setPayload("ping"));
send.add(new ContinuationFrame().setPayload("world").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new PongFrame().setPayload("ping"));
expect.add(new TextFrame().setPayload("hello, world"));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging supress = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class PerMessageDeflateExtensionTest method testDraft21_Hello_UnCompressedBlock_Fragmented.
/**
* Decode payload example as seen in draft-ietf-hybi-permessage-compression-21.
* <p>
* Section 8.2.3.1: A message compressed using 1 compressed DEFLATE block (with fragmentation)
*/
@Test
public void testDraft21_Hello_UnCompressedBlock_Fragmented() {
Tester tester = clientExtensions.newTester("permessage-deflate");
tester.assertNegotiated("permessage-deflate");
// basic, 1 block, compressed with 0 compression level (aka, uncompressed).
tester.parseIncomingHex(// Fragment 1
"0x41 0x03 0xf2 0x48 0xcd", // Fragment 2
"0x80 0x04 0xc9 0xc9 0x07 0x00");
tester.assertHasFrames(new TextFrame().setPayload("He").setFin(false), new ContinuationFrame().setPayload("llo").setFin(true));
}
use of org.eclipse.jetty.websocket.common.frames.ContinuationFrame in project jetty.project by eclipse.
the class FragmentExtensionTest method testOutgoingFramesByMaxLength.
/**
* Verify that outgoing text frames are fragmented by the maxLength configuration.
* @throws IOException on test failure
*/
@Test
public void testOutgoingFramesByMaxLength() throws IOException {
OutgoingFramesCapture capture = new OutgoingFramesCapture();
FragmentExtension ext = new FragmentExtension();
ext.setBufferPool(bufferPool);
ext.setPolicy(WebSocketPolicy.newServerPolicy());
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=20");
ext.setConfig(config);
ext.setNextOutgoingFrames(capture);
// Quote
List<String> quote = new ArrayList<>();
quote.add("No amount of experimentation can ever prove me right;");
quote.add("a single experiment can prove me wrong.");
quote.add("-- Albert Einstein");
// Write quote as separate frames
for (String section : quote) {
Frame frame = new TextFrame().setPayload(section);
ext.outgoingFrame(frame, null, BatchMode.OFF);
}
// Expected Frames
List<WebSocketFrame> expectedFrames = new ArrayList<>();
expectedFrames.add(new TextFrame().setPayload("No amount of experim").setFin(false));
expectedFrames.add(new ContinuationFrame().setPayload("entation can ever pr").setFin(false));
expectedFrames.add(new ContinuationFrame().setPayload("ove me right;").setFin(true));
expectedFrames.add(new TextFrame().setPayload("a single experiment ").setFin(false));
expectedFrames.add(new ContinuationFrame().setPayload("can prove me wrong.").setFin(true));
expectedFrames.add(new TextFrame().setPayload("-- Albert Einstein").setFin(true));
// capture.dump();
int len = expectedFrames.size();
capture.assertFrameCount(len);
String prefix;
LinkedList<WebSocketFrame> frames = capture.getFrames();
for (int i = 0; i < len; i++) {
prefix = "Frame[" + i + "]";
WebSocketFrame actualFrame = frames.get(i);
WebSocketFrame expectedFrame = expectedFrames.get(i);
// System.out.printf("actual: %s%n",actualFrame);
// System.out.printf("expect: %s%n",expectedFrame);
// Validate Frame
Assert.assertThat(prefix + ".opcode", actualFrame.getOpCode(), is(expectedFrame.getOpCode()));
Assert.assertThat(prefix + ".fin", actualFrame.isFin(), is(expectedFrame.isFin()));
Assert.assertThat(prefix + ".rsv1", actualFrame.isRsv1(), is(expectedFrame.isRsv1()));
Assert.assertThat(prefix + ".rsv2", actualFrame.isRsv2(), is(expectedFrame.isRsv2()));
Assert.assertThat(prefix + ".rsv3", actualFrame.isRsv3(), is(expectedFrame.isRsv3()));
// Validate Payload
ByteBuffer expectedData = expectedFrame.getPayload().slice();
ByteBuffer actualData = actualFrame.getPayload().slice();
Assert.assertThat(prefix + ".payloadLength", actualData.remaining(), is(expectedData.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload", expectedData, actualData);
}
}
Aggregations