@Override
  public int reacquireContainer(ContainerReacquisitionContext ctx)
          throws IOException, InterruptedException {
    try {
      if (numaResourceAllocator != null) {
        numaResourceAllocator.recoverNumaResource(ctx.getContainerId());
      }
      return super.reacquireContainer(ctx);
    } finally {
      postComplete(ctx.getContainerId());
    }
  }
@Test
  public void testReacquireContainer() throws Exception {
    @SuppressWarnings("unchecked")
    ConcurrentHashMap<ContainerId, Container> mockContainers = mock(
            ConcurrentHashMap.class);
    Context mockContext = mock(Context.class);
    NMStateStoreService mock = mock(NMStateStoreService.class);
    when(mockContext.getNMStateStore()).thenReturn(mock);
    ResourceMappings resourceMappings = new ResourceMappings();
    AssignedResources assignedRscs = new AssignedResources();
    when(mockContainer.getResource())
            .thenReturn(Resource.newInstance(147434, 2));
    ContainerId cid = ContainerId.fromString("container_1481156246874_0001_01_000001");
    when(mockContainer.getContainerId()).thenReturn(cid);
    NumaResourceAllocation numaResourceAllocation =
            numaResourceAllocator.allocateNumaNodes(mockContainer);
    assignedRscs.updateAssignedResources(Arrays.asList(numaResourceAllocation));
    resourceMappings.addAssignedResources("numa", assignedRscs);
    when(mockContainer.getResourceMappings()).thenReturn(resourceMappings);
    when(mockContainers.get(any())).thenReturn(mockContainer);
    when(mockContext.getContainers()).thenReturn(mockContainers);

    // recovered numa resources should be added to the used resources and
    // remaining will be available for further allocation.

    ContainerReacquisitionContext containerReacquisitionContext =
            new ContainerReacquisitionContext.Builder()
                    .setContainerId(cid)
                    .setUser("user")
                    .setContainer(mockContainer)
                    .build();

    containerExecutor.reacquireContainer(containerReacquisitionContext);

    // reacquireContainer recovers all the numa resources ,
    // that should be free to use next
    testAllocateNumaResource("container_1481156246874_0001_01_000001",
            Resource.newInstance(147434, 2), "0,1", "1");
    when(mockContainer.getContainerId()).thenReturn(
            ContainerId.fromString("container_1481156246874_0001_01_000004"));
    when(mockContainer.getResource())
            .thenReturn(Resource.newInstance(1024, 2));

    // returns null since there are no sufficient resources available for the request
    Assert.assertNull(numaResourceAllocator.allocateNumaNodes(mockContainer));
  }