use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest 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 isPrivate {@code true} if the blob is expected to be private
* @param accountName the expected account name in the response.
* @param containerName the expected container name in response.
* @param usermetadata if non-null, this is expected to come as the body.
* @throws ExecutionException
* @throws InterruptedException
*/
private void getBlobInfoAndVerify(String blobId, GetOption getOption, HttpHeaders expectedHeaders, boolean isPrivate, String accountName, String containerName, byte[] usermetadata) throws ExecutionException, InterruptedException {
HttpHeaders headers = new DefaultHttpHeaders();
if (getOption != null) {
headers.add(RestUtils.Headers.GET_OPTION, getOption.toString());
}
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId + "/" + RestUtils.SubResource.BlobInfo, headers, null);
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
checkCommonGetHeadHeaders(response.headers());
verifyBlobProperties(expectedHeaders, isPrivate, response);
verifyAccountAndContainerHeaders(accountName, containerName, response);
verifyUserMetadata(expectedHeaders, response, usermetadata, responseParts.queue);
assertTrue("Channel should be active", HttpUtil.isKeepAlive(response));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method buildRequest.
// helpers
// general
/**
* Method to easily create a request.
* @param httpMethod the {@link HttpMethod} desired.
* @param uri string representation of the desired URI.
* @param headers any associated headers as a {@link HttpHeaders} object. Can be null.
* @param content the content that accompanies the request. Can be null.
* @return A {@link FullHttpRequest} object that defines the request required by the input.
*/
private FullHttpRequest buildRequest(HttpMethod httpMethod, String uri, HttpHeaders headers, ByteBuffer content) {
ByteBuf contentBuf;
if (content != null) {
contentBuf = Unpooled.wrappedBuffer(content);
} else {
contentBuf = Unpooled.buffer(0);
}
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, uri, contentBuf);
if (headers != null) {
httpRequest.headers().set(headers);
}
if (HttpMethod.POST.equals(httpMethod) && !HttpUtil.isContentLengthSet(httpRequest)) {
HttpUtil.setTransferEncodingChunked(httpRequest, true);
}
return httpRequest;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method verifyOperationsAfterDelete.
/**
* Verifies that the right response code is returned for GET, HEAD and DELETE once a blob is deleted.
* @param blobId the ID of the blob that was deleted.
* @param expectedHeaders the expected headers in the response if the right options are provided.
* @param isPrivate {@code true} if the blob is expected to be private
* @param accountName the expected account name in {@code response}.
* @param containerName the expected container name in {@code response}.
* @param expectedContent the expected content of the blob if the right options are provided.
* @param usermetadata if non-null, this is expected to come as the body.
* @throws Exception
*/
private void verifyOperationsAfterDelete(String blobId, HttpHeaders expectedHeaders, boolean isPrivate, String accountName, String containerName, ByteBuffer expectedContent, byte[] usermetadata) throws Exception {
HttpHeaders headers = new DefaultHttpHeaders().add(RestUtils.Headers.GET_OPTION, GetOption.None.toString());
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.GET, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.DELETE, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.ACCEPTED);
GetOption[] options = { GetOption.Include_Deleted_Blobs, GetOption.Include_All };
for (GetOption option : options) {
getBlobAndVerify(blobId, null, option, expectedHeaders, isPrivate, expectedContent);
getNotModifiedBlobAndVerify(blobId, option, isPrivate);
getUserMetadataAndVerify(blobId, option, expectedHeaders, usermetadata);
getBlobInfoAndVerify(blobId, option, expectedHeaders, isPrivate, accountName, containerName, usermetadata);
getHeadAndVerify(blobId, null, option, expectedHeaders, isPrivate, accountName, containerName);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method deleteBlobAndVerify.
/**
* Deletes the blob with blob ID {@code blobId} and verifies the response returned.
* @param blobId the blob ID of the blob to DELETE.
* @throws ExecutionException
* @throws InterruptedException
*/
private void deleteBlobAndVerify(String blobId) throws ExecutionException, InterruptedException {
FullHttpRequest httpRequest = buildRequest(HttpMethod.DELETE, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.ACCEPTED);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project ambry by linkedin.
the class FrontendIntegrationTest method getUserMetadataAndVerify.
/**
* Gets the user metadata 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 usermetadata if non-null, this is expected to come as the body.
* @throws ExecutionException
* @throws InterruptedException
*/
private void getUserMetadataAndVerify(String blobId, GetOption getOption, HttpHeaders expectedHeaders, byte[] usermetadata) throws ExecutionException, InterruptedException {
HttpHeaders headers = new DefaultHttpHeaders();
if (getOption != null) {
headers.add(RestUtils.Headers.GET_OPTION, getOption.toString());
}
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId + "/" + RestUtils.SubResource.UserMetadata, headers, null);
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
checkCommonGetHeadHeaders(response.headers());
verifyUserMetadata(expectedHeaders, response, usermetadata, responseParts.queue);
assertTrue("Channel should be active", HttpUtil.isKeepAlive(response));
}
Aggregations