@Test
public void testGetEntitiesByTimeWindows() throws Exception {

  // Get entities based on created time start and end time range.
  Set<TimelineEntity> result = reader.getEntities(
      new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1",
      "app", null),
      new TimelineEntityFilters.Builder().createdTimeBegin(1425016502030L)
          .createTimeEnd(1425016502060L).build(),
      new TimelineDataToRetrieve());
  Assert.assertEquals(1, result.size());
  // Only one entity with ID id_4 should be returned.
  for (TimelineEntity entity : result) {
    if (!entity.getId().equals("id_4")) {
      Assert.fail("Incorrect filtering based on created time range");
    }
  }
  // Get entities if only created time end is specified.
  result = reader.getEntities(
      new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1",
          "app", null),
      new TimelineEntityFilters.Builder().createTimeEnd(1425016502010L)
          .build(),
      new TimelineDataToRetrieve());
  Assert.assertEquals(3, result.size());
  for (TimelineEntity entity : result) {
    if (entity.getId().equals("id_4")) {
      Assert.fail("Incorrect filtering based on created time range");
    }
  }
  // Get entities if only created time start is specified.
  result = reader.getEntities(
      new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1",
      "app", null),
      new TimelineEntityFilters.Builder().createdTimeBegin(1425016502010L)
          .build(),
      new TimelineDataToRetrieve());
  Assert.assertEquals(1, result.size());
  for (TimelineEntity entity : result) {
    if (!entity.getId().equals("id_4")) {
      Assert.fail("Incorrect filtering based on created time range");
    }
  }
}