Skip to content

Commit ac27ae7

Browse files
authored
removed setting up batchSize and it will set it to 1 when you set flushInterval to 0 (#500)
1 parent 3f7c53c commit ac27ae7

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

core-api/src/main/java/com/optimizely/ab/odp/ODPEventManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2022, Optimizely
3+
* Copyright 2022-2023, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -53,14 +53,14 @@ public class ODPEventManager {
5353
private final BlockingQueue<Object> eventQueue = new LinkedBlockingQueue<>();
5454

5555
public ODPEventManager(@Nonnull ODPApiManager apiManager) {
56-
this(apiManager, null, null, null);
56+
this(apiManager, null, null);
5757
}
5858

59-
public ODPEventManager(@Nonnull ODPApiManager apiManager, @Nullable Integer batchSize, @Nullable Integer queueSize, @Nullable Integer flushInterval) {
59+
public ODPEventManager(@Nonnull ODPApiManager apiManager, @Nullable Integer queueSize, @Nullable Integer flushInterval) {
6060
this.apiManager = apiManager;
61-
this.batchSize = (batchSize != null && batchSize > 1) ? batchSize : DEFAULT_BATCH_SIZE;
6261
this.queueSize = queueSize != null ? queueSize : DEFAULT_QUEUE_SIZE;
6362
this.flushInterval = (flushInterval != null && flushInterval > 0) ? flushInterval : DEFAULT_FLUSH_INTERVAL;
63+
this.batchSize = (flushInterval != null && flushInterval == 0) ? 1 : DEFAULT_BATCH_SIZE;
6464
}
6565

6666
public void start() {

core-api/src/test/java/com/optimizely/ab/odp/ODPEventManagerTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,23 @@ public void dispatchEventsInCorrectNumberOfBatches() throws InterruptedException
9696
public void dispatchEventsWithCorrectPayload() throws InterruptedException {
9797
Mockito.reset(mockApiManager);
9898
Mockito.when(mockApiManager.sendEvents(any(), any(), any())).thenReturn(202);
99-
int batchSize = 2;
99+
int flushInterval = 0;
100100
ODPConfig odpConfig = new ODPConfig("key", "http://www.odp-host.com", null);
101-
ODPEventManager eventManager = new ODPEventManager(mockApiManager, batchSize, null, null);
101+
ODPEventManager eventManager = new ODPEventManager(mockApiManager, null, flushInterval);
102102
eventManager.updateSettings(odpConfig);
103103
eventManager.start();
104104
for (int i = 0; i < 6; i++) {
105105
eventManager.sendEvent(getEvent(i));
106106
}
107107
Thread.sleep(500);
108-
Mockito.verify(mockApiManager, times(3)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture());
108+
Mockito.verify(mockApiManager, times(6)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture());
109109
List<String> payloads = payloadCaptor.getAllValues();
110110

111111
for (int i = 0; i < payloads.size(); i++) {
112112
JSONArray events = new JSONArray(payloads.get(i));
113-
assertEquals(batchSize, events.length());
113+
assertEquals(1, events.length());
114114
for (int j = 0; j < events.length(); j++) {
115-
int id = (batchSize * i) + j;
115+
int id = (1 * i) + j;
116116
JSONObject event = events.getJSONObject(j);
117117
assertEquals("test-type-" + id , event.getString("type"));
118118
assertEquals("test-action-" + id , event.getString("action"));
@@ -186,27 +186,27 @@ public void shouldFlushAllScheduledEventsBeforeStopping() throws InterruptedExce
186186
public void prepareCorrectPayloadForIdentifyUser() throws InterruptedException {
187187
Mockito.reset(mockApiManager);
188188
Mockito.when(mockApiManager.sendEvents(any(), any(), any())).thenReturn(202);
189-
int batchSize = 2;
189+
int flushInterval = 0;
190190
ODPConfig odpConfig = new ODPConfig("key", "http://www.odp-host.com", null);
191-
ODPEventManager eventManager = new ODPEventManager(mockApiManager, batchSize, null, null);
191+
ODPEventManager eventManager = new ODPEventManager(mockApiManager, null, flushInterval);
192192
eventManager.updateSettings(odpConfig);
193193
eventManager.start();
194194
for (int i = 0; i < 2; i++) {
195195
eventManager.identifyUser("the-vuid-" + i, "the-fs-user-id-" + i);
196196
}
197197

198198
Thread.sleep(1500);
199-
Mockito.verify(mockApiManager, times(1)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture());
199+
Mockito.verify(mockApiManager, times(2)).sendEvents(eq("key"), eq("http://www.odp-host.com/v3/events"), payloadCaptor.capture());
200200

201201
String payload = payloadCaptor.getValue();
202202
JSONArray events = new JSONArray(payload);
203-
assertEquals(batchSize, events.length());
203+
assertEquals(1, events.length());
204204
for (int i = 0; i < events.length(); i++) {
205205
JSONObject event = events.getJSONObject(i);
206206
assertEquals("fullstack", event.getString("type"));
207207
assertEquals("identified", event.getString("action"));
208-
assertEquals("the-vuid-" + i, event.getJSONObject("identifiers").getString("vuid"));
209-
assertEquals("the-fs-user-id-" + i, event.getJSONObject("identifiers").getString("fs_user_id"));
208+
assertEquals("the-vuid-" + (i + 1), event.getJSONObject("identifiers").getString("vuid"));
209+
assertEquals("the-fs-user-id-" + (i + 1), event.getJSONObject("identifiers").getString("fs_user_id"));
210210
assertEquals("sdk", event.getJSONObject("data").getString("data_source_type"));
211211
}
212212
}

0 commit comments

Comments
 (0)