Skip to content

Commit

Permalink
feat: event queue size over test
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Sep 28, 2023
1 parent b26fb1c commit 0857eb3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void restoreFromDisk_corruptedData() throws IOException {
validateEvent(eventQueue.eventQueueMemoryCache.get(0), "test-joinEvents-1", null, 1, null, null);
}

private void writeToEventQueue(String fileContent, boolean delete) throws IOException {
static void writeToEventQueue(String fileContent, boolean delete) throws IOException {
File file = new File(TestUtils.getTestSDirectory(), FILE_NAME_PREFIX + FILE_NAME_SEPARATOR + EVENT_QUEUE_FILE_NAME);
file.createNewFile();
if (delete) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ly.count.sdk.java.internal;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,6 +59,43 @@ public void recordEvent() {
validateEventInQueue(TestUtils.getTestSDirectory(), eventKey, segmentation, 1, 45.9, 32.0, 1, 0);
}

/**
* Recording an event and no event to recover
* "recordEvent" function should create an event with given key
* event queue should be empty when reached to event queue size to send
*/
@Test
public void recordEvent_queueSizeOver() {
Config config = TestUtils.getBaseConfig();
config.enableFeatures(Config.Feature.Events).setEventQueueSizeToSend(2);
init(config);

validateQueueSize(0);

Countly.instance().events().recordEvent("recordEvent_queueSizeOver", 1, 45.9, null, 32.0);
validateQueueSize(1);

Countly.instance().events().recordEvent("recordEvent_queueSizeOver", 1, 45.9, null, 32.0);
validateQueueSize(0);
}

/**
* Recording an event with recovered events
* "recordEvent" function should create an event with given key and create a request with memory data
* event queue should be empty when reached to event queue size to send
*/
@Test
public void recordEvent_queueSizeOverMemory() throws IOException {
EventQueueTests.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);
Config config = TestUtils.getBaseConfig();
config.enableFeatures(Config.Feature.Events).setEventQueueSizeToSend(2);
init(config);

validateQueueSize(2);
Countly.instance().events().recordEvent("recordEvent_queueSizeOver", 1, 45.9, null, 32.0);
validateQueueSize(0);
}

/**
* Recording an event with negative count
* "recordEvent" function should not create an event with given key and negative count
Expand Down Expand Up @@ -368,6 +406,10 @@ private void validateQueueSize(int expectedSize, List<EventImpl> events) {
Assert.assertEquals(expectedSize, moduleEvents.eventQueue.eqSize());
}

private void validateQueueSize(int expectedSize) {
validateQueueSize(expectedSize, TestUtils.getCurrentEventQueue(moduleEvents.ctx.getContext(), moduleEvents.L));
}

private void endEvent(String key, Map<String, Object> segmentation, int count, Double sum) {
boolean result = Countly.instance().events().endEvent(key, segmentation, count, sum);
Assert.assertTrue(result);
Expand Down

0 comments on commit 0857eb3

Please sign in to comment.