@Test
  public void testRejectRequestsOnOverFlowWithException() throws IOException, 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).sendResponse(any(), any(), any());
    when(requestResponseHelper.getDecodedRequest(any())).thenThrow(
        new UnsupportedOperationException("Request type not supported"));
    try {
      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));
      // 2. Verify close connection is invoked due to exception thrown and caught inside rejectRequest()
      verify(channel, times(1)).closeConnection(any());
    } catch (Exception e) {
      fail("Should not have thrown any exception");
    }
  }
Test send and receive requests
@throws Exception
ambry-network/src/test/java/com/github/ambry/network/NettyServerRequestResponseChannelTest.java