use of com.github.ambry.network.NetworkRequest in project ambry by linkedin.
the class AmbryServerRequestsTest method sendRequestGetResponse.
// helpers
// general
/**
* Calls {@link AmbryRequests#handleRequests(NetworkRequest)} with {@code request} and returns the {@link Response} received.
* @param request the {@link NetworkRequest} 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 {
NetworkRequest 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;
}
use of com.github.ambry.network.NetworkRequest in project ambry by linkedin.
the class RequestHandler method run.
public void run() {
NetworkRequest req = null;
while (true) {
try {
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);
} finally {
if (req != null) {
req.release();
req = null;
}
}
}
}
Aggregations