Search in sources :

Example 16 with Response

use of com.github.ambry.protocol.Response in project ambry by linkedin.

the class InMemoryCloudDestinationErrorSimulationTest method testGetBlobErrorSimulation.

/**
 * test error simulation for GetBlobRequest
 * @throws Exception
 */
@Test
public void testGetBlobErrorSimulation() throws Exception {
    BlobId blobId = doPut(partitionId);
    ArrayList<BlobId> blobIdList = new ArrayList<BlobId>();
    blobIdList.add(blobId);
    PartitionRequestInfo partitionRequestInfo = new PartitionRequestInfo(partitionId, blobIdList);
    ArrayList<PartitionRequestInfo> partitionRequestInfoList = new ArrayList<PartitionRequestInfo>();
    partitionRequestInfoList.add(partitionRequestInfo);
    GetRequest getRequest = new GetRequest(1234, "clientId", MessageFormatFlags.Blob, partitionRequestInfoList, GetOption.None);
    RequestInfo requestInfo = new RequestInfo(hostname, port, getRequest, replica, null);
    ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
    GetResponse response = responseInfo.getError() == null ? (GetResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
    PartitionResponseInfo partitionResponseInfo = response.getPartitionResponseInfoList().get(0);
    Assert.assertEquals("GetRequest should succeed.", response.getError(), ServerErrorCode.No_Error);
    Assert.assertEquals("GetRequest partitionResponseInfo should succeed.", partitionResponseInfo.getErrorCode(), ServerErrorCode.No_Error);
    responseInfo.release();
    // inject error for cloud colo.
    cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.ID_Not_Found);
    getRequest = new GetRequest(1234, "clientId", MessageFormatFlags.Blob, partitionRequestInfoList, GetOption.None);
    requestInfo = new RequestInfo(hostname, port, getRequest, replica, null);
    responseInfo = sendAndWaitForResponses(requestInfo);
    response = responseInfo.getError() == null ? (GetResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
    partitionResponseInfo = response.getPartitionResponseInfoList().get(0);
    Assert.assertEquals("GetRequest responseInfo should have no error.", response.getError(), ServerErrorCode.No_Error);
    Assert.assertEquals("GetRequest partitionResponseInfo should be Blob_Not_Found", partitionResponseInfo.getErrorCode(), ServerErrorCode.Blob_Not_Found);
    responseInfo.release();
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) GetResponse(com.github.ambry.protocol.GetResponse) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) UndeleteResponse(com.github.ambry.protocol.UndeleteResponse) DeleteResponse(com.github.ambry.protocol.DeleteResponse) PutResponse(com.github.ambry.protocol.PutResponse) Response(com.github.ambry.protocol.Response) GetRequest(com.github.ambry.protocol.GetRequest) ArrayList(java.util.ArrayList) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) BlobId(com.github.ambry.commons.BlobId) GetResponse(com.github.ambry.protocol.GetResponse) Test(org.junit.Test)

Example 17 with Response

use of com.github.ambry.protocol.Response in project ambry by linkedin.

the class InMemoryCloudDestinationErrorSimulationTest method testUndeleteBlobErrorSimulation.

/**
 * test error simulation for UndeleteRequest
 * @throws Exception
 */
@Test
public void testUndeleteBlobErrorSimulation() throws Exception {
    BlobId blobId = doPut(partitionId);
    // Delete the blob first
    {
        DeleteRequest request = new DeleteRequest(1234, "clientId", blobId, SystemTime.getInstance().milliseconds());
        RequestInfo requestInfo = new RequestInfo(hostname, port, request, replica, null);
        ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
        DeleteResponse response = responseInfo.getError() == null ? (DeleteResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
        Assert.assertEquals("DeleteRequest should succeed.", response.getError(), ServerErrorCode.No_Error);
    }
    UndeleteRequest request = new UndeleteRequest(1234, "clientId", blobId, SystemTime.getInstance().milliseconds());
    RequestInfo requestInfo = new RequestInfo(hostname, port, request, replica, null);
    ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
    UndeleteResponse response = responseInfo.getError() == null ? (UndeleteResponse) RouterUtils.mapToReceivedResponse((UndeleteResponse) responseInfo.getResponse()) : null;
    Assert.assertEquals("UndeleteRequest should succeed.", response.getError(), ServerErrorCode.No_Error);
    response.release();
    // inject error for cloud colo.
    cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.Unknown_Error);
    request = new UndeleteRequest(1234, "clientId", blobId, SystemTime.getInstance().milliseconds());
    requestInfo = new RequestInfo(hostname, port, request, replica, null);
    responseInfo = sendAndWaitForResponses(requestInfo);
    response = responseInfo.getError() == null ? (UndeleteResponse) RouterUtils.mapToReceivedResponse((UndeleteResponse) responseInfo.getResponse()) : null;
    Assert.assertEquals("UndeleteRequest should return Unknown_Error.", response.getError(), ServerErrorCode.Unknown_Error);
    response.release();
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) GetResponse(com.github.ambry.protocol.GetResponse) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) UndeleteResponse(com.github.ambry.protocol.UndeleteResponse) DeleteResponse(com.github.ambry.protocol.DeleteResponse) PutResponse(com.github.ambry.protocol.PutResponse) Response(com.github.ambry.protocol.Response) DeleteResponse(com.github.ambry.protocol.DeleteResponse) UndeleteRequest(com.github.ambry.protocol.UndeleteRequest) UndeleteResponse(com.github.ambry.protocol.UndeleteResponse) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) BlobId(com.github.ambry.commons.BlobId) DeleteRequest(com.github.ambry.protocol.DeleteRequest) Test(org.junit.Test)

