use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class MockRouterCallback method testErrorPrecedence.
/**
* Help test error precedence.
* @param serverErrorCodesInOrder the list of error codes to set the mock servers with.
* @param expectedErrorCode the expected router error code for the operation.
* @throws Exception
*/
private void testErrorPrecedence(ServerErrorCode[] serverErrorCodesInOrder, RouterErrorCode expectedErrorCode) throws Exception {
NonBlockingRouter.currentOperationsCount.incrementAndGet();
GetBlobInfoOperation op = new GetBlobInfoOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobId, options, null, routerCallback, kms, cryptoService, cryptoJobHandler, time);
ArrayList<RequestInfo> requestListToFill = new ArrayList<>();
requestRegistrationCallback.requestListToFill = requestListToFill;
int i = 0;
for (MockServer server : mockServerLayout.getMockServers()) {
server.setServerErrorForAllRequests(serverErrorCodesInOrder[i++]);
}
while (!op.isOperationComplete()) {
op.poll(requestRegistrationCallback);
List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill);
for (ResponseInfo responseInfo : responses) {
GetResponse getResponse = responseInfo.getError() == null ? GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), mockClusterMap) : null;
op.handleResponse(responseInfo, getResponse);
if (op.isOperationComplete()) {
break;
}
}
}
RouterException routerException = (RouterException) op.getOperationException();
Assert.assertEquals(expectedErrorCode, routerException.getErrorCode());
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class NonBlockingRouterTest method testFailureDetectorNotification.
/**
* Test that failure detector is correctly notified for all responses regardless of the order in which successful
* and failed responses arrive.
* @param opHelper the {@link OperationHelper}
* @param networkClient the {@link NetworkClient}
* @param failedReplicaIds the list that will contain all the replicas for which failure was notified.
* @param blobId the id of the blob to get/delete. For puts, this will be null.
* @param successfulResponseCount the AtomicInteger that will contain the count of replicas for which success was
* notified.
* @param invalidResponse the AtomicBoolean that will contain whether an unexpected failure was notified.
* @param indexToFail if greater than 0, the index representing which response for which failure is to be simulated.
* For example, if index is 0, then the first response will be failed.
* If the index is -1, no responses will be failed, and successful responses will be returned to
* the operation managers.
*/
private void testFailureDetectorNotification(OperationHelper opHelper, NetworkClient networkClient, List<ReplicaId> failedReplicaIds, BlobId blobId, AtomicInteger successfulResponseCount, AtomicBoolean invalidResponse, int indexToFail) throws Exception {
failedReplicaIds.clear();
successfulResponseCount.set(0);
invalidResponse.set(false);
mockSelectorState.set(MockSelectorState.Good);
FutureResult futureResult = opHelper.submitOperation(blobId);
int requestParallelism = opHelper.requestParallelism;
List<RequestInfo> allRequests = new ArrayList<>();
long loopStartTimeMs = SystemTime.getInstance().milliseconds();
while (allRequests.size() < requestParallelism) {
if (loopStartTimeMs + AWAIT_TIMEOUT_MS < SystemTime.getInstance().milliseconds()) {
Assert.fail("Waited too long for requests.");
}
opHelper.pollOpManager(allRequests);
}
ReplicaId replicaIdToFail = indexToFail == -1 ? null : ((RouterRequestInfo) allRequests.get(indexToFail)).getReplicaId();
for (RequestInfo requestInfo : allRequests) {
ResponseInfo responseInfo;
if (replicaIdToFail != null && replicaIdToFail.equals(((RouterRequestInfo) requestInfo).getReplicaId())) {
responseInfo = new ResponseInfo(requestInfo, NetworkClientErrorCode.NetworkError, null);
} else {
List<RequestInfo> requestInfoListToSend = new ArrayList<>();
requestInfoListToSend.add(requestInfo);
List<ResponseInfo> responseInfoList;
loopStartTimeMs = SystemTime.getInstance().milliseconds();
do {
if (loopStartTimeMs + AWAIT_TIMEOUT_MS < SystemTime.getInstance().milliseconds()) {
Assert.fail("Waited too long for the response.");
}
responseInfoList = networkClient.sendAndPoll(requestInfoListToSend, 10);
requestInfoListToSend.clear();
} while (responseInfoList.size() == 0);
responseInfo = responseInfoList.get(0);
}
opHelper.handleResponse(responseInfo);
}
// Poll once again so that the operation gets a chance to complete.
allRequests.clear();
if (testEncryption) {
opHelper.awaitOpCompletionOrTimeOut(futureResult);
} else {
opHelper.pollOpManager(allRequests);
}
futureResult.get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
if (indexToFail == -1) {
Assert.assertEquals("Successful notification should have arrived for replicas that were up", opHelper.requestParallelism, successfulResponseCount.get());
Assert.assertEquals("Failure detector should not have been notified", 0, failedReplicaIds.size());
Assert.assertFalse("There should be no notifications of any other kind", invalidResponse.get());
} else {
Assert.assertEquals("Failure detector should have been notified", 1, failedReplicaIds.size());
Assert.assertEquals("Failed notification should have arrived for the failed replica", replicaIdToFail, failedReplicaIds.get(0));
Assert.assertEquals("Successful notification should have arrived for replicas that were up", opHelper.requestParallelism - 1, successfulResponseCount.get());
Assert.assertFalse("There should be no notifications of any other kind", invalidResponse.get());
}
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class ServerAdminTool method sendRequestGetResponse.
/**
* Sends {@code request} to {@code dataNodeId} and returns the response as a {@link ByteBuffer}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param request the request to send.
* @return the response as a {@link ByteBuffer} if the response was successfully received. {@code null} otherwise.
* @throws TimeoutException
*/
private ByteBuffer sendRequestGetResponse(DataNodeId dataNodeId, Send request) throws TimeoutException {
String hostname = dataNodeId.getHostname();
Port port = dataNodeId.getPortToConnectTo();
String identifier = hostname + ":" + port.getPort();
RequestInfo requestInfo = new RequestInfo(hostname, port, request);
List<RequestInfo> requestInfos = Collections.singletonList(requestInfo);
ResponseInfo responseInfo = null;
long startTimeMs = time.milliseconds();
do {
if (time.milliseconds() - startTimeMs > OPERATION_TIMEOUT_MS) {
throw new TimeoutException(identifier + ": Operation did not complete within " + OPERATION_TIMEOUT_MS + " ms");
}
List<ResponseInfo> responseInfos = networkClient.sendAndPoll(requestInfos, POLL_TIMEOUT_MS);
if (responseInfos.size() > 1) {
throw new IllegalStateException("Received more than one response even though a single request was sent");
} else if (!responseInfos.isEmpty()) {
responseInfo = responseInfos.get(0);
}
requestInfos = Collections.EMPTY_LIST;
} while (responseInfo == null);
if (responseInfo.getError() != null) {
throw new IllegalStateException(identifier + ": Encountered error while trying to send request - " + responseInfo.getError());
}
return responseInfo.getResponse();
}
use of com.github.ambry.network.ResponseInfo 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.network.ResponseInfo 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();
}
Aggregations