Skip to content

Commit c3e55ce

Browse files
author
Mike Davis
authored
Require EventHandler in the BatchEventProcessor. (#333)
1 parent 444eac6 commit c3e55ce

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

core-api/src/main/java/com/optimizely/ab/event/BatchEventProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ public BatchEventProcessor build(boolean shouldStart) {
313313
timeoutMillis = DEFAULT_TIMEOUT_INTERVAL;
314314
}
315315

316+
if (eventHandler == null) {
317+
throw new IllegalArgumentException("EventHandler was not configured");
318+
}
319+
316320
if (executor == null) {
317321
final ThreadFactory threadFactory = Executors.defaultThreadFactory();
318322
executor = Executors.newSingleThreadExecutor(runnable -> {

core-api/src/test/java/com/optimizely/ab/event/BatchEventProcessorTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public void setUp() throws Exception {
6767

6868
@After
6969
public void tearDown() throws Exception {
70-
eventProcessor.close();
70+
if (eventProcessor != null) {
71+
eventProcessor.close();
72+
}
7173
}
7274

7375
@Test
@@ -288,6 +290,11 @@ public void testInvalidTimeoutUsesDefault() {
288290
assertEquals(eventProcessor.timeoutMillis, BatchEventProcessor.DEFAULT_TIMEOUT_INTERVAL);
289291
}
290292

293+
@Test(expected = IllegalArgumentException.class)
294+
public void testDefaultEventHandler() {
295+
eventProcessor = BatchEventProcessor.builder().build();
296+
}
297+
291298
private void setEventProcessor(EventHandler eventHandler) {
292299
eventProcessor = BatchEventProcessor.builder()
293300
.withEventQueue(eventQueue)

core-httpclient-impl/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ compile 'com.optimizely.ab:core-httpclient-impl:{VERSION}'
2424

2525
## Basic usage
2626
```java
27+
package com.optimizely;
28+
2729
import com.optimizely.ab.Optimizely;
2830
import com.optimizely.ab.OptimizelyFactory;
2931

@@ -38,9 +40,13 @@ public class App {
3840

3941
## Advanced usage
4042
```java
43+
package com.optimizely;
44+
4145
import com.optimizely.ab.Optimizely;
46+
import com.optimizely.ab.config.ProjectConfigManager;
4247
import com.optimizely.ab.config.HttpProjectConfigManager;
4348
import com.optimizely.ab.event.AsyncEventHandler;
49+
import com.optimizely.ab.event.EventHandler;
4450
import java.util.concurrent.TimeUnit;
4551

4652
public class App {
@@ -54,12 +60,12 @@ public class App {
5460

5561
ProjectConfigManager projectConfigManager = HttpProjectConfigManager.builder()
5662
.withSdkKey(sdkKey)
57-
.withPollingInterval(1, TimeUnit.MINUTES)
63+
.withPollingInterval(1L, TimeUnit.MINUTES)
5864
.build();
5965

6066
Optimizely optimizely = Optimizely.builder()
61-
.withConfig(projectConfigManager)
6267
.withEventHandler(eventHandler)
68+
.withConfigManager(projectConfigManager)
6369
.build();
6470
}
6571
}

0 commit comments

Comments
 (0)