use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class ChannelWriteCallback method headersPresenceTest.
/**
* Sends a request with certain headers that will copied into the response. Checks the response for those headers to
* see that values match.
* @throws ParseException
*/
@Test
public void headersPresenceTest() throws ParseException {
HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.CopyHeaders.toString());
HttpUtil.setKeepAlive(request, false);
EmbeddedChannel channel = createEmbeddedChannel();
channel.writeInbound(request);
HttpResponse response = (HttpResponse) channel.readOutbound();
assertFalse("Channel not closed on the server", channel.isActive());
checkHeaders(request, response);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class ChannelWriteCallback method setStatusTest.
/**
* Tests setting of different available {@link ResponseStatus} codes and sees that they are recognized and converted
* in {@link NettyResponseChannel}.
* <p/>
* If this test fails, a case for conversion probably needs to be added in {@link NettyResponseChannel}.
*/
@Test
public void setStatusTest() {
// ask for every status to be set
for (ResponseStatus expectedResponseStatus : ResponseStatus.values()) {
HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.SetStatus.toString());
request.headers().set(MockNettyMessageProcessor.STATUS_HEADER_NAME, expectedResponseStatus);
HttpUtil.setKeepAlive(request, false);
EmbeddedChannel channel = createEmbeddedChannel();
channel.writeInbound(request);
// pull but discard response
channel.readOutbound();
assertFalse("Channel not closed on the server", channel.isActive());
}
// check if all the ResponseStatus codes were recognized.
String metricName = MetricRegistry.name(NettyResponseChannel.class, "UnknownResponseStatusCount");
long metricCount = MockNettyMessageProcessor.METRIC_REGISTRY.getCounters().get(metricName).getCount();
assertEquals("Some of the ResponseStatus codes were not recognized", 0, metricCount);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class ChannelWriteCallback method closeTest.
/**
* Tests that the underlying network channel is closed when {@link NettyResponseChannel#close()} is called.
*/
@Test
public void closeTest() {
// request is keep-alive by default.
HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.Close.toString());
EmbeddedChannel channel = createEmbeddedChannel();
channel.writeInbound(request);
HttpResponse response = (HttpResponse) channel.readOutbound();
assertEquals("Unexpected response status", HttpResponseStatus.INTERNAL_SERVER_ERROR, response.status());
assertFalse("Inconsistent value for Connection header", HttpUtil.isKeepAlive(response));
// drain the channel of content.
while (channel.readOutbound() != null) {
}
assertFalse("Channel should be closed", channel.isOpen());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class PublicAccessLogHandlerTest method doRequestHandleWithKeepAliveTest.
/**
* Does a test to see that two consecutive request handling results in expected entries in public access log
* with keep alive
* @param httpMethod the {@link HttpMethod} for the request.
* @param uri Uri to be used during the request
* @param useSSL {@code true} to test SSL logging.
* @throws Exception
*/
private void doRequestHandleWithKeepAliveTest(HttpMethod httpMethod, String uri, boolean useSSL) throws Exception {
EmbeddedChannel channel = createChannel(useSSL);
// contains one logged request header
HttpHeaders headers = new DefaultHttpHeaders();
headers.add(HttpHeaderNames.CONTENT_LENGTH, new Random().nextLong());
HttpRequest request = RestTestUtils.createRequest(httpMethod, uri, headers);
HttpUtil.setKeepAlive(request, true);
sendRequestCheckResponse(channel, request, uri, headers, false, false, useSSL);
Assert.assertTrue("Channel should not be closed ", channel.isOpen());
// contains one logged and not logged header
headers = new DefaultHttpHeaders();
headers.add(NOT_LOGGED_HEADER_KEY + "1", "headerValue1");
headers.add(HttpHeaderNames.CONTENT_LENGTH, new Random().nextLong());
request = RestTestUtils.createRequest(httpMethod, uri, headers);
HttpUtil.setKeepAlive(request, true);
sendRequestCheckResponse(channel, request, uri, headers, false, false, useSSL);
Assert.assertTrue("Channel should not be closed ", channel.isOpen());
channel.close();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project ambry by linkedin.
the class PublicAccessLogHandlerTest method doRequestHandleTest.
// requestHandleTest() helpers
/**
* Does a test to see that request handling results in expected entries in public access log
* @param httpMethod the {@link HttpMethod} for the request.
* @param uri Uri to be used during the request
* @param testErrorCase true if error case has to be tested, false otherwise
* @param useSSL {@code true} to test SSL logging.
* @throws Exception
*/
private void doRequestHandleTest(HttpMethod httpMethod, String uri, boolean testErrorCase, boolean useSSL) throws Exception {
EmbeddedChannel channel = createChannel(useSSL);
List<HttpHeaders> httpHeadersList = getHeadersList();
for (HttpHeaders headers : httpHeadersList) {
HttpRequest request = RestTestUtils.createRequest(httpMethod, uri, headers);
HttpUtil.setKeepAlive(request, true);
sendRequestCheckResponse(channel, request, uri, headers, testErrorCase, false, useSSL);
if (!testErrorCase) {
Assert.assertTrue("Channel should not be closed ", channel.isOpen());
} else {
Assert.assertFalse("Channel should have been closed ", channel.isOpen());
channel = createChannel(useSSL);
}
}
channel.close();
}
Aggregations