Skip to content

Instantly share code, notes, and snippets.

@colaru
Created July 2, 2013 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colaru/5909656 to your computer and use it in GitHub Desktop.
Save colaru/5909656 to your computer and use it in GitHub Desktop.
Integration test for Vert.x WebSocket server that insteed of responding to a request, register a Event Bus handler that send back to client all events on Event Bus for a given topic.
@Test
public void testWebSocketServer() {
long startTime;
long endTime;
startTime = System.currentTimeMillis();
container.logger().info("Starting web socket test");
HttpClient client = vertx.createHttpClient().setPort(8081).setHost("localhost").setMaxPoolSize(CONNS);
for (int i = 0; i < CONNS; i++) {
container.logger().info("Connecting ws: " + (i+1));
client.connectWebsocket("/rtp", new Handler<WebSocket>() {
public void handle(WebSocket ws) {
ws.write(new Buffer(Util.createEventMessage().toString()));
vertx.eventBus().publish("default.address", Util.createEventMessage().toString());
ws.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buff) {
assertEquals(buff.toString(), Util.createEventMessage().toString());
container.logger().info("Response: " + buff.toString());
testComplete();
}
});
}
});
}
endTime = System.currentTimeMillis();
container.logger().info("Ending web socket test (asynchronous call) client in: " + (endTime - startTime) + " milliseconds");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment