Search in sources :

Example 11 with MockRestRequest

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

the class TtlUpdateHandlerTest method badArgsTest.

/**
 * Tests for expected failures with bad arguments
 * @throws Exception
 */
private void badArgsTest() throws Exception {
    RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
    // no service ID
    verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.MissingArgs);
    restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
    // no blob ID
    verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.MissingArgs);
    restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    // not a valid blob ID
    restRequest.setArg(RestUtils.Headers.BLOB_ID, "abcd");
    idConverterFactory.translation = "abcd";
    restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
    verifyFailureWithErrorCode(restRequest, RestServiceErrorCode.BadRequest);
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 12 with MockRestRequest

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

the class StorageQuotaEnforcerTest method createRestRequest.

/**
 * Create a {@link MockRestRequest} with account and container headers.
 * @param accountService The {@link AccountService}.
 * @param accountId the account id.
 * @param containerId the container id.
 * @return a {@link MockRestRequest} with account and container headers.
 * @throws Exception
 */
private RestRequest createRestRequest(AccountService accountService, short accountId, short containerId) throws Exception {
    JSONObject data = new JSONObject();
    data.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
    data.put(MockRestRequest.URI_KEY, "/");
    JSONObject headers = new JSONObject();
    headers.put(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY, accountService.getAccountById(accountId));
    headers.put(RestUtils.InternalKeys.TARGET_CONTAINER_KEY, accountService.getAccountById(accountId).getContainerById(containerId));
    data.put(MockRestRequest.HEADERS_KEY, headers);
    return new MockRestRequest(data, null);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 13 with MockRestRequest

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

the class NonBlockingRouterTest method createRestRequestForPutOperation.

private RestRequest createRestRequestForPutOperation() throws Exception {
    JSONObject header = new JSONObject();
    header.put(MockRestRequest.REST_METHOD_KEY, RestMethod.POST.name());
    header.put(MockRestRequest.URI_KEY, "/");
    return new MockRestRequest(header, null);
}
Also used : JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 14 with MockRestRequest

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

the class AmbryIdConverterFactoryTest method testConversion.

/**
 * Tests the conversion by the {@code idConverter}.
 * @param idConverter the {@link IdConverter} instance to use.
 * @param restMethod the {@link RestMethod} of the {@link RestRequest} that will be created.
 * @param input the input string
 * @param expectedOutput the expected output from the {@code idConverter}.
 * @throws Exception
 */
private void testConversion(IdConverter idConverter, RestMethod restMethod, String input, String expectedOutput) throws Exception {
    JSONObject requestData = new JSONObject();
    requestData.put(MockRestRequest.REST_METHOD_KEY, restMethod);
    requestData.put(MockRestRequest.URI_KEY, "/");
    RestRequest restRequest = new MockRestRequest(requestData, null);
    IdConversionCallback callback = new IdConversionCallback();
    assertEquals("Converted ID does not match expected (Future)", expectedOutput, idConverter.convert(restRequest, input, callback).get());
    assertEquals("Converted ID does not match expected (Callback)", expectedOutput, callback.result);
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest)

Example 15 with MockRestRequest

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

the class PutBlobOptionsTest method testOptions.

/**
 * Test that the chunk upload and max size options can be assigned and retrieved correctly.
 * @throws Exception
 */
@Test
public void testOptions() throws Exception {
    PutBlobOptions options = new PutBlobOptionsBuilder().chunkUpload(true).build();
    assertTrue("chunkUpload from options not as expected.", options.isChunkUpload());
    assertEquals("maxUploadSize from options not as expected.", Long.MAX_VALUE, options.getMaxUploadSize());
    options = new PutBlobOptionsBuilder().chunkUpload(false).maxUploadSize(3).build();
    assertFalse("chunkUpload from options not as expected.", options.isChunkUpload());
    assertEquals("maxUploadSize from options not as expected.", 3, options.getMaxUploadSize());
    JSONObject header = new JSONObject();
    header.put(MockRestRequest.URI_KEY, "/");
    header.put(MockRestRequest.REST_METHOD_KEY, RestMethod.GET.name());
    RestRequest restRequest = new MockRestRequest(header, null);
    options = new PutBlobOptionsBuilder().restRequest(restRequest).build();
    assertEquals("RestRequest mismatch", restRequest, options.getRestRequest());
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) JSONObject(org.json.JSONObject) MockRestRequest(com.github.ambry.rest.MockRestRequest) Test(org.junit.Test)

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