use of com.github.ambry.network.RequestInfo in project ambry by linkedin.
the class InMemoryCloudDestinationErrorSimulationTest method doPut.
/**
* Do a put directly to the cloud mock servers.
* @param partitionId partition id
* @param expectedCode expected response error code
* @return the blob id
* @throws Exception
*/
private BlobId doPut(PartitionId partitionId, ServerErrorCode expectedCode) throws Exception {
int blobSize = 4096;
// direct put DataBlob
BlobType blobType = BlobType.DataBlob;
BlobProperties blobProperties = new BlobProperties(blobSize, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time, Utils.getRandomShort(random), Utils.getRandomShort(random), false, null, null, null);
byte[] userMetadata = new byte[10];
random.nextBytes(userMetadata);
byte[] putContent = new byte[blobSize];
random.nextBytes(putContent);
ByteBuf blobContent = PooledByteBufAllocator.DEFAULT.heapBuffer(blobSize);
blobContent.writeBytes(putContent);
BlobId blobId = new BlobId(routerConfig.routerBlobidCurrentVersion, BlobId.BlobIdType.NATIVE, mockClusterMap.getLocalDatacenterId(), blobProperties.getAccountId(), blobProperties.getContainerId(), partitionId, blobProperties.isEncrypted(), blobType == BlobType.MetadataBlob ? BlobId.BlobDataType.METADATA : BlobId.BlobDataType.DATACHUNK);
ByteBuffer userMetadataBuf = ByteBuffer.wrap(userMetadata);
// send to Cloud destinations.
PutRequest request = new PutRequest(random.nextInt(), "clientId", blobId, blobProperties, userMetadataBuf.duplicate(), blobContent.retainedDuplicate(), blobContent.readableBytes(), blobType, null);
RequestInfo requestInfo = new RequestInfo(hostname, port, request, replica, null);
ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
Assert.assertEquals("doPut should succeed.", responseInfo.getError(), null);
// PutResponse response = PutResponse.readFrom(new NettyByteBufDataInputStream(responseInfo.content()));
PutResponse response = (PutResponse) RouterUtils.mapToReceivedResponse((PutResponse) responseInfo.getResponse());
Assert.assertEquals("The PutResponse is not expected.", expectedCode, response.getError());
request.release();
blobContent.release();
return blobId;
}
use of com.github.ambry.network.RequestInfo 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.network.RequestInfo in project ambry by linkedin.
the class InMemoryCloudDestinationErrorSimulationTest method testTtlUpdateErrorSimulation.
/**
* test error simulation for TtlUpdateRequest
* @throws Exception
*/
@Test
public void testTtlUpdateErrorSimulation() throws Exception {
BlobId blobId = doPut(partitionId);
TtlUpdateRequest ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
RequestInfo requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
TtlUpdateResponse response = responseInfo.getError() == null ? (TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
Assert.assertEquals("TtlUpdate should succeed.", response.getError(), ServerErrorCode.No_Error);
response.release();
// inject error for cloud colo.
cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.TTL_Expired);
ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
responseInfo = sendAndWaitForResponses(requestInfo);
response = responseInfo.getError() == null ? ((TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse())) : null;
Assert.assertEquals("TtlUpdate should return Blob_Expired.", response.getError(), ServerErrorCode.Blob_Expired);
response.release();
}
use of com.github.ambry.network.RequestInfo in project ambry by linkedin.
the class InMemoryCloudDestinationErrorSimulationTest method sendAndWaitForResponses.
/**
* Submit all the requests that were handed over by the operation and wait until a response is received for every
* one of them.
* @param requestInfo the request handed over by the operation.
* @return the response from the network client.
*/
private ResponseInfo sendAndWaitForResponses(RequestInfo requestInfo) {
List<RequestInfo> requestList = new ArrayList<>();
requestList.add(requestInfo);
int sendCount = requestList.size();
List<ResponseInfo> responseList = new ArrayList<>();
responseList.addAll(mockNetworkClient.sendAndPoll(requestList, Collections.emptySet(), 100));
requestList.clear();
while (responseList.size() < sendCount) {
responseList.addAll(mockNetworkClient.sendAndPoll(requestList, Collections.emptySet(), 100));
}
Assert.assertEquals("Only one request and response", responseList.size(), 1);
ResponseInfo responseInfo = responseList.get(0);
return responseInfo;
}
use of com.github.ambry.network.RequestInfo in project ambry by linkedin.
the class Http2ClientStreamStatsHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Http2Frame frame) throws Exception {
ReferenceCountUtil.retain(frame);
RequestInfo requestInfo = ctx.channel().attr(Http2NetworkClient.REQUEST_INFO).get();
requestInfo.responseFramesCount++;
long time = System.currentTimeMillis() - requestInfo.getStreamSendTime();
if (frame instanceof Http2HeadersFrame) {
http2ClientMetrics.http2StreamRoundTripTime.update(time);
requestInfo.setStreamHeaderFrameReceiveTime(System.currentTimeMillis());
logger.debug("Header Frame received. Time from send: {}ms. Request: {}", time, requestInfo);
} else if (frame instanceof Http2DataFrame) {
logger.debug("Data Frame size: {}. Time from send: {}ms. Request: {}", ((Http2DataFrame) frame).content().readableBytes(), time, requestInfo);
}
if (frame instanceof Http2DataFrame && ((Http2DataFrame) frame).isEndStream()) {
http2ClientMetrics.http2StreamFirstToLastFrameTime.update(time);
http2ClientMetrics.http2ResponseFrameCount.update(requestInfo.responseFramesCount);
logger.debug("All Frame received. Time from send: {}ms. Request: {}", time, requestInfo);
}
ctx.fireChannelRead(frame);
}
Aggregations