use of com.github.ambry.network.Request in project ambry by linkedin.
the class RequestHandlerPool method run.
public void run() {
while (true) {
try {
Request req = requestChannel.receiveRequest();
if (req.equals(EmptyRequest.getInstance())) {
logger.debug("Request handler {} received shut down command", id);
return;
}
requests.handleRequests(req);
logger.trace("Request handler {} handling request {}", id, req);
} catch (Throwable e) {
// TODO add metric to track background threads
logger.error("Exception when handling request", e);
// this is bad and we need to shutdown the app
Runtime.getRuntime().halt(1);
}
}
}
use of com.github.ambry.network.Request in project ambry by linkedin.
the class AmbryRequestsTest method sendRequestGetResponse.
// helpers
// general
/**
* Calls {@link AmbryRequests#handleRequests(Request)} with {@code request} and returns the {@link Response} received.
* @param request the {@link Request} to process
* @param expectedServerErrorCode the expected {@link ServerErrorCode} in the server response.
* @return the {@link Response} received.
* @throws InterruptedException
* @throws IOException
*/
private Response sendRequestGetResponse(RequestOrResponse request, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
Request mockRequest = MockRequest.fromRequest(request);
ambryRequests.handleRequests(mockRequest);
assertEquals("Request accompanying response does not match original request", mockRequest, requestResponseChannel.lastOriginalRequest);
assertNotNull("Response not sent", requestResponseChannel.lastResponse);
Response response = (Response) requestResponseChannel.lastResponse;
assertNotNull("Response is not of type Response", response);
assertEquals("Correlation id in response does match the one in the request", request.getCorrelationId(), response.getCorrelationId());
assertEquals("Client id in response does match the one in the request", request.getClientId(), response.getClientId());
assertEquals("Error code does not match expected", expectedServerErrorCode, response.getError());
return response;
}
Aggregations