use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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.HttpResponse in project ambry by linkedin.
the class FrontendIntegrationTest method multipartPostGetHeadTest.
/**
* Tests multipart POST and verifies it via GET operations.
* @throws Exception
*/
@Test
public void multipartPostGetHeadTest() throws Exception {
Account refAccount = ACCOUNT_SERVICE.createAndAddRandomAccount();
Container refContainer = refAccount.getContainerById(Container.DEFAULT_PUBLIC_CONTAINER_ID);
doPostGetHeadDeleteTest(0, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
doPostGetHeadDeleteTest(FRONTEND_CONFIG.frontendChunkedGetResponseThresholdInBytes * 3, refAccount, refContainer, refAccount.getName(), !refContainer.isCacheable(), refAccount.getName(), refContainer.getName(), true);
// failure case
// size of content being POSTed is higher than what is allowed via multipart/form-data
long maxAllowedSizeBytes = new NettyConfig(FRONTEND_VERIFIABLE_PROPS).nettyMultipartPostMaxSizeBytes;
ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes((int) maxAllowedSizeBytes + 1));
HttpHeaders headers = new DefaultHttpHeaders();
setAmbryHeadersForPut(headers, 7200, !refContainer.isCacheable(), refAccount.getName(), "application/octet-stream", null, refAccount.getName(), refContainer.getName());
HttpRequest httpRequest = RestTestUtils.createRequest(HttpMethod.POST, "/", headers);
HttpPostRequestEncoder encoder = createEncoder(httpRequest, content, ByteBuffer.allocate(0));
ResponseParts responseParts = nettyClient.sendRequest(encoder.finalizeRequest(), encoder, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertTrue("No Date header", response.headers().getTimeMillis(HttpHeaderNames.DATE, -1) != -1);
assertFalse("Channel should not be active", HttpUtil.isKeepAlive(response));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse 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));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project ambry by linkedin.
the class FrontendIntegrationTest method verifyGetBlobResponse.
/**
* Verifies the GET blob response.
* @param responseParts the response received from the server.
* @param range the {@link ByteRange} for the request.
* @param expectedHeaders the expected headers in the response.
* @param isPrivate {@code true} if the blob is private, {@code false} if not.
* @param expectedContent the expected content of the blob.
* @throws RestServiceException
*/
private void verifyGetBlobResponse(ResponseParts responseParts, ByteRange range, HttpHeaders expectedHeaders, boolean isPrivate, ByteBuffer expectedContent) throws RestServiceException {
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", range == null ? HttpResponseStatus.OK : HttpResponseStatus.PARTIAL_CONTENT, response.status());
checkCommonGetHeadHeaders(response.headers());
assertEquals("Content-Type does not match", expectedHeaders.get(RestUtils.Headers.AMBRY_CONTENT_TYPE), response.headers().get(HttpHeaderNames.CONTENT_TYPE));
assertEquals(RestUtils.Headers.BLOB_SIZE + " does not match", expectedHeaders.get(RestUtils.Headers.BLOB_SIZE), response.headers().get(RestUtils.Headers.BLOB_SIZE));
assertEquals("Accept-Ranges not set correctly", "bytes", response.headers().get(RestUtils.Headers.ACCEPT_RANGES));
byte[] expectedContentArray = expectedContent.array();
if (range != null) {
long blobSize = Long.parseLong(expectedHeaders.get(RestUtils.Headers.BLOB_SIZE));
assertEquals("Content-Range header not set correctly", RestUtils.buildContentRangeAndLength(range, blobSize).getFirst(), response.headers().get(RestUtils.Headers.CONTENT_RANGE));
ByteRange resolvedRange = range.toResolvedByteRange(blobSize);
expectedContentArray = Arrays.copyOfRange(expectedContentArray, (int) resolvedRange.getStartOffset(), (int) resolvedRange.getEndOffset() + 1);
} else {
assertNull("Content-Range header should not be set", response.headers().get(RestUtils.Headers.CONTENT_RANGE));
}
if (expectedContentArray.length < FRONTEND_CONFIG.frontendChunkedGetResponseThresholdInBytes) {
assertEquals("Content-length not as expected", expectedContentArray.length, HttpUtil.getContentLength(response));
}
verifyCacheHeaders(isPrivate, response);
byte[] responseContentArray = getContent(responseParts.queue, expectedContentArray.length).array();
assertArrayEquals("GET content does not match original content", expectedContentArray, responseContentArray);
assertTrue("Channel should be active", HttpUtil.isKeepAlive(response));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project ambry by linkedin.
the class FrontendIntegrationTest method getReplicasTest.
/**
* Tests {@link RestUtils.SubResource#Replicas} requests
* <p/>
* For each {@link PartitionId} in the {@link ClusterMap}, a {@link BlobId} is created. The replica list returned from
* server is checked for equality against a locally obtained replica list.
* @throws Exception
*/
@Test
public void getReplicasTest() throws Exception {
List<? extends PartitionId> partitionIds = CLUSTER_MAP.getWritablePartitionIds();
for (PartitionId partitionId : partitionIds) {
String originalReplicaStr = partitionId.getReplicaIds().toString().replace(", ", ",");
BlobId blobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMapUtils.UNKNOWN_DATACENTER_ID, Account.UNKNOWN_ACCOUNT_ID, Container.UNKNOWN_CONTAINER_ID, partitionId, false);
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, blobId.getID() + "/" + RestUtils.SubResource.Replicas, Unpooled.buffer(0));
ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
HttpResponse response = getHttpResponse(responseParts);
assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
ByteBuffer content = getContent(responseParts.queue, HttpUtil.getContentLength(response));
JSONObject responseJson = new JSONObject(new String(content.array()));
String returnedReplicasStr = responseJson.getString(GetReplicasHandler.REPLICAS_KEY).replace("\"", "");
assertEquals("Replica IDs returned for the BlobId do no match with the replicas IDs of partition", originalReplicaStr, returnedReplicasStr);
}
}
Aggregations