@Test
  public void testRejectRequestsOnOverFlow() throws InterruptedException {
    Properties properties = new Properties();
    properties.setProperty(NetworkConfig.REQUEST_QUEUE_CAPACITY, "2");
    ServerRequestResponseHelper requestResponseHelper = mock(ServerRequestResponseHelper.class);
    NettyServerRequestResponseChannel channel =
        spy(new NettyServerRequestResponseChannel(new NetworkConfig(new VerifiableProperties(properties)),
            new Http2ServerMetrics(new MetricRegistry()), new ServerMetrics(new MetricRegistry(), this.getClass()),
            requestResponseHelper));
    doNothing().when(channel).rejectRequest(any(), anyBoolean());
    channel.sendRequest(createNettyServerRequest(1));
    channel.sendRequest(createNettyServerRequest(1));
    // 1. Verify rejectRequest() is invoked for last request
    NettyServerRequest overFlowRequest = createNettyServerRequest(1);
    channel.sendRequest(overFlowRequest);
    verify(channel, times(1)).rejectRequest(eq(overFlowRequest), eq(false));
  }
Test send and receive requests
@throws Exception
ambry-network/src/test/java/com/github/ambry/network/NettyServerRequestResponseChannelTest.java