@Test
public void testAllocationWhenDockerContainerEnabled() throws Exception {

  // When docker container is enabled, no devices should be written to
  // devices.deny.
  initializeGpus();
  startContainerWithGpuRequestsDocker(1, 3);
  verifyDeniedDevices(getContainerId(1), Collections.emptyList());
  /* Start container 2, asks 2 containers. Excepted to fail */
  boolean failedToAllocate = false;
  try {
    startContainerWithGpuRequestsDocker(2, 2);
  } catch (ResourceHandlerException e) {
    failedToAllocate = true;
  }
  assertTrue("Container allocation is expected to fail!", failedToAllocate);
  startContainerWithGpuRequestsDocker(3, 1);
  verifyDeniedDevices(getContainerId(3), Collections.emptyList());
  startContainerWithGpuRequestsDocker(4, 0);
  verifyDeniedDevices(getContainerId(4), Collections.emptyList());
  gpuResourceHandler.postComplete(getContainerId(1));
  verifyCgroupsDeletedForContainer(1);
  verifyNumberOfAvailableGpus(3, gpuResourceHandler);
  gpuResourceHandler.postComplete(getContainerId(3));
  verifyCgroupsDeletedForContainer(3);
  verifyNumberOfAvailableGpus(4, gpuResourceHandler);
}