hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/web/client/TestVolume.java
private static void verifyHttpConnectionClosed(
      List<CloseableHttpClient> mockedHttpClients) {
    final AtomicInteger totalCalled = new AtomicInteger();
    assertTrue(mockedHttpClients.stream().allMatch(closeableHttpClient -> {
      boolean clientUsed = false;
      try {
        verify(closeableHttpClient, times(1)).execute(Mockito.any());
        totalCalled.incrementAndGet();
        clientUsed = true;
      } catch (Throwable e) {
        // There might be some redundant instances in mockedHttpClients,
        // it is allowed that a client is not used.
        return true;
      }

      if (clientUsed) {
        try {
          // If a client is used, ensure the close function is called.
          verify(closeableHttpClient, times(1)).close();
          return true;
        } catch (IOException e) {
          return false;
        }
      } else {
        return true;
      }
    }));
    System.out.println("Successful connections " + totalCalled.get());
    assertTrue("The mocked http client should be called at least once.",
        totalCalled.get() > 0);
  }
/**
   * This method is used together with
   * {@link TestVolume#mockHttpClients(OzoneRestClient)} to verify
   * if the http client is properly closed. It verifies that as long as
   * a client calls {@link CloseableHttpClient#execute(HttpUriRequest)} to
   * send request, then it must calls {@link CloseableHttpClient#close()}
   * close the http connection.
   *
   * @param mockedHttpClients
   */
This method is used together with
TestVolume#mockHttpClients(OzoneRestClient) to verify
if the http client is properly closed. It verifies that as long as
a client calls  CloseableHttpClient#execute(HttpUriRequest) to
send request, then it must calls  CloseableHttpClient#close()
close the http connection.


This method is used together with TestVolume#mockHttpClients ( OzoneRestClient ) to verify if the http client is properly closed . It verifies that as long as a client calls CloseableHttpClient#execute ( HttpUriRequest ) to send request then it must calls CloseableHttpClient#close () close the http connection .
private static void verifyHttpConnectionClosed(
      List<CloseableHttpClient> mockedHttpClients) {
    final AtomicInteger totalCalled = new AtomicInteger();
    assertTrue(mockedHttpClients.stream().allMatch(closeableHttpClient -> {
      boolean clientUsed = false;
      try {
        verify(closeableHttpClient, times(1)).execute(Mockito.any());
        totalCalled.incrementAndGet();
        clientUsed = true;
      } catch (Throwable e) {
        return true;
      }
      if (clientUsed) {
        try {
          verify(closeableHttpClient, times(1)).close();
          return true;
        } catch (IOException e) {
          return false;
        }
      } else {
        return true;
      }
    }));
    System.out.println("Successful connections " + totalCalled.get());
    assertTrue("The mocked http client should be called at least once.",
        totalCalled.get() > 0);
  }
private static void verifyHttpConnectionClosed ( List < CloseableHttpClient > mockedHttpClients ) { final AtomicInteger totalCalled = new AtomicInteger ( ) ; assertTrue ( mockedHttpClients . stream ( ) . allMatch ( closeableHttpClient -> { boolean clientUsed = false ; try { verify ( closeableHttpClient , times ( 1 ) ) . execute ( Mockito . any ( ) ) ; totalCalled . incrementAndGet ( ) ; clientUsed = true ; } catch ( Throwable e ) { return true ; } if ( clientUsed ) { try { verify ( closeableHttpClient , times ( 1 ) ) . close ( ) ; return true ; } catch ( IOException e ) { return false ; } } else { return true ; } } ) ) ; System . out . println ( "Successful connections " + totalCalled . get ( ) ) ; assertTrue ( "The mocked http client should be called at least once." , totalCalled . get ( ) > 0 ) ; }
This method is used together with
 {@link TestVolume#mockHttpClients(OzoneRestClient)} to verify
 if the http client is properly closed.
This method is used together with { @link TestVolume#mockHttpClients ( OzoneRestClient ) } to verify if the http client is properly closed .
// There might be some redundant instances in mockedHttpClients, // it is allowed that a client is not used. // If a client is used, ensure the close function is called.