in java/ws-server/src/main/java/com/epam/deltix/tbwg/webapp/utils/ApiTest.java [39:82]
public static void main(String[] args) throws InterruptedException, IOException {
Properties values = SimpleArgsParser.process(args);
toFile = Boolean.parseBoolean(values.getProperty("-tofile", "False"));
String url = values.getProperty("-url", "http://localhost:8099/api/v0/speed.test.stream/select");
int requests = Integer.parseInt(values.getProperty("-requests", "8"));
if (toFile) {
writer = new PrintWriter(new FileWriter("api_" + Integer.toString(requests) + ".txt"));
}
Stats stats = new Stats();
AsyncHttpClient client = asyncHttpClient();
CountDownLatch latch = new CountDownLatch(requests);
long start = System.currentTimeMillis();
for (int i = 0; i < requests; i++) {
MyAsyncHandler handler = new MyAsyncHandler();
ListenableFuture<Response> whenResponse = client.prepareGet(url).execute(handler);
whenResponse.addListener(() -> {
try {
Response response = whenResponse.get();
int length = response.getResponseBody().length();
double time = handler.getPerformanceTime();
double speed = length / time / 1024 / 1024;
System.out.printf("Response[%d]. status: %d; speed: %.10f Mib/sec\n",
handler.id, response.getStatusCode(), speed);
if (toFile) {
writer.printf("Response[%d]. status: %d; speed: %.10f Mib/sec\n",
handler.id, response.getStatusCode(), speed);
}
stats.addResponse();
stats.addLength(length);
latch.countDown();
} catch (InterruptedException | ExecutionException exc) {
exc.printStackTrace();
}
}, null);
}
latch.await();
stats.printStats(start);
if (toFile) {
writer.close();
}
System.exit(0);
}