@SuppressWarnings("unchecked")
  @Test
  public void testStatsNumIdleCachedInstancesDecrementsDuringExecute() {
    // Make sure we only get FOO_ENDPOINT.
    reset(_loadBalanceAlgorithm);
    when(_loadBalanceAlgorithm.choose(
            Matchers.<Iterable<ServiceEndPoint>>any(), any(ServicePoolStatistics.class)))
        .thenReturn(FOO_ENDPOINT);

    // Prime the cache.
    _pool.execute(NEVER_RETRY, mock(ServiceCallback.class));

    final ServicePoolStatistics servicePoolStatistics = _pool.getServicePoolStatistics();

    int numIdleInitially = servicePoolStatistics.getNumIdleCachedInstances(FOO_ENDPOINT);

    int numIdleDuringExecute =
        _pool.execute(
            NEVER_RETRY,
            new ServiceCallback<Service, Integer>() {
              @Override
              public Integer call(Service service) throws ServiceException {
                return servicePoolStatistics.getNumIdleCachedInstances(FOO_ENDPOINT);
              }
            });

    assertEquals(numIdleInitially - 1, numIdleDuringExecute);
  }
  @Test
  public void testStatsNumActiveInstancesDecrementsAfterExecute() {
    // Make sure we only get FOO_ENDPOINT.
    reset(_loadBalanceAlgorithm);
    when(_loadBalanceAlgorithm.choose(
            Matchers.<Iterable<ServiceEndPoint>>any(), any(ServicePoolStatistics.class)))
        .thenReturn(FOO_ENDPOINT);

    final ServicePoolStatistics servicePoolStatistics = _pool.getServicePoolStatistics();

    int numActiveDuringExecute =
        _pool.execute(
            NEVER_RETRY,
            new ServiceCallback<Service, Integer>() {
              @Override
              public Integer call(Service service) throws ServiceException {
                return servicePoolStatistics.getNumActiveInstances(FOO_ENDPOINT);
              }
            });

    int numActiveAfterExecute = servicePoolStatistics.getNumActiveInstances(FOO_ENDPOINT);

    assertEquals(numActiveDuringExecute - 1, numActiveAfterExecute);
  }