Search in sources :

Example 1 with WebSocketAdapter

use of org.eclipse.jetty.websocket.api.WebSocketAdapter in project jetty.project by eclipse.

the class BatchModeTest method testBatchModeAuto.

@Test
public void testBatchModeAuto() throws Exception {
    URI uri = URI.create("ws://localhost:" + connector.getLocalPort());
    final CountDownLatch latch = new CountDownLatch(1);
    WebSocketAdapter adapter = new WebSocketAdapter() {

        @Override
        public void onWebSocketText(String message) {
            latch.countDown();
        }
    };
    try (Session session = client.connect(adapter, uri).get()) {
        RemoteEndpoint remote = session.getRemote();
        Future<Void> future = remote.sendStringByFuture("batch_mode_on");
        // The write is aggregated and therefore completes immediately.
        future.get(1, TimeUnit.MICROSECONDS);
        // Wait for the echo.
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    }
}
Also used : WebSocketAdapter(org.eclipse.jetty.websocket.api.WebSocketAdapter) RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Aggregations

URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RemoteEndpoint (org.eclipse.jetty.websocket.api.RemoteEndpoint)1 Session (org.eclipse.jetty.websocket.api.Session)1 WebSocketAdapter (org.eclipse.jetty.websocket.api.WebSocketAdapter)1 Test (org.junit.Test)1