@Test
public void findEventsByEntityIdAndPageLink() {

    UUID tenantId = UUIDs.timeBased();
    UUID entityId1 = UUIDs.timeBased();
    UUID entityId2 = UUIDs.timeBased();
    long startTime = System.currentTimeMillis();
    long endTime = createEventsTwoEntities(tenantId, entityId1, entityId2, startTime, 20);
    TimePageLink pageLink1 = new TimePageLink(30, null, null, true);
    List<Event> events1 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink1);
    assertEquals(10, events1.size());
    TimePageLink pageLink2 = new TimePageLink(30, startTime, null, true);
    List<Event> events2 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink2);
    assertEquals(10, events2.size());
    TimePageLink pageLink3 = new TimePageLink(30, startTime, endTime, true);
    List<Event> events3 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink3);
    assertEquals(10, events3.size());
    TimePageLink pageLink4 = new TimePageLink(5, startTime, endTime, true);
    List<Event> events4 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink4);
    assertEquals(5, events4.size());
    UUID idOffset = events4.get(4).getId().getId();
    TimePageLink pageLink5 = new TimePageLink(10, startTime, endTime, true, idOffset);
    List<Event> events5 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink5);
    assertEquals(5, events5.size());
}