use of io.undertow.websockets.jsr.ServerWebSocketContainer in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testBinaryWithByteBufferByFuture.
@org.junit.Test
public void testBinaryWithByteBufferByFuture() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Future<Void>> sendResult = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult<?> latch = new FutureResult<>();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
@Override
public void onMessage(ByteBuffer message) {
ByteBuffer buf = ByteBuffer.allocate(message.remaining());
buf.put(message);
buf.flip();
sendResult.set(session.getAsyncRemote().sendBinary(buf));
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorkerSupplier(), DefaultServer.getBufferPool(), Collections.emptyList(), false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + DefaultServer.getHostAddress("default") + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(BinaryWebSocketFrame.class, payload, latch));
// FIXME UNDERTOW-1862 assertEquals(DONE, latch.getIoFuture().await());
latch.getIoFuture().get();
Future<Void> result = sendResult.get();
/* FIXME result.wait(4000);
assertTrue(result.isDone());*/
client.destroy();
}
Aggregations