use of perf.test.utils.BackendResponse in project WSPerfLab by Netflix-Skunkworks.
the class TestRouteBasic method handle.
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
long startTime = System.currentTimeMillis();
List<String> _id = request.getQueryParameters().get("id");
if (_id == null || _id.size() != 1) {
return writeError(request, response, "Please provide a numerical 'id' value. It can be a random number (uuid).");
}
long id = Long.parseLong(String.valueOf(_id.get(0)));
Observable<List<BackendResponse>> acd = getDataFromBackend("/mock.json?numItems=2&itemSize=50&delay=50&id=" + id).doOnError(Throwable::printStackTrace).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseA -> {
Observable<BackendResponse> responseC = getDataFromBackend("/mock.json?numItems=1&itemSize=5000&delay=80&id=" + responseA.getResponseKey());
Observable<BackendResponse> responseD = getDataFromBackend("/mock.json?numItems=1&itemSize=1000&delay=1&id=" + responseA.getResponseKey());
return Observable.zip(Observable.just(responseA), responseC, responseD, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
Observable<List<BackendResponse>> be = getDataFromBackend("/mock.json?numItems=25&itemSize=30&delay=150&id=" + id).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseB -> {
Observable<BackendResponse> responseE = getDataFromBackend("/mock.json?numItems=100&itemSize=30&delay=4&id=" + responseB.getResponseKey());
return Observable.zip(Observable.just(responseB), responseE, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
return Observable.zip(acd, be, (_acd, _be) -> {
BackendResponse responseA = _acd.get(0);
BackendResponse responseB = _be.get(0);
BackendResponse responseC = _acd.get(1);
BackendResponse responseD = _acd.get(2);
BackendResponse responseE = _be.get(1);
return new BackendResponse[] { responseA, responseB, responseC, responseD, responseE };
}).flatMap(backendResponses -> {
try {
ByteArrayOutputStream responseStream = ServiceResponseBuilder.buildTestAResponse(jsonFactory, backendResponses);
response.getHeaders().addHeader("Content-Type", "application/json");
addResponseHeaders(response, startTime);
int contentLength = responseStream.size();
response.getHeaders().addHeader("Content-Length", contentLength);
return response.writeBytesAndFlush(responseStream.toByteArray());
} catch (Exception e) {
return writeError(request, response, "Failed: " + e.getMessage());
}
}).doOnError(Throwable::printStackTrace);
}
use of perf.test.utils.BackendResponse in project WSPerfLab by Netflix-Skunkworks.
the class TestCaseAServlet method get.
public BackendResponse get(String url) {
String uri = backendMockUriPrefix + url;
HttpGet httpGet = new HttpGet(uri);
try {
HttpResponse response = client.execute(httpGet);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failure: " + response.getStatusLine());
}
HttpEntity entity = response.getEntity();
BackendResponse backendResponse = BackendResponse.fromJson(jsonFactory, entity.getContent());
// ensure it is fully consumed
EntityUtils.consume(entity);
return backendResponse;
} catch (Exception e) {
throw new RuntimeException("Failure retrieving: " + uri, e);
} finally {
httpGet.releaseConnection();
}
}
use of perf.test.utils.BackendResponse in project WSPerfLab by Netflix-Skunkworks.
the class TestCaseAServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long startTime = System.currentTimeMillis();
try {
Object _id = request.getParameter("id");
if (_id == null) {
response.getWriter().println("Please provide a numerical 'id' value. It can be a random number (uuid).");
response.setStatus(500);
return;
}
final long id = Long.parseLong(String.valueOf(_id));
try {
/* First 2 requests (A, B) in parallel */
final Future<BackendResponse> aResponseFuture = queueGet("/mock.json?type=A&numItems=2&itemSize=50&delay=50&id=" + id);
final Future<BackendResponse> bResponseFuture = queueGet("/mock.json?type=B&numItems=25&itemSize=30&delay=150&id=" + id);
/* When response A received perform C & D */
// spawned in another thread so we don't block the ability to B/E to proceed in parallel
Future<BackendResponse[]> aGroupResponses = executor.submit(new Callable<BackendResponse[]>() {
@Override
public BackendResponse[] call() throws Exception {
BackendResponse aResponse = aResponseFuture.get();
final Future<BackendResponse> cResponse = queueGet("/mock.json?type=C&numItems=1&itemSize=5000&delay=80&id=" + aResponse.getResponseKey());
final Future<BackendResponse> dResponse = queueGet("/mock.json?type=D&numItems=1&itemSize=1000&delay=1&id=" + aResponse.getResponseKey());
return new BackendResponse[] { aResponse, cResponse.get(), dResponse.get() };
}
});
/* When response B is received perform E */
BackendResponse b = bResponseFuture.get();
BackendResponse e = get("/mock.json?type=E&numItems=100&itemSize=30&delay=4&id=" + b.getResponseKey());
/*
* Parse JSON so we can extract data and combine data into a single response.
*
* This simulates what real web-services do most of the time.
*/
BackendResponse a = aGroupResponses.get()[0];
BackendResponse c = aGroupResponses.get()[1];
BackendResponse d = aGroupResponses.get()[2];
//EventLogger.log(requestId, "build-response-start");
ByteArrayOutputStream bos = ServiceResponseBuilder.buildTestAResponse(jsonFactory, a, b, c, d, e);
//EventLogger.log(requestId, "build-response-end");
// output to stream
//EventLogger.log(requestId, "flush-response-start");
response.getWriter().write(bos.toString());
//EventLogger.log(requestId, "flush-response-end");
} catch (Exception e) {
// error that needs to be returned
response.setStatus(500);
response.getWriter().println("Error: " + e.getMessage());
e.printStackTrace();
}
} finally {
ServiceResponseBuilder.addResponseHeaders(response, startTime);
}
}
Aggregations