List of usage examples for io.netty.channel.embedded EmbeddedChannel disconnect
@Override public final ChannelFuture disconnect()
From source file:com.github.ambry.rest.PublicAccessLogHandlerTest.java
License:Open Source License
/** * Sends the provided {@code httpRequest} and verifies that the response is as expected. * @param channel the {@link EmbeddedChannel} to send the request over. * @param httpRequest the {@link HttpRequest} that has to be sent * @param uri, Uri to be used for the request * @param headers {@link HttpHeaders} that is set in the request to be used for verification purposes * @param testErrorCase true if error case has to be tested, false otherwise *///from w w w. j ava2 s .c o m private void sendRequestCheckResponse(EmbeddedChannel channel, HttpRequest httpRequest, String uri, HttpHeaders headers, boolean testErrorCase, boolean chunkedResponse) { channel.writeInbound(httpRequest); if (uri.equals(EchoMethodHandler.DISCONNECT_URI)) { channel.disconnect(); } else { channel.writeInbound(new DefaultLastHttpContent()); } String lastLogEntry = publicAccessLogger.getLastPublicAccessLogEntry(); // verify remote host, http method and uri String subString = testErrorCase ? "Error" : "Info" + ":embedded" + " " + httpRequest.getMethod() + " " + uri; Assert.assertTrue("Public Access log entry doesn't have expected remote host/method/uri ", lastLogEntry.startsWith(subString)); // verify request headers verifyPublicAccessLogEntryForRequestHeaders(lastLogEntry, headers, httpRequest.getMethod(), true); // verify response subString = "Response ("; for (String responseHeader : RESPONSE_HEADERS.split(",")) { if (headers.contains(responseHeader)) { subString += "[" + responseHeader + "=" + headers.get(responseHeader) + "] "; } } subString += "[isChunked=" + chunkedResponse + "]), status=" + HttpResponseStatus.OK.code(); if (!testErrorCase) { Assert.assertTrue("Public Access log entry doesn't have response set correctly", lastLogEntry.contains(subString)); } else { Assert.assertTrue("Public Access log entry doesn't have error set correctly ", lastLogEntry.contains(": Channel closed while request in progress.")); } }