Skip to content

Require EventHandler in the BatchEventProcessor. #333

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 2 commits into from
Aug 28, 2019
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
Expand Up @@ -313,6 +313,10 @@ public BatchEventProcessor build(boolean shouldStart) {
timeoutMillis = DEFAULT_TIMEOUT_INTERVAL;
}

if (eventHandler == null) {
throw new IllegalArgumentException("EventHandler was not configured");
}

if (executor == null) {
final ThreadFactory threadFactory = Executors.defaultThreadFactory();
executor = Executors.newSingleThreadExecutor(runnable -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
eventProcessor.close();
if (eventProcessor != null) {
eventProcessor.close();
}
}

@Test
Expand Down Expand Up @@ -288,6 +290,11 @@ public void testInvalidTimeoutUsesDefault() {
assertEquals(eventProcessor.timeoutMillis, BatchEventProcessor.DEFAULT_TIMEOUT_INTERVAL);
}

@Test(expected = IllegalArgumentException.class)
public void testDefaultEventHandler() {
eventProcessor = BatchEventProcessor.builder().build();
}

private void setEventProcessor(EventHandler eventHandler) {
eventProcessor = BatchEventProcessor.builder()
.withEventQueue(eventQueue)
Expand Down
10 changes: 8 additions & 2 deletions core-httpclient-impl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ compile 'com.optimizely.ab:core-httpclient-impl:{VERSION}'

## Basic usage
```java
package com.optimizely;

import com.optimizely.ab.Optimizely;
import com.optimizely.ab.OptimizelyFactory;

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

## Advanced usage
```java
package com.optimizely;

import com.optimizely.ab.Optimizely;
import com.optimizely.ab.config.ProjectConfigManager;
import com.optimizely.ab.config.HttpProjectConfigManager;
import com.optimizely.ab.event.AsyncEventHandler;
import com.optimizely.ab.event.EventHandler;
import java.util.concurrent.TimeUnit;

public class App {
Expand All @@ -54,12 +60,12 @@ public class App {

ProjectConfigManager projectConfigManager = HttpProjectConfigManager.builder()
.withSdkKey(sdkKey)
.withPollingInterval(1, TimeUnit.MINUTES)
.withPollingInterval(1L, TimeUnit.MINUTES)
.build();

Optimizely optimizely = Optimizely.builder()
.withConfig(projectConfigManager)
.withEventHandler(eventHandler)
.withConfigManager(projectConfigManager)
.build();
}
}
Expand Down