@Test public void testAccessRequestCookies() throws Exception { BlockheadClient client = new BlockheadClient(server.getServerUri()); client.setTimeout(1, TimeUnit.SECONDS); try { client.connect(); client.sendStandardRequest(); client.expectUpgradeResponse(); client.write(new TextFrame().setPayload("info")); EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS); WebSocketFrame resp = frames.poll(); String textMsg = resp.getPayloadAsUTF8(); assertThat( "DecoratedObjectFactory", textMsg, containsString("Object is a DecoratedObjectFactory")); assertThat("decorators.size", textMsg, containsString("Decorators.size = [1]")); assertThat( "decorator type", textMsg, containsString("decorator[] = " + DummyLegacyDecorator.class.getName())); } finally { client.close(); } }
/** * Test session open session cleanup (bug #474936) * * @throws Exception on test failure */ @Test public void testOpenSessionCleanup() throws Exception { int iterationCount = 100; StdErrLog.getLogger(FastFailSocket.class).setLevel(StdErrLog.LEVEL_OFF); StdErrLog sessLog = StdErrLog.getLogger(WebSocketSession.class); int oldLevel = sessLog.getLevel(); sessLog.setLevel(StdErrLog.LEVEL_OFF); for (int requests = 0; requests < iterationCount; requests++) { fastFail(); fastClose(); dropConnection(); } sessLog.setLevel(oldLevel); try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) { client.setProtocols("container"); client.setTimeout(1, TimeUnit.SECONDS); client.connect(); client.sendStandardRequest(); client.expectUpgradeResponse(); client.write(new TextFrame().setPayload("calls")); client.write(new TextFrame().setPayload("openSessions")); EventQueue<WebSocketFrame> frames = client.readFrames(3, 6, TimeUnit.SECONDS); WebSocketFrame frame; String resp; frame = frames.poll(); assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.TEXT)); resp = frame.getPayloadAsUTF8(); assertThat( "Should only have 1 open session", resp, containsString("calls=" + ((iterationCount * 2) + 1))); frame = frames.poll(); assertThat("frames[1].opcode", frame.getOpCode(), is(OpCode.TEXT)); resp = frame.getPayloadAsUTF8(); assertThat("Should only have 1 open session", resp, containsString("openSessions.size=1\n")); frame = frames.poll(); assertThat("frames[2].opcode", frame.getOpCode(), is(OpCode.CLOSE)); CloseInfo close = new CloseInfo(frame); assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.NORMAL)); client.write(close.asFrame()); // respond with close // ensure server socket got close event assertThat( "Open Sessions Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true)); assertThat("Open Sessions.statusCode", closeSocket.closeStatusCode, is(StatusCode.NORMAL)); assertThat("Open Sessions.errors", closeSocket.errors.size(), is(0)); } }
public void clear() { messageQueue.clear(); }
public void awaitMessage(int expectedMessageCount, TimeUnit timeoutUnit, int timeoutDuration) throws TimeoutException, InterruptedException { messageQueue.awaitEventCount(expectedMessageCount, timeoutDuration, timeoutUnit); }
public void assertMessage(String expected) { String actual = messageQueue.poll(); Assert.assertEquals("Message", expected, actual); }
@Override public void onWebSocketText(String message) { LOG.debug("{} onWebSocketText({})", id, message); messageQueue.offer(message); dataLatch.countDown(); }
@Override public void onWebSocketError(Throwable cause) { LOG.debug("{} onWebSocketError", id, cause); Assert.assertThat("Error capture", errorQueue.offer(cause), is(true)); }
@Override public void onWebSocketBinary(byte[] payload, int offset, int len) { LOG.debug("{} onWebSocketBinary(byte[{}],{},{})", id, payload.length, offset, len); messageQueue.offer(MessageDebug.toDetailHint(payload, offset, len)); dataLatch.countDown(); }