Search in sources :

Example 26 with ResponseInfo

use of com.github.ambry.network.ResponseInfo 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;
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) BlobType(com.github.ambry.messageformat.BlobType) BlobProperties(com.github.ambry.messageformat.BlobProperties) PutRequest(com.github.ambry.protocol.PutRequest) ByteBuf(io.netty.buffer.ByteBuf) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) PutResponse(com.github.ambry.protocol.PutResponse) BlobId(com.github.ambry.commons.BlobId) ByteBuffer(java.nio.ByteBuffer)

Example 27 with ResponseInfo

use of com.github.ambry.network.ResponseInfo 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 28 with ResponseInfo

use of com.github.ambry.network.ResponseInfo 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();
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test)

Example 29 with ResponseInfo

use of com.github.ambry.network.ResponseInfo 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;
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) ArrayList(java.util.ArrayList) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo)

Example 30 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class Http2ClientResponseHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) {
    ByteBuf dup = msg.content().retainedDuplicate();
    // Consume length
    dup.readLong();
    RequestInfo requestInfo = ctx.channel().attr(Http2NetworkClient.REQUEST_INFO).get();
    if (requestInfo != null) {
        // A request maybe just dropped by Http2NetworkClient.
        http2ClientMetrics.http2StreamFirstToAllFrameReadyTime.update(System.currentTimeMillis() - requestInfo.getStreamHeaderFrameReceiveTime());
        ResponseInfo responseInfo = new ResponseInfo(requestInfo, null, dup);
        responseInfoQueue.put(responseInfo);
        releaseAndCloseStreamChannel(ctx.channel());
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ByteBuf(io.netty.buffer.ByteBuf) RequestInfo(com.github.ambry.network.RequestInfo)

Aggregations

ResponseInfo (com.github.ambry.network.ResponseInfo)44 RequestInfo (com.github.ambry.network.RequestInfo)33 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)18 GetResponse (com.github.ambry.protocol.GetResponse)17 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)17 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)12 BlobProperties (com.github.ambry.messageformat.BlobProperties)9 PutResponse (com.github.ambry.protocol.PutResponse)9 DataInputStream (java.io.DataInputStream)9 BlobId (com.github.ambry.commons.BlobId)8 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)6 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)6 ReplicaId (com.github.ambry.clustermap.ReplicaId)5 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 AdminRequest (com.github.ambry.protocol.AdminRequest)5 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)5 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)5 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)5 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)5