Source:
<code>public void completeRequestWithDelayedCloseTest() throws Exception { Properties properties = new Properties(); properties.setProperty(NettyConfig.NETTY_SERVER_CLOSE_DELAY_TIMEOUT_MS, "500"); NettyConfig nettyConfig = new NettyConfig(new VerifiableProperties(properties)); MockNettyMessageProcessor processor = new MockNettyMessageProcessor(); processor.setNettyConfig(nettyConfig); ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler(); EmbeddedChannel channel = new EmbeddedChannel(chunkedWriteHandler, processor); RestServiceErrorCode REST_ERROR_CODE = RestServiceErrorCode.BadRequest; String content = "@@randomContent@@@"; HttpHeaders httpHeaders = new DefaultHttpHeaders(); httpHeaders.set(MockNettyMessageProcessor.REST_SERVICE_ERROR_CODE_HEADER_NAME, REST_ERROR_CODE); httpHeaders.set(MockNettyMessageProcessor.INCLUDE_EXCEPTION_MESSAGE_IN_RESPONSE_HEADER_NAME, "true"); HttpRequest httpRequest = RestTestUtils.createFullRequest(HttpMethod.POST, TestingUri.OnResponseCompleteWithRestException.toString(), httpHeaders, content.getBytes()); channel.writeInbound(httpRequest); HttpResponse response = (HttpResponse) channel.readOutbound(); assertEquals("Unexpected response status", getExpectedHttpResponseStatus(REST_ERROR_CODE), response.status()); <START> assertTrue("Channel closed on the server", channel.isActive()); <END> }</code><technical_language>wait 500ms verify get closed. check counters incremented</technical_language>

Target:
public void completeRequestWithDelayedCloseTest() throws Exception { Properties properties = new Properties(); long delayMs = 500; properties.setProperty(NettyConfig.NETTY_SERVER_CLOSE_DELAY_TIMEOUT_MS, String.valueOf(delayMs)); NettyConfig nettyConfig = new NettyConfig(new VerifiableProperties(properties)); MockNettyMessageProcessor processor = new MockNettyMessageProcessor(); processor.setNettyConfig(nettyConfig); ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler(); EmbeddedChannel channel = new EmbeddedChannel(chunkedWriteHandler, processor); RestServiceErrorCode REST_ERROR_CODE = RestServiceErrorCode.BadRequest; String content = "@@randomContent@@@"; HttpHeaders httpHeaders = new DefaultHttpHeaders(); httpHeaders.set(MockNettyMessageProcessor.REST_SERVICE_ERROR_CODE_HEADER_NAME, REST_ERROR_CODE); httpHeaders.set(MockNettyMessageProcessor.INCLUDE_EXCEPTION_MESSAGE_IN_RESPONSE_HEADER_NAME, "true"); HttpRequest httpRequest = RestTestUtils.createFullRequest(HttpMethod.POST, TestingUri.OnResponseCompleteWithRestException.toString(), httpHeaders, content.getBytes()); channel.writeInbound(httpRequest); HttpResponse response = channel.readOutbound(); assertEquals("Unexpected response status", getExpectedHttpResponseStatus(REST_ERROR_CODE), response.status()); assertTrue("Channel closed on the server", channel.isActive()); Thread.sleep(delayMs * 2); channel.runPendingTasks(); assertFalse("Channel not closed on the server", channel.isActive()); assertEquals("delayed close scheduled counter mismatch", 1, processor.getNettyMetrics().delayedCloseScheduledCount.getCount()); assertEquals("delayed close executed counter mismatch", 1, processor.getNettyMetrics().delayedCloseExecutedCount.getCount()); }