Search in sources :

Example 1 with NetworkRequest

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;
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Response(com.github.ambry.protocol.Response) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) NetworkRequest(com.github.ambry.network.NetworkRequest)

Example 2 with NetworkRequest

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;
            }
        }
    }
}
Also used : NetworkRequest(com.github.ambry.network.NetworkRequest)

Aggregations

NetworkRequest (com.github.ambry.network.NetworkRequest)2 AdminResponse (com.github.ambry.protocol.AdminResponse)1 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)1 GetResponse (com.github.ambry.protocol.GetResponse)1 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)1 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)1 Response (com.github.ambry.protocol.Response)1