@VisibleForTesting
  void updateBackoffMetrics(int retryCount, int statusCode) {
    if (abfsBackoffMetrics != null) {
      if (statusCode < HttpURLConnection.HTTP_OK
              || statusCode >= HttpURLConnection.HTTP_INTERNAL_ERROR) {
        synchronized (this) {
          if (retryCount >= maxIoRetries) {
            abfsBackoffMetrics.incrementNumberOfRequestsFailed();
          }
        }
      } else {
        synchronized (this) {
          if (retryCount > ZERO && retryCount <= maxIoRetries) {
            maxRetryCount = Math.max(abfsBackoffMetrics.getMaxRetryCount(), retryCount);
            abfsBackoffMetrics.setMaxRetryCount(maxRetryCount);
            updateCount(retryCount);
          } else {
            abfsBackoffMetrics.incrementNumberOfRequestsSucceededWithoutRetrying();
          }
        }
      }
    }
  }
@Test
  public void testBackoffRetryMetrics() throws Exception {
    // Create an AzureBlobFileSystem instance.
    final Configuration configuration = getRawConfiguration();
    configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT));
    final AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration);
    AbfsConfiguration abfsConfiguration = fs.getAbfsStore().getAbfsConfiguration();

    // Get an instance of AbfsClient and AbfsRestOperation.
    AbfsClient testClient = super.getAbfsClient(super.getAbfsStore(fs));
    AbfsRestOperation op = ITestAbfsClient.getRestOp(
        DeletePath, testClient, HTTP_METHOD_DELETE,
        ITestAbfsClient.getTestUrl(testClient, "/NonExistingPath"),
        ITestAbfsClient.getTestRequestHeaders(testClient), getConfiguration());

    // Mock retry counts and status code.
    ArrayList<String> retryCounts = new ArrayList<>(Arrays.asList("35", "28", "31", "45", "10", "2", "9"));
    int statusCode = HttpURLConnection.HTTP_UNAVAILABLE;

    // Update backoff metrics.
    for (String retryCount : retryCounts) {
      op.updateBackoffMetrics(Integer.parseInt(retryCount), statusCode);
    }

    // For retry count greater than the max configured value, the request should fail.
    Assert.assertEquals("Number of failed requests does not match expected value.",
            "3", String.valueOf(testClient.getAbfsCounters().getAbfsBackoffMetrics().getNumberOfRequestsFailed()));

    // Close the AzureBlobFileSystem.
    fs.close();
  }