use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class TailoredPeersClusterMap method verifyFailureWithMsg.
/**
* Verifies that attempting to get peers of any datanode 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 = getRestRequest(TailoredPeersClusterMap.DATANODE_NAMES[0]);
try {
sendRequestGetResponse(restRequest, new MockRestResponseChannel());
fail("Request should have failed");
} catch (Exception e) {
assertEquals("Unexpected Exception", msg, e.getMessage());
}
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class GetSignedUrlHandlerTest method handleGoodCaseTest.
/**
* Handles the case where url signing succeeds
* @throws Exception
*/
@Test
public void handleGoodCaseTest() throws Exception {
urlSigningServiceFactory.signedUrlToReturn = TestUtils.getRandomString(10);
// POST
RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.InternalKeys.REQUEST_PATH, RequestPath.parse("/signedUrl", Collections.emptyMap(), Collections.emptyList(), "Ambry-test"));
restRequest.setArg(RestUtils.Headers.URL_TYPE, RestMethod.POST.name());
restRequest.setArg(RestUtils.Headers.TARGET_ACCOUNT_NAME, REF_ACCOUNT.getName());
restRequest.setArg(RestUtils.Headers.TARGET_CONTAINER_NAME, REF_CONTAINER.getName());
verifySigningUrl(restRequest, urlSigningServiceFactory.signedUrlToReturn, REF_ACCOUNT, REF_CONTAINER);
idConverterFactory.translation = testBlobId.getID();
// GET (also makes sure that the IDConverter is used)
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.InternalKeys.REQUEST_PATH, RequestPath.parse("/signedUrl", Collections.emptyMap(), Collections.emptyList(), "Ambry-test"));
restRequest.setArg(RestUtils.Headers.URL_TYPE, RestMethod.GET.name());
// add a random string. IDConverter will convert it
restRequest.setArg(RestUtils.Headers.BLOB_ID, TestUtils.getRandomString(10));
verifySigningUrl(restRequest, urlSigningServiceFactory.signedUrlToReturn, REF_ACCOUNT, REF_CONTAINER);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class UndeleteHandlerTest method handleGoodCaseTest.
/**
* Tests the case where undelete succeeds
* @throws Exception
*/
@Test
public void handleGoodCaseTest() throws Exception {
setupBlob();
// 1. Test undelete a deleted blob
RestRequest restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
verifyUndelete(restRequest, REF_ACCOUNT, REF_CONTAINER);
// 2. Test undelete it again
router.deleteBlob(blobId, SERVICE_ID).get(1, TimeUnit.SECONDS);
restRequest = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
restRequest.setArg(RestUtils.Headers.BLOB_ID, blobId);
restRequest.setArg(RestUtils.Headers.SERVICE_ID, SERVICE_ID);
verifyUndelete(restRequest, REF_ACCOUNT, REF_CONTAINER);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class UndeleteHandlerTest method badArgsTest.
/**
* Tests for expected failures with bad arguments
* @throws Exception
*/
private void badArgsTest() throws Exception {
setupBlob();
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);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class GetClusterMapSnapshotHandlerTest method handleGoodCaseTest.
/**
* Handles the case where everything works as expected
* @throws Exception
*/
@Test
public void handleGoodCaseTest() throws Exception {
RestRequest restRequest = createRestRequest();
RestResponseChannel restResponseChannel = new MockRestResponseChannel();
ReadableStreamChannel channel = sendRequestGetResponse(restRequest, restResponseChannel);
assertNotNull("There should be a response", channel);
Assert.assertNotNull("Date has not been set", restResponseChannel.getHeader(RestUtils.Headers.DATE));
assertEquals("Content-type is not as expected", RestUtils.JSON_CONTENT_TYPE, restResponseChannel.getHeader(RestUtils.Headers.CONTENT_TYPE));
assertEquals("Content-length is not as expected", channel.getSize(), Integer.parseInt((String) restResponseChannel.getHeader(RestUtils.Headers.CONTENT_LENGTH)));
JSONObject expected = clusterMap.getSnapshot();
JSONObject actual = RestTestUtils.getJsonizedResponseBody(channel);
// remove timestamps because they may differ
expected.remove(ClusterMapSnapshotConstants.TIMESTAMP_MS);
actual.remove(ClusterMapSnapshotConstants.TIMESTAMP_MS);
assertEquals("Snapshot does not match expected", expected.toString(), actual.toString());
}
Aggregations