Search in sources :

Example 11 with Response

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();
    }
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Response(com.github.ambry.protocol.Response) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) GetRequest(com.github.ambry.protocol.GetRequest) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) GetResponse(com.github.ambry.protocol.GetResponse)

Example 12 with Response

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());
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse)

Example 13 with Response

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);
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId) UtilsTest(com.github.ambry.utils.UtilsTest) Test(org.junit.Test)

Example 14 with Response

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;
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) ReplicaMetadataRequest(com.github.ambry.protocol.ReplicaMetadataRequest) GetRequest(com.github.ambry.protocol.GetRequest) Request(com.github.ambry.network.Request) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PutRequest(com.github.ambry.protocol.PutRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) DeleteRequest(com.github.ambry.protocol.DeleteRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Example 15 with 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);
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest)

Aggregations

GetResponse (com.github.ambry.protocol.GetResponse)23 Response (com.github.ambry.protocol.Response)23 AdminResponse (com.github.ambry.protocol.AdminResponse)18 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)18 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)18 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)18 AdminRequest (com.github.ambry.protocol.AdminRequest)12 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)12 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)12 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)12 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)12 PartitionId (com.github.ambry.clustermap.PartitionId)8 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)7 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)7 Test (org.junit.Test)7 BlobId (com.github.ambry.commons.BlobId)6 GetRequest (com.github.ambry.protocol.GetRequest)6 DeleteRequest (com.github.ambry.protocol.DeleteRequest)5 DeleteResponse (com.github.ambry.protocol.DeleteResponse)5 PutResponse (com.github.ambry.protocol.PutResponse)5