use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method updateBlobTtlAndVerify.
/**
* Updates the TTL of the blob with blob ID {@code blobId} and verifies that the operation succeeded.
* @param blobId the blob ID of the blob to HEAD.
* @param expectedHeaders the expected headers in the GET response triggered for verification.
* @param expectedAccount the expected account in the GET response triggered for verification. Also used to attach
* preconditions if required
* @param expectedContainer the expected container in the GET response triggered for verification. Also used to attach
* preconditions if required
* @param attachPreconditions if {@code true}, attaches preconditions to the request
* @throws Exception
*/
private void updateBlobTtlAndVerify(String blobId, JSONObject expectedHeaders, Account expectedAccount, Container expectedContainer, boolean attachPreconditions) throws Exception {
JSONObject headers = new JSONObject();
setUpdateTtlHeaders(headers, blobId, "updateBlobTtlAndVerify");
if (attachPreconditions) {
setAccountAndContainerHeaders(headers, expectedAccount.getName(), expectedContainer.getName());
}
RestRequest restRequest = createRestRequest(RestMethod.PUT, Operations.UPDATE_TTL, headers, null);
verifyUpdateBlobTtlResponse(restRequest);
expectedHeaders.remove(RestUtils.Headers.TTL);
getBlobInfoAndVerify(blobId, GetOption.None, expectedHeaders, expectedAccount, expectedContainer);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method oldStyleUserMetadataTest.
/**
* Tests how metadata that has not been POSTed in the form of headers is returned.
* @throws Exception
*/
@Test
public void oldStyleUserMetadataTest() throws Exception {
ByteBuffer content = ByteBuffer.allocate(0);
BlobProperties blobProperties = new BlobProperties(0, "userMetadataTestOldStyleServiceID", Account.UNKNOWN_ACCOUNT_ID, Container.UNKNOWN_CONTAINER_ID, false);
byte[] usermetadata = TestUtils.getRandomBytes(25);
String blobId = router.putBlob(blobProperties, usermetadata, new ByteBufferReadableStreamChannel(content), new PutBlobOptionsBuilder().build()).get();
RestUtils.SubResource[] subResources = { RestUtils.SubResource.UserMetadata, RestUtils.SubResource.BlobInfo };
for (RestUtils.SubResource subResource : subResources) {
RestRequest restRequest = createRestRequest(RestMethod.GET, blobId + "/" + subResource, null, null);
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
doOperation(restRequest, restResponseChannel);
assertEquals("Unexpected response status for " + subResource, ResponseStatus.Ok, restResponseChannel.getStatus());
assertEquals("Unexpected Content-Type for " + subResource, "application/octet-stream", restResponseChannel.getHeader(RestUtils.Headers.CONTENT_TYPE));
assertEquals("Unexpected Content-Length for " + subResource, usermetadata.length, Integer.parseInt(restResponseChannel.getHeader(RestUtils.Headers.CONTENT_LENGTH)));
assertArrayEquals("Unexpected user metadata for " + subResource, usermetadata, restResponseChannel.getResponseBody());
}
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method getBlobInfoAndVerify.
/**
* Gets the blob info of the blob with blob ID {@code blobId} and verifies them against what is expected.
* @param blobId the blob ID of the blob to HEAD.
* @param getOption the options to use while getting the blob.
* @param expectedHeaders the expected headers in the response.
* @param expectedAccount the expected account in the rest request.
* @param expectedContainer the expected container in the rest request.
* @throws Exception
*/
private void getBlobInfoAndVerify(String blobId, GetOption getOption, JSONObject expectedHeaders, Account expectedAccount, Container expectedContainer) throws Exception {
JSONObject headers = new JSONObject();
if (getOption != null) {
headers.put(RestUtils.Headers.GET_OPTION, getOption.toString());
}
RestRequest restRequest = createRestRequest(RestMethod.GET, blobId + "/" + RestUtils.SubResource.BlobInfo, headers, null);
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
doOperation(restRequest, restResponseChannel);
assertEquals("Unexpected response status", ResponseStatus.Ok, restResponseChannel.getStatus());
checkCommonGetHeadHeaders(restResponseChannel);
assertEquals("Content-Length is not 0", "0", restResponseChannel.getHeader(RestUtils.Headers.CONTENT_LENGTH));
assertNull("Accept-Ranges should not be set", restResponseChannel.getHeader(RestUtils.Headers.ACCEPT_RANGES));
assertNull("Content-Range header should not be set", restResponseChannel.getHeader(RestUtils.Headers.CONTENT_RANGE));
verifyBlobProperties(expectedHeaders, restResponseChannel);
verifyUserMetadataHeaders(expectedHeaders, restResponseChannel);
verifyAccountAndContainerHeaders(restResponseChannel, expectedAccount, expectedContainer);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method getPeersTest.
/**
* Tests the handling of {@link Operations#GET_PEERS} requests.
* @throws Exception
*/
@Test
public void getPeersTest() throws Exception {
frontendRestRequestService.shutdown();
TailoredPeersClusterMap clusterMap = new TailoredPeersClusterMap();
frontendRestRequestService = new FrontendRestRequestService(frontendConfig, frontendMetrics, router, clusterMap, idConverterFactory, securityServiceFactory, urlSigningService, idSigningService, null, accountService, accountAndContainerInjector, datacenterName, hostname, clusterName, accountStatsStore, QUOTA_MANAGER);
frontendRestRequestService.setupResponseHandler(responseHandler);
frontendRestRequestService.start();
// test good requests
for (String datanode : TailoredPeersClusterMap.DATANODE_NAMES) {
String[] parts = datanode.split(":");
String baseUri = Operations.GET_PEERS + "?" + GetPeersHandler.NAME_QUERY_PARAM + "=" + parts[0] + "&" + GetPeersHandler.PORT_QUERY_PARAM + "=" + parts[1];
String[] uris = { baseUri, "/" + baseUri };
for (String uri : uris) {
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
doOperation(createRestRequest(RestMethod.GET, uri, null, null), restResponseChannel);
byte[] peerStrBytes = restResponseChannel.getResponseBody();
Set<String> peersFromResponse = GetPeersHandlerTest.getPeersFromResponse(new JSONObject(new String(peerStrBytes)));
Set<String> expectedPeers = clusterMap.getPeers(datanode);
assertEquals("Peer list returned does not match expected for " + datanode, expectedPeers, peersFromResponse);
}
}
// test one bad request
RestRequest restRequest = createRestRequest(RestMethod.GET, Operations.GET_PEERS, null, null);
verifyOperationFailure(restRequest, RestServiceErrorCode.MissingArgs);
}
use of com.github.ambry.rest.RestRequest in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method getBlobAndVerify.
/**
* Gets the blob with blob ID {@code blobId} and verifies that the headers and content match with what is expected.
* @param blobId the blob ID of the blob to GET.
* @param range the optional {@link ByteRange} for the request.
* @param getOption the options to use while getting the blob.
* @param expectedHeaders the expected headers in the response.
* @param expectedContent the expected content of the blob.
* @param expectedAccount the expected account in the rest request.
* @param expectedContainer the expected container in the rest request.
* @throws Exception
*/
private void getBlobAndVerify(String blobId, ByteRange range, GetOption getOption, JSONObject expectedHeaders, ByteBuffer expectedContent, Account expectedAccount, Container expectedContainer) throws Exception {
RestRequest restRequest = createRestRequest(RestMethod.GET, blobId, createRequestHeaders(range, getOption), null);
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
doOperation(restRequest, restResponseChannel);
verifyGetBlobResponse(restRequest, restResponseChannel, range, expectedHeaders, expectedContent, expectedAccount, expectedContainer);
}
Aggregations