@Test(timeout = 20000, expected = YarnRuntimeException.class)
public void testInfiniteOOM() throws Exception {

  conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH,
      script.getAbsolutePath());
  Runnable handler = mock(Runnable.class);
  try {
    FileUtils.writeStringToFile(script,
        "#!/bin/bash\nprintf oomevent;sleep 1000;\n",
        Charset.defaultCharset(), false);
    assertTrue("Could not set executable",
        script.setExecutable(true));
    CGroupsHandler cgroups = mock(CGroupsHandler.class);
    when(cgroups.getPathForCGroup(any(), any())).thenReturn("");
    when(cgroups.getCGroupParam(any(), any(), any()))
        .thenReturn("under_oom 1");
    doNothing().when(handler).run();
    CGroupElasticMemoryController controller =
        new CGroupElasticMemoryController(
            conf,
            null,
            cgroups,
            true,
            false,
            10000,
            handler
        );
    controller.run();
  } finally {
    verify(handler, times(1)).run();
    assertTrue(String.format("Could not clean up script %s",
        script.getAbsolutePath()), script.delete());
  }
}