From 28118ce2e51b69bfa70ab7f875254ef3001c2e00 Mon Sep 17 00:00:00 2001 From: mnoman09 Date: Mon, 9 Jan 2023 21:46:08 +0500 Subject: [PATCH] removed setting up batchSize and it will set it to 1 when you set flushInterval to 0 --- .../optimizely/ab/odp/ODPEventManager.java | 8 +++---- .../ab/odp/ODPEventManagerTest.java | 22 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java b/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java index ae034fd68..a0129f925 100644 --- a/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java +++ b/core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java @@ -1,6 +1,6 @@ /** * - * Copyright 2022, Optimizely + * Copyright 2022-2023, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,14 +53,14 @@ public class ODPEventManager { private final BlockingQueue eventQueue = new LinkedBlockingQueue<>(); public ODPEventManager(@Nonnull ODPApiManager apiManager) { - this(apiManager, null, null, null); + this(apiManager, null, null); } - public ODPEventManager(@Nonnull ODPApiManager apiManager, @Nullable Integer batchSize, @Nullable Integer queueSize, @Nullable Integer flushInterval) { + public ODPEventManager(@Nonnull ODPApiManager apiManager, @Nullable Integer queueSize, @Nullable Integer flushInterval) { this.apiManager = apiManager; - this.batchSize = (batchSize != null && batchSize > 1) ? batchSize : DEFAULT_BATCH_SIZE; this.queueSize = queueSize != null ? queueSize : DEFAULT_QUEUE_SIZE; this.flushInterval = (flushInterval != null && flushInterval > 0) ? flushInterval : DEFAULT_FLUSH_INTERVAL; + this.batchSize = (flushInterval != null && flushInterval == 0) ? 1 : DEFAULT_BATCH_SIZE; } public void start() { diff --git a/core-api/src/test/java/com/optimizely/ab/odp/ODPEventManagerTest.java b/core-api/src/test/java/com/optimizely/ab/odp/ODPEventManagerTest.java index 17c489dd4..ff970c846 100644 --- a/core-api/src/test/java/com/optimizely/ab/odp/ODPEventManagerTest.java +++ b/core-api/src/test/java/com/optimizely/ab/odp/ODPEventManagerTest.java @@ -96,23 +96,23 @@ public void dispatchEventsInCorrectNumberOfBatches() throws InterruptedException public void dispatchEventsWithCorrectPayload() throws InterruptedException { Mockito.reset(mockApiManager); Mockito.when(mockApiManager.sendEvents(any(), any(), any())).thenReturn(202); - int batchSize = 2; + int flushInterval = 0; ODPConfig odpConfig = new ODPConfig("key", "http://www.odp-host.com", null); - ODPEventManager eventManager = new ODPEventManager(mockApiManager, batchSize, null, null); + ODPEventManager eventManager = new ODPEventManager(mockApiManager, null, flushInterval); eventManager.updateSettings(odpConfig); eventManager.start(); for (int i = 0; i < 6; i++) { eventManager.sendEvent(getEvent(i)); } Thread.sleep(500); - Mockito.verify(mockApiManager, times(3)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture()); + Mockito.verify(mockApiManager, times(6)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture()); List payloads = payloadCaptor.getAllValues(); for (int i = 0; i < payloads.size(); i++) { JSONArray events = new JSONArray(payloads.get(i)); - assertEquals(batchSize, events.length()); + assertEquals(1, events.length()); for (int j = 0; j < events.length(); j++) { - int id = (batchSize * i) + j; + int id = (1 * i) + j; JSONObject event = events.getJSONObject(j); assertEquals("test-type-" + id , event.getString("type")); assertEquals("test-action-" + id , event.getString("action")); @@ -186,9 +186,9 @@ public void shouldFlushAllScheduledEventsBeforeStopping() throws InterruptedExce public void prepareCorrectPayloadForIdentifyUser() throws InterruptedException { Mockito.reset(mockApiManager); Mockito.when(mockApiManager.sendEvents(any(), any(), any())).thenReturn(202); - int batchSize = 2; + int flushInterval = 0; ODPConfig odpConfig = new ODPConfig("key", "http://www.odp-host.com", null); - ODPEventManager eventManager = new ODPEventManager(mockApiManager, batchSize, null, null); + ODPEventManager eventManager = new ODPEventManager(mockApiManager, null, flushInterval); eventManager.updateSettings(odpConfig); eventManager.start(); for (int i = 0; i < 2; i++) { @@ -196,17 +196,17 @@ public void prepareCorrectPayloadForIdentifyUser() throws InterruptedException { } Thread.sleep(1500); - Mockito.verify(mockApiManager, times(1)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture()); + Mockito.verify(mockApiManager, times(2)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture()); String payload = payloadCaptor.getValue(); JSONArray events = new JSONArray(payload); - assertEquals(batchSize, events.length()); + assertEquals(1, events.length()); for (int i = 0; i < events.length(); i++) { JSONObject event = events.getJSONObject(i); assertEquals("fullstack", event.getString("type")); assertEquals("identified", event.getString("action")); - assertEquals("the-vuid-" + i, event.getJSONObject("identifiers").getString("vuid")); - assertEquals("the-fs-user-id-" + i, event.getJSONObject("identifiers").getString("fs_user_id")); + assertEquals("the-vuid-" + (i + 1), event.getJSONObject("identifiers").getString("vuid")); + assertEquals("the-fs-user-id-" + (i + 1), event.getJSONObject("identifiers").getString("fs_user_id")); assertEquals("sdk", event.getJSONObject("data").getString("data_source_type")); } }