Search in sources :

Example 71 with MockRestResponseChannel

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

the class UndeleteHandlerTest method verifyFailureWithErrorCode.

/**
 * Verifies that processing {@code restRequest} fails with {@code errorCode}
 * @param restRequest the {@link RestRequest} that is expected to fail
 * @param errorCode the {@link RestServiceErrorCode} that it should fail with
 * @throws Exception
 */
private void verifyFailureWithErrorCode(RestRequest restRequest, RestServiceErrorCode errorCode) throws Exception {
    try {
        sendRequestGetResponse(restRequest, new MockRestResponseChannel());
        fail("Request should have failed");
    } catch (RestServiceException e) {
        assertEquals("Unexpected RestServiceErrorCode", errorCode, e.getErrorCode());
    }
}
Also used : RestServiceException(com.github.ambry.rest.RestServiceException) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel)

Example 72 with MockRestResponseChannel

use of com.github.ambry.rest.MockRestResponseChannel 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)

Aggregations

MockRestResponseChannel (com.github.ambry.rest.MockRestResponseChannel)72 RestRequest (com.github.ambry.rest.RestRequest)57 MockRestRequest (com.github.ambry.rest.MockRestRequest)51 JSONObject (org.json.JSONObject)39 RestServiceException (com.github.ambry.rest.RestServiceException)36 Test (org.junit.Test)34 RestResponseChannel (com.github.ambry.rest.RestResponseChannel)27 RestMethod (com.github.ambry.rest.RestMethod)19 Account (com.github.ambry.account.Account)18 FutureResult (com.github.ambry.router.FutureResult)17 ReadableStreamChannel (com.github.ambry.router.ReadableStreamChannel)17 ExecutionException (java.util.concurrent.ExecutionException)17 StorageStatsUtilTest (com.github.ambry.server.StorageStatsUtilTest)16 RestUtils (com.github.ambry.rest.RestUtils)15 ByteBuffer (java.nio.ByteBuffer)15 MetricRegistry (com.codahale.metrics.MetricRegistry)14 RestServiceErrorCode (com.github.ambry.rest.RestServiceErrorCode)14 RestUtilsTest (com.github.ambry.rest.RestUtilsTest)14 TestUtils (com.github.ambry.utils.TestUtils)14 TimeUnit (java.util.concurrent.TimeUnit)14