Skip to content

refact(odp): Removes support for odp batchSize. #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -53,14 +53,14 @@ public class ODPEventManager {
private final BlockingQueue<Object> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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"));
Expand Down Expand Up @@ -186,27 +186,27 @@ 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++) {
eventManager.identifyUser("the-vuid-" + i, "the-fs-user-id-" + i);
}

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"));
}
}
Expand Down