Search in sources :

Example 26 with MockRestRequest

use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.

the class GetStatsReportHandlerTest method createRestRequest.

// Helpers
private RestRequest createRestRequest(String clusterName, String reportType) throws Exception {
    JSONObject data = new JSONObject();
    data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
    data.put(MockRestRequest.URI_KEY, Operations.STATS_REPORT);
    JSONObject headers = new JSONObject();
    if (reportType != null) {
        headers.put(RestUtils.Headers.GET_STATS_REPORT_TYPE, reportType);
    }
    if (clusterName != null) {
        headers.put(RestUtils.Headers.CLUSTER_NAME, clusterName);
    }
    data.put(MockRestRequest.HEADERS_KEY, headers);
    return new MockRestRequest(data, null);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 27 with MockRestRequest

use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.

the class TtlUpdateHandlerTest method handleGoodCaseTest.

/**
 * Tests the case where TTL update succeeds
 * @throws Exception
 */
@Test
public void handleGoodCaseTest() throws Exception {
    RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
    restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
    verifyTtlUpdate(restRequest, REF_ACCOUNT, REF_CONTAINER);
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest) Test(org.junit.Test)

Example 28 with MockRestRequest

use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.

the class TtlUpdateHandlerTest method verifyFailureWithMsg.

/**
 * Verifies that attempting to update TTL fails with the provided {@code msg}.
 * @param msg the message in the {@link Exception} that will be thrown.
 * @throws Exception
 */
private void verifyFailureWithMsg(String msg) throws Exception {
    RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
    restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
    try {
        sendRequestGetResponse(restRequest, new MockRestResponseChannel());
        fail("Request should have failed");
    } catch (Exception e) {
        if (!msg.equals(e.getMessage())) {
            throw e;
        }
    }
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel) IOException(java.io.IOException) RestServiceException(com.github.ambry.rest.RestServiceException)

Example 29 with MockRestRequest

use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.

the class UndeleteHandlerTest method verifyFailureWithMsg.

/**
 * Verifies that attempting to undelete fails with the provided {@code msg}.
 * @param msg the message in the {@link Exception} that will be thrown.
 * @throws Exception
 */
private void verifyFailureWithMsg(String msg) throws Exception {
    RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
    restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
    try {
        sendRequestGetResponse(restRequest, new MockRestResponseChannel());
        fail("Request should have failed");
    } catch (Exception e) {
        if (!msg.equals(e.getMessage())) {
            throw e;
        }
    }
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) RestServiceException(com.github.ambry.rest.RestServiceException)

Example 30 with MockRestRequest

use of com.github.ambry.rest.MockRestRequest in project ambry by linkedin.

the class GetClusterMapSnapshotHandlerTest method createRestRequest.

// helpers
// general
/**
 * Creates a {@link RestRequest} that requests for a snapshot of the cluster map.
 * @return a {@link RestRequest} that requests for a snapshot of the cluster map.
 * @throws Exception
 */
private RestRequest createRestRequest() throws Exception {
    JSONObject data = new JSONObject();
    data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
    data.put(MockRestRequest.URI_KEY, Operations.GET_CLUSTER_MAP_SNAPSHOT);
    return new MockRestRequest(data, null);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Aggregations

MockRestRequest (com.github.ambry.rest.MockRestRequest)34 JSONObject (org.json.JSONObject)20 RestRequest (com.github.ambry.rest.RestRequest)18 RestServiceException (com.github.ambry.rest.RestServiceException)7 Test (org.junit.Test)7 ByteBuffer (java.nio.ByteBuffer)6 ReadableStreamChannel (com.github.ambry.router.ReadableStreamChannel)5 MockRestResponseChannel (com.github.ambry.rest.MockRestResponseChannel)4 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 BlobProperties (com.github.ambry.messageformat.BlobProperties)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 Callback (com.github.ambry.commons.Callback)1 ServerMetrics (com.github.ambry.commons.ServerMetrics)1 ServerConfig (com.github.ambry.config.ServerConfig)1 BlobInfo (com.github.ambry.messageformat.BlobInfo)1