@SuppressWarnings("unchecked")
  private void publishContainerKilledEvent(
      ContainerEvent event) {
    if (publishNMContainerEvents) {
      ContainerKillEvent killEvent = (ContainerKillEvent) event;
      ContainerId containerId = killEvent.getContainerID();
      ContainerEntity entity = createContainerEntity(containerId);

      Map<String, Object> entityInfo = new HashMap<String, Object>();
      entityInfo.put(ContainerMetricsConstants.DIAGNOSTICS_INFO,
          killEvent.getDiagnostic());
      entityInfo.put(ContainerMetricsConstants.EXIT_STATUS_INFO,
          killEvent.getContainerExitStatus());
      entity.setInfo(entityInfo);

      Container container = context.getContainers().get(containerId);
      if (container != null) {
        TimelineEvent tEvent = new TimelineEvent();
        tEvent.setId(ContainerMetricsConstants.KILLED_EVENT_TYPE);
        tEvent.setTimestamp(event.getTimestamp());
        entity.addEvent(tEvent);
        dispatcher.getEventHandler().handle(new TimelinePublishEvent(entity,
            containerId.getApplicationAttemptId().getApplicationId()));
      }
    }
  }
@Test
  public void testPublishContainerKilledEvent() {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId =
        ApplicationAttemptId.newInstance(appId, 1);
    ContainerId cId = ContainerId.newContainerId(appAttemptId, 1);

    ContainerEvent containerEvent =
        new ContainerKillEvent(cId, 1, "test kill");

    publisher.createTimelineClient(appId);
    publisher.publishContainerEvent(containerEvent);
    publisher.stopTimelineClient(appId);
    dispatcher.await();

    ContainerEntity cEntity = new ContainerEntity();
    cEntity.setId(cId.toString());
    TimelineEntity[] lastPublishedEntities =
        timelineClient.getLastPublishedEntities();

    Assert.assertNotNull(lastPublishedEntities);
    Assert.assertEquals(1, lastPublishedEntities.length);
    TimelineEntity entity = lastPublishedEntities[0];
    Assert.assertEquals(cEntity, entity);

    NavigableSet<TimelineEvent> events = entity.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(ContainerMetricsConstants.KILLED_EVENT_TYPE,
        events.iterator().next().getId());

    Map<String, Object> info = entity.getInfo();
    Assert.assertTrue(
        info.containsKey(ContainerMetricsConstants.DIAGNOSTICS_INFO));
    Assert.assertEquals("test kill",
        info.get(ContainerMetricsConstants.DIAGNOSTICS_INFO));
    Assert.assertTrue(
        info.containsKey(ContainerMetricsConstants.EXIT_STATUS_INFO));
    Assert.assertEquals(1,
        info.get(ContainerMetricsConstants.EXIT_STATUS_INFO));
  }