use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryServerRequestsTest method sendAndVerifyGetOriginalStoreKeys.
/**
* Sends and verifies that GetRequest with a list of original blobIds works correctly.
* @param blobIds List of blobIds for GetRequest.
* @param expectedErrorCode the {@link ServerErrorCode} expected in the response.
* @throws InterruptedException
* @throws IOException
*/
private void sendAndVerifyGetOriginalStoreKeys(List<BlobId> blobIds, ServerErrorCode expectedErrorCode) throws InterruptedException, IOException {
PartitionId partitionId = blobIds.get(0).getPartition();
int correlationId = blobIds.get(0).getContainerId();
String clientId = TestUtils.getRandomString(10);
PartitionRequestInfo pRequestInfo = new PartitionRequestInfo(partitionId, blobIds);
RequestOrResponse request = new GetRequest(correlationId, clientId, MessageFormatFlags.All, Collections.singletonList(pRequestInfo), GetOption.Include_All);
storageManager.resetStore();
if (!expectedErrorCode.equals(ServerErrorCode.Unknown_Error)) {
// known error will be filled to each PartitionResponseInfo and set ServerErrorCode.No_Error in response.
Response response = sendRequestGetResponse(request, ServerErrorCode.No_Error);
assertEquals("Operation received at the store not as expected", RequestOrResponseType.GetRequest, MockStorageManager.operationReceived);
for (PartitionResponseInfo info : ((GetResponse) response).getPartitionResponseInfoList()) {
assertEquals("Error code does not match expected", expectedErrorCode, info.getErrorCode());
}
response.release();
} else {
sendRequestGetResponse(request, ServerErrorCode.Unknown_Error).release();
}
}
use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryRequestsTest method doCatchupStatusTest.
// catchupStatusSuccessTest() and catchupStatusFailureTest() helpers
/**
* Does the test for {@link AdminRequestOrResponseType#CatchupStatus} by checking that the request is correctly
* deserialized in {@link AmbryRequests} and the necessary info obtained from {@link ReplicationManager}.
* @param id the {@link PartitionId} to disable replication on. Can be {@code null}.
* @param acceptableLagInBytes the value of acceptable lag to set in the {@link CatchupStatusAdminRequest}.
* @param numReplicasCaughtUpPerPartition the value of num replicas caught up per partition to set in the
* {@link CatchupStatusAdminRequest}.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @param expectedIsCaughtUp the expected return from {@link CatchupStatusAdminResponse#isCaughtUp()}.
* @throws InterruptedException
* @throws IOException
*/
private void doCatchupStatusTest(PartitionId id, long acceptableLagInBytes, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode, boolean expectedIsCaughtUp) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = UtilsTest.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, id, correlationId, clientId);
CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLagInBytes, numReplicasCaughtUpPerPartition, adminRequest);
Response response = sendRequestGetResponse(catchupStatusRequest, expectedServerErrorCode);
assertTrue("Response not of type CatchupStatusAdminResponse", response instanceof CatchupStatusAdminResponse);
CatchupStatusAdminResponse adminResponse = (CatchupStatusAdminResponse) response;
assertEquals("Catchup status not as expected", expectedIsCaughtUp, adminResponse.isCaughtUp());
}
use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryRequestsTest method stopBlobStoreSuccessTest.
/**
* Tests for the response received on a {@link BlobStoreControlAdminRequest} for successful case
* @throws InterruptedException
* @throws IOException
*/
@Test
public void stopBlobStoreSuccessTest() throws InterruptedException, IOException {
List<? extends PartitionId> partitionIds = clusterMap.getAllPartitionIds();
PartitionId id = partitionIds.get(0);
List<? extends ReplicaId> replicaIds = id.getReplicaIds();
assertTrue("This test needs more than one replica for the first partition to work", replicaIds.size() > 1);
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = UtilsTest.getRandomString(10);
long acceptableLagInBytes = 0;
short numReplicasCaughtUpPerPartition = 3;
replicationManager.reset();
replicationManager.controlReplicationReturnVal = true;
generateLagOverrides(0, acceptableLagInBytes);
// stop BlobStore
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
BlobStoreControlAdminRequest stopBlobStoreAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
Response response = sendRequestGetResponse(stopBlobStoreAdminRequest, ServerErrorCode.No_Error);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
// test APIs are called in the process of stopping BlobStore
assertEquals("Partition disabled for compaction not as expected", id, storageManager.compactionDisabledPartitionId);
assertEquals("Origins list should be empty", true, replicationManager.originsVal.isEmpty());
assertEquals("Replication on given BlobStore should be disabled", false, replicationManager.enableVal);
assertEquals("Partition shutdown not as expected", id, storageManager.shutdownPartitionId);
}
use of com.github.ambry.protocol.Response 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;
}
use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryRequestsTest method sendAndVerifyRequestControlRequest.
/**
* Sends and verifies that a {@link AdminRequestOrResponseType#RequestControl} request received the error code
* expected.
* @param toControl the {@link AdminRequestOrResponseType#RequestControl} to control.
* @param enable {@code true} if {@code toControl} needs to be enabled. {@code false} otherwise.
* @param id the {@link PartitionId} to send the request for. Can be {@code null}.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @throws InterruptedException
* @throws IOException
*/
private void sendAndVerifyRequestControlRequest(RequestOrResponseType toControl, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = UtilsTest.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.RequestControl, id, correlationId, clientId);
RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(toControl, enable, adminRequest);
Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
}
Aggregations