@Test(timeout = 15000)
public void testMainFailure() throws Exception {

  ContainerLocalizerWrapper wrapper = new ContainerLocalizerWrapper();
  ContainerLocalizer localizer = wrapper.setupContainerLocalizerForTest();
  LocalizationProtocol nmProxy = wrapper.nmProxy;
  mockOutDownloads(localizer);
  // Assume the NM heartbeat fails say because of absent tokens.
  when(nmProxy.heartbeat(isA(LocalizerStatus.class))).thenThrow(
      new YarnException("Sigh, no token!"));
  // run localization, it should fail
  try {
    localizer.runLocalization(nmAddr);
    Assert.fail("Localization succeeded unexpectedly!");
  } catch (IOException e) {
    Assert.assertTrue(e.getMessage().contains("Sigh, no token!"));
  }
}