Created
July 2, 2013 14:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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