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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations