use of javax.websocket.Session in project jetty.project by eclipse.
the class AnnotatedEchoTest method testEcho.
@Test
public void testEcho() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
AnnotatedEchoClient echoer = new AnnotatedEchoClient();
Session session = container.connectToServer(echoer, serverUri);
session.getBasicRemote().sendText("Echo");
echoer.messageQueue.awaitMessages(1, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class MessageReceivingTest method testWholeTextMessage.
/**
* Method tests receiving of text messages at once.
*
* @throws Exception on exception occur
*/
@Test
@Ignore("flappy test")
public void testWholeTextMessage() throws Exception {
final TestEndpoint echoer = new TestEndpoint(new WholeStringCaptureHandler());
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends Endpoint
final Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("");
session.getBasicRemote().sendText("Echo");
session.getBasicRemote().sendText(VERY_LONG_STRING);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.handler.getMessageQueue().awaitMessages(2, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class ExtensionStackProcessingTest method testDeflateFrameExtension.
@Test
public void testDeflateFrameExtension() throws Exception {
assumeDeflateFrameAvailable();
ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions(Arrays.<Extension>asList(new JsrExtension("deflate-frame"))).build();
final String content = "deflate_me";
final CountDownLatch messageLatch = new CountDownLatch(1);
URI uri = URI.create("ws://localhost:" + connector.getLocalPort());
Session session = client.connectToServer(new EndpointAdapter() {
@Override
public void onMessage(String message) {
Assert.assertEquals(content, message);
messageLatch.countDown();
}
}, config, uri);
// Make sure everything is wired properly.
OutgoingFrames firstOut = ((JsrSession) session).getOutgoingHandler();
Assert.assertTrue(firstOut instanceof ExtensionStack);
ExtensionStack extensionStack = (ExtensionStack) firstOut;
Assert.assertTrue(extensionStack.isRunning());
OutgoingFrames secondOut = extensionStack.getNextOutgoing();
Assert.assertTrue(secondOut instanceof DeflateFrameExtension);
DeflateFrameExtension deflateExtension = (DeflateFrameExtension) secondOut;
Assert.assertTrue(deflateExtension.isRunning());
OutgoingFrames thirdOut = deflateExtension.getNextOutgoing();
Assert.assertTrue(thirdOut instanceof WebSocketClientConnection);
final CountDownLatch latch = new CountDownLatch(1);
session.getAsyncRemote().sendText(content, new SendHandler() {
@Override
public void onResult(SendResult result) {
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(messageLatch.await(5, TimeUnit.SECONDS));
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class ExtensionStackProcessingTest method testPerMessageDeflateExtension.
@Test
public void testPerMessageDeflateExtension() throws Exception {
assumeDeflateFrameAvailable();
ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions(Arrays.<Extension>asList(new JsrExtension("permessage-deflate"))).build();
final String content = "deflate_me";
final CountDownLatch messageLatch = new CountDownLatch(1);
URI uri = URI.create("ws://localhost:" + connector.getLocalPort());
Session session = client.connectToServer(new EndpointAdapter() {
@Override
public void onMessage(String message) {
Assert.assertEquals(content, message);
messageLatch.countDown();
}
}, config, uri);
final CountDownLatch latch = new CountDownLatch(1);
session.getAsyncRemote().sendText(content, new SendHandler() {
@Override
public void onResult(SendResult result) {
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(messageLatch.await(5, TimeUnit.SECONDS));
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class JsrBatchModeTest method testBatchModeOn.
@Test
public void testBatchModeOn() throws Exception {
ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build();
URI uri = URI.create("ws://localhost:" + connector.getLocalPort());
final CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter() {
@Override
public void onMessage(String message) {
latch.countDown();
}
};
try (Session session = client.connectToServer(endpoint, config, uri)) {
RemoteEndpoint.Async remote = session.getAsyncRemote();
remote.setBatchingAllowed(true);
Future<Void> future = remote.sendText("batch_mode_on");
// The write is aggregated and therefore completes immediately.
future.get(1, TimeUnit.MICROSECONDS);
// Did not flush explicitly, so the message should not be back yet.
Assert.assertFalse(latch.await(1, TimeUnit.SECONDS));
// Explicitly flush.
remote.flushBatch();
// Wait for the echo.
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
}
Aggregations