@Test
  public void testRejectRequestsOnExpiry() throws InterruptedException {
    ServerRequestResponseHelper requestResponseHelper = mock(ServerRequestResponseHelper.class);
    MockTime mockTime = new MockTime();
    FifoNetworkRequestQueue requestQueue = new FifoNetworkRequestQueue(TIMEOUT, mockTime, CAPACITY);
    NettyServerRequestResponseChannel channel =
        spy(new NettyServerRequestResponseChannel(new Http2ServerMetrics(new MetricRegistry()),
            new ServerMetrics(new MetricRegistry(), this.getClass()), requestResponseHelper, requestQueue));
    doNothing().when(channel).rejectRequest(any(), anyBoolean());
    // Queue 2 requests with a sleep between them so that 1st request expires
    NettyServerRequest expiredRequest = createNettyServerRequest(mockTime.milliseconds());
    channel.sendRequest(expiredRequest);
    mockTime.sleep(TIMEOUT + 1);
    NettyServerRequest validRequest = createNettyServerRequest(mockTime.milliseconds());
    channel.sendRequest(validRequest);
    // 1. Verify received request is 2nd request
    NetworkRequest receiveRequest = channel.receiveRequest();
    assertEquals("Mismatch in request dequeued", validRequest, receiveRequest);
    // 2. Verify rejectRequest() is invoked with 1st request
    verify(channel, times(1)).rejectRequest(eq(expiredRequest), eq(true));
  }
Test send and receive requests
@throws Exception
ambry-network/src/test/java/com/github/ambry/network/NettyServerRequestResponseChannelTest.java