@Test
public void testOneOpportunisticContainerOverLimitUponOOM() throws Exception {

  ConcurrentHashMap<ContainerId, Container> containers =
      new ConcurrentHashMap<>();
  Container c1 = createContainer(1, false, 2L, true);
  containers.put(c1.getContainerId(), c1);
  Container c2 = createContainer(2, false, 1L, true);
  containers.put(c2.getContainerId(), c2);
  ContainerExecutor ex = createContainerExecutor(containers);
  Context context = mock(Context.class);
  when(context.getContainers()).thenReturn(containers);
  when(context.getContainerExecutor()).thenReturn(ex);
  CGroupsHandler cGroupsHandler = mock(CGroupsHandler.class);
  when(cGroupsHandler.getCGroupParam(
      CGroupsHandler.CGroupController.MEMORY,
      "",
      CGROUP_PARAM_MEMORY_OOM_CONTROL))
      .thenReturn("under_oom 1").thenReturn("under_oom 0");
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c1.getContainerId().toString(), CGROUP_PROCS_FILE))
      .thenReturn("1234").thenReturn("");
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c1.getContainerId().toString(), CGROUP_PARAM_MEMORY_USAGE_BYTES))
      .thenReturn(getMB(9));
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c1.getContainerId().toString(), CGROUP_PARAM_MEMORY_MEMSW_USAGE_BYTES))
      .thenReturn(getMB(9));
  // contnainer c2 is out of its limit
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c2.getContainerId().toString(), CGROUP_PROCS_FILE))
      .thenReturn("1235").thenReturn("");
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c2.getContainerId().toString(), CGROUP_PARAM_MEMORY_USAGE_BYTES))
      .thenReturn(getMB(11));
  when(cGroupsHandler.getCGroupParam(CGroupsHandler.CGroupController.MEMORY,
      c2.getContainerId().toString(), CGROUP_PARAM_MEMORY_MEMSW_USAGE_BYTES))
      .thenReturn(getMB(11));
  DefaultOOMHandler handler =
      new DefaultOOMHandler(context, false) {
        @Override
        protected CGroupsHandler getCGroupsHandler() {
          return cGroupsHandler;
        }
      };
  handler.run();
  verify(ex, times(1)).signalContainer(
      new ContainerSignalContext.Builder()
          .setPid("1235")
          .setContainer(c2)
          .setSignal(ContainerExecutor.Signal.KILL)
          .build()
  );
  verify(ex, times(1)).signalContainer(any());
}