Skip to content

Commit

Permalink
refactor: recordEvent function
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Sep 25, 2023
1 parent 3b5aa05 commit 58fd752
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ private void stop() {
}

/**
* Records an event and checks if it was recorded correctly
* by looking into event queue
* Recording an event with segmentation
* "recordEvent" function should create an event with given key and segmentation and add it to event queue
* recorded event should have correct key, segmentation, count, sum, duration, dow, hour and timestamp
*/
@Test
public void recordEvent() {
Config config = TestUtils.getBaseConfig();
config.enableFeatures(Config.Feature.Events).setEventQueueSizeToSend(4);
init(config);

Assert.assertEquals(0, moduleEvents.eventQueue.eqSize());
List<EventImpl> events = TestUtils.getCurrentEventQueue(moduleEvents.ctx.getContext(), moduleEvents.L);
validateQueueSize(0, events);

//create segmentation
Map<String, Object> segmentation = new HashMap<>();
Expand All @@ -46,14 +48,14 @@ public void recordEvent() {
Countly.instance().events().recordEvent("test-recordEvent", 1, 45.9, segmentation, 32.0);

//check if event was recorded correctly and size of event queue is equal to size of events in queue
List<EventImpl> events = TestUtils.getCurrentEventQueue(moduleEvents.ctx.getContext(), moduleEvents.L);
Assert.assertEquals(1, moduleEvents.eventQueue.eqSize());
Assert.assertEquals(1, events.size());
events = TestUtils.getCurrentEventQueue(moduleEvents.ctx.getContext(), moduleEvents.L);
validateQueueSize(1, events);

//check if event was recorded correctly
EventImpl event = events.get(0);
EventImpl eventInMemory = moduleEvents.eventQueue.eventQueueMemoryCache.get(0);
validateEvent(event, "test-recordEvent", segmentation, 1, 45.9, 32.0, event.dow, event.hour, event.timestamp);

validateEvent(eventInMemory, "test-recordEvent", segmentation, 1, 45.9, 32.0, event.dow, event.hour, event.timestamp);
stop();
}

Expand Down Expand Up @@ -281,6 +283,11 @@ public void endEvent_withSegmentation_negativeCount() {
stop();
}

private void validateQueueSize(int expectedSize, List<EventImpl> events) {
Assert.assertEquals(expectedSize, events.size());
Assert.assertEquals(expectedSize, moduleEvents.eventQueue.eqSize());
}

private void validateEvent(EventImpl gonnaValidate, String key, Map<String, Object> segmentation,
int count, Double sum, Double duration, int dow, int hour, long timestamp) {
Assert.assertEquals(key, gonnaValidate.key);
Expand Down

0 comments on commit 58fd752

Please sign in to comment.