NumaResourceHandlerImpl implements ResourceHandler { @Override public List<PrivilegedOperation> reacquireContainer(ContainerId containerId) throws ResourceHandlerException { try { numaResourceAllocator.recoverNumaResource(containerId); } catch (Throwable e) { throw new ResourceHandlerException( "Failed to recover numa resource for " + containerId, e); } return null; } NumaResourceHandlerImpl(Configuration conf, Context nmContext); @Override List<PrivilegedOperation> bootstrap(Configuration configuration); @Override List<PrivilegedOperation> preStart(Container container); @Override List<PrivilegedOperation> reacquireContainer(ContainerId containerId); @Override List<PrivilegedOperation> updateContainer(Container container); @Override List<PrivilegedOperation> postComplete(ContainerId containerId); @Override List<PrivilegedOperation> teardown(); @Override String toString();  }
@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(); NumaResourceAllocation numaResourceAllocation = new NumaResourceAllocation( "0", 70000, "0", 4); 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); numaResourceHandler = new NumaResourceHandlerImpl(conf, mockContext); numaResourceHandler.bootstrap(conf); numaResourceHandler.reacquireContainer( ContainerId.fromString("container_1481156246874_0001_01_000001")); testAllocateNumaResource("container_1481156246874_0001_01_000005", Resource.newInstance(2048, 1), "1", "1"); when(mockContainer.getContainerId()).thenReturn( ContainerId.fromString("container_1481156246874_0001_01_000005")); when(mockContainer.getResource()).thenReturn(Resource.newInstance(2048, 4)); List<PrivilegedOperation> preStart = numaResourceHandler .preStart(mockContainer); assertNull(preStart); }