Skip to content

Commit

Permalink
Fix NullPointerException when event buffer is full (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyway authored Apr 20, 2022
1 parent a2886cd commit 4e75a55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,31 @@ public void additionalHeadersIncludedInEventsRequest() throws IOException, Inter
}
}

@Test
public void testEventBufferFillsUp() throws IOException, InterruptedException {
try (MockWebServer mockEventsServer = new MockWebServer()) {
mockEventsServer.start();
// Enqueue a successful empty response
mockEventsServer.enqueue(new MockResponse());

LDConfig ldConfig = baseConfigBuilder(mockEventsServer)
.eventsCapacity(1)
.build();

// Don't wait as we are not set offline
try (LDClient client = LDClient.init(application, ldConfig, ldUser, 0)) {
client.identify(ldUser);
LDValue testData = LDValue.of("xyz");
client.trackData("test-event", testData);
client.blockingFlush();

// Verify that only the first event was sent and other events were dropped
Event[] events = getEventsFromLastRequest(mockEventsServer, 1);
assertTrue(events[0] instanceof IdentifyEvent);
}
}
}

private Event[] getEventsFromLastRequest(MockWebServer server, int expectedCount) throws InterruptedException {
RecordedRequest r = server.takeRequest();
assertEquals("POST", r.getMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ private void sendEvent(Event event) {
boolean processed = eventProcessor.sendEvent(event);
if (!processed) {
LDConfig.LOG.w("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
diagnosticStore.incrementDroppedEventCount();
if (diagnosticStore != null) {
diagnosticStore.incrementDroppedEventCount();
}
}
}
}
Expand Down

0 comments on commit 4e75a55

Please sign in to comment.