Example 18 with Response

use of com.github.ambry.protocol.Response in project ambry by linkedin.

the class InMemoryCloudDestinationErrorSimulationTest method testDeleteBlobErrorSimulation.

/**
 * test error simulation for DeleteRequest
 * @throws Exception
 */
@Test
public void testDeleteBlobErrorSimulation() throws Exception {
    BlobId blobId = doPut(partitionId);
    DeleteRequest request = new DeleteRequest(1234, "clientId", blobId, SystemTime.getInstance().milliseconds());
    RequestInfo requestInfo = new RequestInfo(hostname, port, request, replica, null);
    ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
    DeleteResponse response = responseInfo.getError() == null ? ((DeleteResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse())) : null;
    Assert.assertEquals("DeleteBlob should succeed.", response.getError(), ServerErrorCode.No_Error);
    // inject error for cloud colo.
    cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.Unknown_Error);
    request = new DeleteRequest(1234, "clientId", blobId, SystemTime.getInstance().milliseconds());
    requestInfo = new RequestInfo(hostname, port, request, replica, null);
    responseInfo = sendAndWaitForResponses(requestInfo);
    response = responseInfo.getError() == null ? ((DeleteResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse())) : null;
    Assert.assertEquals("DeleteBlob should return Unknown_Error.", response.getError(), ServerErrorCode.Unknown_Error);
    response.release();
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) GetResponse(com.github.ambry.protocol.GetResponse) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) UndeleteResponse(com.github.ambry.protocol.UndeleteResponse) DeleteResponse(com.github.ambry.protocol.DeleteResponse) PutResponse(com.github.ambry.protocol.PutResponse) Response(com.github.ambry.protocol.Response) DeleteResponse(com.github.ambry.protocol.DeleteResponse) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) BlobId(com.github.ambry.commons.BlobId) DeleteRequest(com.github.ambry.protocol.DeleteRequest) Test(org.junit.Test)

Example 19 with Response

use of com.github.ambry.protocol.Response in project ambry by linkedin.

the class RouterUtils method mapToReceivedResponse.

/**
 * This method is applicable when we are processing responses received from Azure APIs in Frontend via {@link LocalNetworkClient}.
 * The responses received from Azure are constructed as java objects such as {@link GetResponse}, {@link PutResponse} in
 * {@link com.github.ambry.protocol.AmbryRequests} class methods from {@link com.github.ambry.protocol.RequestHandler}
 * threads running within the Frontend itself. The content in these responses is available as buffer but we access it
 * as stream in the Frontend router. Hence, we create new Response objects by having a stream enclose the buffer.
 *
 * At the moment, only {@link GetResponse} carries content and needs to be constructed again as below. Other responses
 * like {@link PutResponse}, {@link DeleteResponse}, etc which don't carry any content don't need to be reconstructed
 * and can be referenced as they are.
 * @param sentResponse {@link Response} object constructed at sender side.
 * @return {@link Response} object constructed at receiver side.
 */
public static Response mapToReceivedResponse(Response sentResponse) {
    Response receivedResponse;
    if (sentResponse instanceof GetResponse) {
        GetResponse getResponse = (GetResponse) sentResponse;
        receivedResponse = new GetResponse(getResponse.getCorrelationId(), getResponse.getClientId(), getResponse.getPartitionResponseInfoList(), new ByteBufInputStream(getResponse.getDataToSend().content()), getResponse.getError());
    } else {
        receivedResponse = sentResponse;
    }
    return receivedResponse;
}
Also used : GetResponse(com.github.ambry.protocol.GetResponse) DeleteResponse(com.github.ambry.protocol.DeleteResponse) PutResponse(com.github.ambry.protocol.PutResponse) Response(com.github.ambry.protocol.Response) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) GetResponse(com.github.ambry.protocol.GetResponse)

Example 20 with Response

use of com.github.ambry.protocol.Response in project ambry by linkedin.

the class AmbryServerRequestsTest method sendAndVerifyStoreControlRequest.

/**
 * Sends and verifies that a {@link AdminRequestOrResponseType#BlobStoreControl} request received the error code
 * expected.
 * @param partitionId the {@link PartitionId} to send the request for. Can be {@code null}.
 * @param storeControlRequestType type of control operation that will be performed on certain store.
 * @param numReplicasCaughtUpPerPartition the number of peer replicas which have caught up with this store before proceeding.
 * @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
 * @throws InterruptedException
 * @throws IOException
 */
private void sendAndVerifyStoreControlRequest(PartitionId partitionId, BlobStoreControlAction storeControlRequestType, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, partitionId, correlationId, clientId);
    BlobStoreControlAdminRequest blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, storeControlRequestType, adminRequest);
    Response response = sendRequestGetResponse(blobStoreControlAdminRequest, expectedServerErrorCode);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    response.release();
}
Also used : ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) 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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Aggregations

GetResponse (com.github.ambry.protocol.GetResponse)23 Response (com.github.ambry.protocol.Response)23 AdminResponse (com.github.ambry.protocol.AdminResponse)18 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)18 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)18 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)18 AdminRequest (com.github.ambry.protocol.AdminRequest)12 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)12 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)12 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)12 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)12 PartitionId (com.github.ambry.clustermap.PartitionId)8 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)7 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)7 Test (org.junit.Test)7 BlobId (com.github.ambry.commons.BlobId)6 GetRequest (com.github.ambry.protocol.GetRequest)6 DeleteRequest (com.github.ambry.protocol.DeleteRequest)5 DeleteResponse (com.github.ambry.protocol.DeleteResponse)5 PutResponse (com.github.ambry.protocol.PutResponse)5