use of org.apache.tomcat.websocket.TesterMessageCountClient.BasicText in project tomcat by apache.
the class TestShutdown method testShutdownBufferedMessages.
@Test
public void testShutdownBufferedMessages() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(EchoBufferedConfig.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, clientEndpointConfig, new URI("ws://localhost:" + getPort() + "/test"));
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getBasicRemote().sendText("Hello");
int count = 0;
while (count < 10 && EchoBufferedEndpoint.messageCount.get() == 0) {
Thread.sleep(200);
count++;
}
Assert.assertNotEquals("Message not received by server", EchoBufferedEndpoint.messageCount.get(), 0);
tomcat.stop();
Assert.assertTrue("Latch expired waiting for message", latch.await(10, TimeUnit.SECONDS));
}
Aggregations