@Test
public void testAllocation() throws Exception {

  initializeGpus();
  //Start container 1, asks 3 containers --> Only device=4 will be blocked.
  startContainerWithGpuRequests(1, 3);
  verifyDeniedDevices(getContainerId(1),
      Collections.singletonList(new GpuDevice(3, 4)));
  /* Start container 2, asks 2 containers. Excepted to fail */
  boolean failedToAllocate = false;
  try {
    startContainerWithGpuRequests(2, 2);
  } catch (ResourceHandlerException e) {
    failedToAllocate = true;
  }
  assertTrue("Container allocation is expected to fail!", failedToAllocate);
  // Start container 3, ask 1 container, succeeded
  // devices = 0/1/3 will be blocked
  startContainerWithGpuRequests(3, 1);
  verifyDeniedDevices(getContainerId(3), Arrays.asList(new GpuDevice(0, 0),
      new GpuDevice(1, 1), new GpuDevice(2, 3)));
  // Start container 4, ask 0 container, succeeded
  // --> All devices will be blocked
  startContainerWithGpuRequests(4, 0);
  verifyDeniedDevices(getContainerId(4), Arrays.asList(new GpuDevice(0, 0),
      new GpuDevice(1, 1), new GpuDevice(2, 3), new GpuDevice(3, 4)));
  gpuResourceHandler.postComplete(getContainerId(1));
  verifyCgroupsDeletedForContainer(1);
  verifyNumberOfAvailableGpus(3, gpuResourceHandler);
  gpuResourceHandler.postComplete(getContainerId(3));
  verifyCgroupsDeletedForContainer(3);
  verifyNumberOfAvailableGpus(4, gpuResourceHandler);
}