@After
  public void destroyCacheAndDLS() {
    if (DLockService.getServiceNamed(AutoBalancer.AUTO_BALANCER_LOCK_SERVICE_NAME) != null) {
      DLockService.destroy(AutoBalancer.AUTO_BALANCER_LOCK_SERVICE_NAME);
    }

    AutoBalancer autoBalancer = (AutoBalancer) cache.getInitializer();
    if (autoBalancer != null) {
      autoBalancer.destroy();
    }

    if (cache != null && !cache.isClosed()) {
      try {
        final HostStatSampler statSampler =
            ((InternalDistributedSystem) cache.getDistributedSystem()).getStatSampler();
        cache.close();
        // wait for the stat sampler to stand down
        await().until(isAlive(statSampler), equalTo(false));
      } finally {
        cache = null;
      }
    }
  }
IntegrationTests for AutoBalancer that include usage of Cache, StatSampler and
DistributedLockService.
geode-rebalancer/src/integrationTest/java/org/apache/geode/cache/util/AutoBalancerIntegrationJUnitTest.java