public void JSONBench(int clientCount, int iterations) throws Exception { ServerThread server = startup(); Thread.sleep(1000); JSONClient[] clients = new JSONClient[clientCount]; for (int i = 0; i < clientCount; i++) clients[i] = new JSONClient(i, iterations); long execTime = 0; long start = System.nanoTime(); for (JSONClient client : clients) { client.start(); } for (JSONClient client : clients) { client.join(); execTime += client.totalExecTime; } long finish = System.nanoTime(); double seconds = (finish - start) / (1000d * 1000d * 1000d); double rate = (iterations * clientCount) / seconds; double latency = execTime / (double) (iterations * clientCount); latency /= 1000d * 1000d; System.out.printf( "Simple bench did %.2f iterations / sec at %.2f ms latency per txn.\n", rate, latency); server.shutdown(); server.join(); }
public Order saveOrder( String address, String pizzaType, String quantity, String customerName, String creditCardNumber, String token) { Order order = new Order(address, pizzaType, customerName, quantity, creditCardNumber); String jsonString = JSONClient.generateSaveOrderMessage(order); String submitUrl = PizzaShackWebConfiguration.getInstance().getServerURL() + PIZZA_ORDER_URL; try { HttpResponse httpResponse = httpClient.doPost(submitUrl, "Bearer " + token, jsonString, "application/json"); String response = httpClient.getResponsePayload(httpResponse); // new instance with orderId order = JSONClient.getOrder(response); } catch (IOException e) { e.printStackTrace(); } return order; }
public Order getOrder(String orderId, String token) { String submitUrl = PizzaShackWebConfiguration.getInstance().getServerURL() + PIZZA_ORDER_URL + "/" + orderId; Order order = null; try { HttpResponse httpResponse = httpClient.doGet(submitUrl, "Bearer " + token); String response = httpClient.getResponsePayload(httpResponse); order = JSONClient.getOrder(response); return order; } catch (IOException e) { e.printStackTrace(); } return order; }