use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class MisbehavingClassTest method testListenerRuntimeOnConnect.
@Test
public void testListenerRuntimeOnConnect() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri());
StacklessLogging scope = new StacklessLogging(ListenerRuntimeOnConnectSocket.class, WebSocketSession.class)) {
client.setProtocols("listener-runtime-connect");
client.setTimeout(1, TimeUnit.SECONDS);
ListenerRuntimeOnConnectSocket socket = badSocketsServlet.listenerRuntimeConnect;
socket.reset();
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Close Latch", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("closeStatusCode", socket.closeStatusCode, is(StatusCode.SERVER_ERROR));
// Validate errors
assertThat("socket.onErrors", socket.errors.size(), is(1));
Throwable cause = socket.errors.pop();
assertThat("Error type", cause, instanceOf(RuntimeException.class));
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase6_GoodUTF method assertEchoTextMessage.
@Test
public void assertEchoTextMessage() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(msg));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(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);
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7 method testCase7_1_5.
/**
* Text fin=false, close, then continuation fin=true
* @throws Exception on test failure
*/
@Test
public void testCase7_1_5() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("an").setFin(false));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
send.add(new ContinuationFrame().setPayload("ticipation").setFin(true));
List<WebSocketFrame> expect = new ArrayList<>();
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);
fuzzer.expectNoMoreFrames();
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7 method testCase7_1_2.
/**
* Close frame, then another close frame (send frame ignored)
* @throws Exception on test failure
*/
@Test
public void testCase7_1_2() throws Exception {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
send.add(new CloseInfo().asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
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);
fuzzer.expectNoMoreFrames();
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7 method testCase7_3_5.
/**
* close with valid payload (with 123 byte reason)
* @throws Exception on test failure
*/
@Test
public void testCase7_3_5() throws Exception {
byte[] utf = new byte[123];
Arrays.fill(utf, (byte) '!');
String reason = StringUtil.toUTF8String(utf, 0, utf.length);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new CloseInfo(StatusCode.NORMAL, reason).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.NORMAL, reason).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging logging = new StacklessLogging(AbstractWebSocketConnection.class)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
fuzzer.expectNoMoreFrames();
}
}
Aggregations