use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase4 method testCase4_1_2.
/**
* Send opcode 4 (reserved), with payload
* @throws Exception on test failure
*/
@Test
public void testCase4_1_2() throws Exception {
byte[] payload = StringUtil.getUtf8Bytes("reserved payload");
ByteBuffer buf = ByteBuffer.wrap(payload);
List<WebSocketFrame> send = new ArrayList<>();
// intentionally bad
send.add(new BadFrame((byte) 4).setPayload(buf));
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging logging = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase4 method testCase4_1_5.
/**
* Send small text, then frame with opcode 7 (reserved) w/payload, then ping
* @throws Exception on test failure
*/
@Test
public void testCase4_1_5() throws Exception {
ByteBuffer buf = ByteBuffer.wrap(StringUtil.getUtf8Bytes("bad"));
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("hello"));
// intentionally bad
send.add(new BadFrame((byte) 7).setPayload(buf));
send.add(new PingFrame());
List<WebSocketFrame> expect = new ArrayList<>();
// echo
expect.add(new TextFrame().setPayload("hello"));
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging logging = new StacklessLogging(Parser.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class OnCloseTest method testOnCloseCall.
@Test
public void testOnCloseCall() throws Exception {
// Scan annotations
AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, testcase.closeClass);
AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
scanner.scan();
// Build up EventDriver
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
ClientEndpointConfig config = metadata.getConfig();
TrackingSocket endpoint = (TrackingSocket) testcase.closeClass.newInstance();
EndpointInstance ei = new EndpointInstance(endpoint, config, metadata);
JsrEvents<ClientEndpoint, ClientEndpointConfig> jsrevents = new JsrEvents<>(metadata);
EventDriver driver = new JsrAnnotatedEventDriver(policy, ei, jsrevents);
// Execute onClose call
driver.onClose(new CloseInfo(StatusCode.NORMAL, "normal"));
// Test captured event
EventQueue<String> events = endpoint.eventQueue;
Assert.assertThat("Number of Events Captured", events.size(), is(1));
String closeEvent = events.poll();
Assert.assertThat("Close Event", closeEvent, is(testcase.expectedCloseEvent));
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class WebSocketCloseTest method fastClose.
@SuppressWarnings("Duplicates")
private void fastClose() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("fastclose");
client.setTimeout(1, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.readFrames(1, 1, TimeUnit.SECONDS);
CloseInfo close = new CloseInfo(StatusCode.NORMAL, "Normal");
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.NORMAL));
// Notify server of close handshake
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Fast Close Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Fast Close.statusCode", closeSocket.closeStatusCode, is(StatusCode.NORMAL));
}
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class WebSocketCloseTest method fastFail.
private void fastFail() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("fastfail");
client.setTimeout(1, TimeUnit.SECONDS);
try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.readFrames(1, 1, TimeUnit.SECONDS);
CloseInfo close = new CloseInfo(StatusCode.NORMAL, "Normal");
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Fast Fail Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("Fast Fail.statusCode", closeSocket.closeStatusCode, is(StatusCode.SERVER_ERROR));
assertThat("Fast Fail.errors", closeSocket.errors.size(), is(1));
}
}
}
Aggregations