Skip to content

Commit

Permalink
Merge branch 'views_test' into new_view_module
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray authored Jan 31, 2024
2 parents 171052f + 973e715 commit 18035e9
Show file tree
Hide file tree
Showing 12 changed files with 1,716 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private Map<String, Object> createViewEventSegmentation(@Nonnull ViewData vd, bo
if (firstView) {
viewSegmentation.put(KEY_START, KEY_START_VALUE);
}

viewSegmentation.put(KEY_SEGMENT, internalConfig.getSdkPlatform());
return viewSegmentation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ public void restoreFromDisk() throws IOException {
init(TestUtils.getConfigEvents(2));

TestUtils.validateEQSize(0, eventQueue);
writeToEventQueue("{\"hour\":10,\"count\":1,\"dow\":4,\"key\":\"test-joinEvents-1\",\"timestamp\":1695887006647}:::{\"hour\":10,\"count\":1,\"dow\":4,\"key\":\"test-joinEvents-2\",\"timestamp\":1695887006657}", false);
writeToEventQueue("{\"id\":\"id\",\"cvid\":\"cvid\",\"pvid\":\"pvid\",\"peid\":\"peid\",\"hour\":10,\"count\":1,\"dow\":4,\"key\":\"test-joinEvents-1\",\"timestamp\":1695887006647}:::{\"hour\":10,\"count\":1,\"dow\":4,\"key\":\"test-joinEvents-2\",\"timestamp\":1695887006657}", false);

eventQueue.restoreFromDisk();
TestUtils.validateEQSize(2, eventQueue);
validateEvent(eventQueue.eventQueueMemoryCache.get(0), "test-joinEvents-1", null, 1, null, null);
validateEvent(eventQueue.eventQueueMemoryCache.get(1), "test-joinEvents-2", null, 1, null, null);
validateEvent(eventQueue.eventQueueMemoryCache.get(0), "test-joinEvents-1", null, 1, null, null, "id", "pvid", "cvid", "peid");
validateEvent(eventQueue.eventQueueMemoryCache.get(1), "test-joinEvents-2", null, 1, null, null, null, null, null, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ private void validateDeviceIdWithoutMergeChange(final int rqSize, String oldDevi
viewSegmentation.put("name", TestUtils.keysValues[1]);
viewSegmentation.put("start", "1");
viewSegmentation.put("visit", "1");
TestUtils.validateEvent(existingEvents.get(1), "[CLY]_view", viewSegmentation, 1, null, null); // view start event
TestUtils.validateEvent(existingEvents.get(1), "[CLY]_view", viewSegmentation, 1, 0.0, null, "_CLY_", "", null, null); // view start event
viewSegmentation.remove("start");
viewSegmentation.remove("visit");
TestUtils.validateEvent(existingEvents.get(3), "[CLY]_view", viewSegmentation, 1, null, 1.0); // view stop event
TestUtils.validateEvent(existingEvents.get(3), "[CLY]_view", viewSegmentation, 1, 0.0, 1.0, "_CLY_", "", null, null); // view stop event
remainingRequestIndex++;
}
} catch (NullPointerException ignored) {
Expand Down Expand Up @@ -591,8 +591,12 @@ private void setupEvent() {
private List<EventImpl> validateEvents(int requestIndex, String deviceId, int timedEventIdx) {
List<EventImpl> existingEvents = TestUtils.readEventsFromRequest(requestIndex, deviceId);
if (!existingEvents.isEmpty()) {
TestUtils.validateEvent(existingEvents.get(0), TestUtils.keysValues[2], null, 1, null, null); // casual event
TestUtils.validateEvent(existingEvents.get(timedEventIdx), TestUtils.keysValues[0], null, 1, null, 1.0); // timed event
String expectedCVId = "";
if (existingEvents.size() > 2) {
expectedCVId = existingEvents.get(3).id;
}
TestUtils.validateEvent(existingEvents.get(0), TestUtils.keysValues[2], null, 1, null, null, "_CLY_", null, "", null); // casual event
TestUtils.validateEvent(existingEvents.get(timedEventIdx), TestUtils.keysValues[0], null, 1, null, 1.0, "_CLY_", null, expectedCVId, existingEvents.get(0).id); // timed event
}

return existingEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void recordEvent() {
Countly.instance().events().recordEvent(eKeys[0], segmentation, 1, 45.9, 32.0);

//check if event was recorded correctly and size of event queue is equal to size of events in queue
TestUtils.validateEventInEQ(eKeys[0], segmentation, 1, 45.9, 32.0, 0, 1);
TestUtils.validateEventInEQ(eKeys[0], segmentation, 1, 45.9, 32.0, 0, 1, "_CLY_", null, "", null);
}

/**
Expand All @@ -75,8 +75,11 @@ public void recordEvent_queueSizeOver() {
Assert.assertEquals(1, TestUtils.getCurrentRQ().length);

List<EventImpl> eventsInRequest = TestUtils.readEventsFromRequest();
validateEvent(eventsInRequest.get(0), eKeys[0], null, 1, 45.9, 32.0);
validateEvent(eventsInRequest.get(1), eKeys[1], null, 1, 45.9, 32.0);

// check first event has no peid and has an SDK generated id by giving "_CLY_" flag to the function
validateEvent(eventsInRequest.get(0), eKeys[0], null, 1, 45.9, 32.0, "_CLY_", null, "", null);
// check second event has peid of first event and has an SDK generated id by giving "_CLY_" flag to the function
validateEvent(eventsInRequest.get(1), eKeys[1], null, 1, 45.9, 32.0, "_CLY_", null, "", eventsInRequest.get(0).id);
}

/**
Expand All @@ -98,7 +101,7 @@ public void recordEvent_queueSizeOverMemory() throws IOException {
List<EventImpl> eventsInRequest = TestUtils.readEventsFromRequest();
validateEvent(eventsInRequest.get(0), "test-joinEvents-1", null, 5, null, null);
validateEvent(eventsInRequest.get(1), "test-joinEvents-2", null, 1, null, null);
validateEvent(eventsInRequest.get(2), eKeys[0], null, 1, 45.9, 32.0);
validateEvent(eventsInRequest.get(2), eKeys[0], null, 1, 45.9, 32.0, "_CLY_", null, "", null);
}

/**
Expand Down Expand Up @@ -168,7 +171,7 @@ public void recordEvent_invalidSegment() {
//record event with key segmentation
Countly.instance().events().recordEvent(eKeys[0], segmentation);

TestUtils.validateEventInEQ(eKeys[0], expectedSegmentation, 1, null, null, 0, 1);
TestUtils.validateEventInEQ(eKeys[0], expectedSegmentation, 1, null, null, 0, 1, "_CLY_", null, "", null);
}

/**
Expand All @@ -191,7 +194,7 @@ public void startEvent() {
endEvent(eKeys[0], null, 1, null);

Assert.assertEquals(0, moduleEvents.timedEvents.size());
TestUtils.validateEventInEQ(eKeys[0], null, 1, null, 0.0, 0, 1);
TestUtils.validateEventInEQ(eKeys[0], null, 1, null, 0.0, 0, 1, "_CLY_", null, "", null);
}

/**
Expand Down Expand Up @@ -248,7 +251,7 @@ public void startEvent_alreadyStarted() {
endEvent(eKeys[0], null, 1, null);

Assert.assertEquals(0, moduleEvents.timedEvents.size());
TestUtils.validateEventInEQ(eKeys[0], null, 1, null, 0.0, 0, 1);
TestUtils.validateEventInEQ(eKeys[0], null, 1, null, 0.0, 0, 1, "_CLY_", null, "", null);
}

/**
Expand Down Expand Up @@ -313,12 +316,13 @@ public void endEvent_withSegmentation() {
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("hair_color", "red");
segmentation.put("hair_length", "short");
segmentation.put("chauffeur", "g3chauffeur"); //
segmentation.put("chauffeur", "g3chauffeur");

endEvent(eKeys[0], segmentation, 1, 5.0);

Assert.assertEquals(0, moduleEvents.timedEvents.size());
TestUtils.validateEventInEQ(eKeys[0], segmentation, 1, 5.0, 0.0, 0, 1);
// check event has desired segmentation, no peid and a sdk generated id by giving "_CLY_" flag to the function
TestUtils.validateEventInEQ(eKeys[0], segmentation, 1, 5.0, 0.0, 0, 1, "_CLY_", null, "", null);
}

/**
Expand Down Expand Up @@ -414,7 +418,9 @@ public void cancelEvent() {

@Test
public void timedEventFlow() throws InterruptedException {
init(TestUtils.getConfigEvents(4));
InternalConfig config = new InternalConfig(TestUtils.getConfigEvents(4));
config.eventIdGenerator = TestUtils.idGenerator();
init(config);
validateTimedEventSize(0, 0);

startEvent(eKeys[0]); // start event to end it
Expand All @@ -428,12 +434,12 @@ public void timedEventFlow() throws InterruptedException {
endEvent(eKeys[1], null, 3, 15.0);

Assert.assertEquals(1, moduleEvents.timedEvents.size());
TestUtils.validateEventInEQ(eKeys[1], null, 3, 15.0, 1.0, 0, 1);
TestUtils.validateEventInEQ(eKeys[1], null, 3, 15.0, 1.0, 0, 1, TestUtils.keysValues[0], null, "", null);

endEvent(eKeys[0], null, 2, 4.0);

Assert.assertEquals(0, moduleEvents.timedEvents.size());
TestUtils.validateEventInEQ(eKeys[0], null, 2, 4.0, 2.0, 1, 2);
TestUtils.validateEventInEQ(eKeys[0], null, 2, 4.0, 2.0, 1, 2, TestUtils.keysValues[1], null, "", TestUtils.keysValues[0]);
}

private void validateTimedEventSize(int expectedQueueSize, int expectedTimedEventSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ private Map<String, Object> requiredWidgetSegmentation(String widgetId, Map<Stri
}

void feedbackValidateManualResultEQ(String eventKey, String widgetID, Map<String, Object> feedbackWidgetResult, int eqIndex) {
validateEvent(TestUtils.getCurrentEQ().get(eqIndex), eventKey, requiredWidgetSegmentation(widgetID, feedbackWidgetResult), 1, null, null);
validateEvent(TestUtils.getCurrentEQ().get(eqIndex), eventKey, requiredWidgetSegmentation(widgetID, feedbackWidgetResult), 1, null, null, "_CLY_", null, "", null);
}

void feedbackValidateManualResultRQ(String eventKey, String widgetID, Map<String, Object> feedbackWidgetResult, int eqIndex) {
validateEvent(TestUtils.readEventsFromRequest().get(eqIndex), eventKey, requiredWidgetSegmentation(widgetID, feedbackWidgetResult), 1, null, null);
validateEvent(TestUtils.readEventsFromRequest().get(eqIndex), eventKey, requiredWidgetSegmentation(widgetID, feedbackWidgetResult), 1, null, null, "_CLY_", null, "", null);
}
}
Loading

0 comments on commit 18035e9

Please sign in to comment.