use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class BaseEventServiceTest method saveEventWithProvidedTime.
private Event saveEventWithProvidedTime(long time, EntityId entityId, TenantId tenantId) throws IOException {
Event event = generateEvent(tenantId, entityId, DataConstants.STATS, null);
event.setId(new EventId(UUIDs.startOf(time)));
return eventService.save(event);
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class BaseEventServiceTest method findEventsByTypeAndTimeAscOrder.
@Test
public void findEventsByTypeAndTimeAscOrder() throws Exception {
long timeBeforeStartTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
long startTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
long eventTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
RuleId ruleId = new RuleId(UUIDs.timeBased());
TenantId tenantId = new TenantId(UUIDs.timeBased());
saveEventWithProvidedTime(timeBeforeStartTime, ruleId, tenantId);
Event savedEvent = saveEventWithProvidedTime(eventTime, ruleId, tenantId);
Event savedEvent2 = saveEventWithProvidedTime(eventTime + 1, ruleId, tenantId);
Event savedEvent3 = saveEventWithProvidedTime(eventTime + 2, ruleId, tenantId);
saveEventWithProvidedTime(timeAfterEndTime, ruleId, tenantId);
TimePageData<Event> events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, new TimePageLink(2, startTime, endTime, true));
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 2);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent.getUuidId()));
Assert.assertTrue(events.getData().get(1).getUuidId().equals(savedEvent2.getUuidId()));
Assert.assertTrue(events.hasNext());
Assert.assertNotNull(events.getNextPageLink());
events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, events.getNextPageLink());
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 1);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent3.getUuidId()));
Assert.assertFalse(events.hasNext());
Assert.assertNull(events.getNextPageLink());
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class BaseEventServiceTest method saveEventIfNotExists.
@Test
public void saveEventIfNotExists() throws Exception {
DeviceId devId = new DeviceId(UUIDs.timeBased());
Event event = generateEvent(null, devId, "ALARM", UUIDs.timeBased().toString());
Optional<Event> saved = eventService.saveIfNotExists(event);
Assert.assertTrue(saved.isPresent());
saved = eventService.saveIfNotExists(event);
Assert.assertFalse(saved.isPresent());
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method findEventsByEntityIdAndEventTypeAndPageLink.
@Test
public void findEventsByEntityIdAndEventTypeAndPageLink() {
UUID tenantId = UUIDs.timeBased();
UUID entityId1 = UUIDs.timeBased();
UUID entityId2 = UUIDs.timeBased();
long startTime = System.currentTimeMillis();
long endTime = createEventsTwoEntitiesTwoTypes(tenantId, entityId1, entityId2, startTime, 20);
TimePageLink pageLink1 = new TimePageLink(30, null, null, true);
List<Event> events1 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink1);
assertEquals(5, events1.size());
TimePageLink pageLink2 = new TimePageLink(30, startTime, null, true);
List<Event> events2 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink2);
assertEquals(5, events2.size());
TimePageLink pageLink3 = new TimePageLink(30, startTime, endTime, true);
List<Event> events3 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink3);
assertEquals(5, events3.size());
TimePageLink pageLink4 = new TimePageLink(4, startTime, endTime, true);
List<Event> events4 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink4);
assertEquals(4, events4.size());
UUID idOffset = events3.get(2).getId().getId();
TimePageLink pageLink5 = new TimePageLink(10, startTime, endTime, true, idOffset);
List<Event> events5 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink5);
assertEquals(2, events5.size());
}
use of org.thingsboard.server.common.data.Event in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method createEventsTwoEntitiesTwoTypes.
private long createEventsTwoEntitiesTwoTypes(UUID tenantId, UUID entityId1, UUID entityId2, long startTime, int count) {
for (int i = 0; i < count / 2; i++) {
String type = i % 2 == 0 ? STATS : ALARM;
UUID eventId1 = UUIDs.timeBased();
Event event1 = getEvent(eventId1, tenantId, entityId1, type);
eventDao.save(event1);
UUID eventId2 = UUIDs.timeBased();
Event event2 = getEvent(eventId2, tenantId, entityId2, type);
eventDao.save(event2);
}
return System.currentTimeMillis();
}
Aggregations