Skip to content
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

propagate errors during async refresh #637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -244,8 +244,8 @@ public void triggerRefresh() {
* <p>
* This is an asynchronous call.
*/
public void triggerAsyncRefresh() {
triggerAsyncRefreshWithDelay(0);
public CompletableFuture<Void> triggerAsyncRefresh() {
return triggerAsyncRefreshWithDelay(0);
}

/**
Expand All @@ -256,10 +256,10 @@ public void triggerAsyncRefresh() {
*
* @param delayMillis the delay, in millseconds, before triggering the refresh
*/
public void triggerAsyncRefreshWithDelay(int delayMillis) {
public CompletableFuture<Void> triggerAsyncRefreshWithDelay(int delayMillis) {
final long targetBeginTime = System.currentTimeMillis() + delayMillis;

refreshExecutor.execute(() -> {
return CompletableFuture.runAsync(() -> {
try {
long delay = targetBeginTime - System.currentTimeMillis();
if (delay > 0)
Expand All @@ -278,7 +278,7 @@ public void triggerAsyncRefreshWithDelay(int delayMillis) {
LOG.log(Level.SEVERE, "Async refresh failed", e);
throw e;
}
});
}, refreshExecutor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.netflix.hollow.tools.compact.HollowCompactor.CompactionConfig;
import java.time.Duration;
import java.util.BitSet;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -487,6 +488,28 @@ public void consumerFilteringSupport() {
Assert.fail(); // fail if UnsupportedOperationException was not thrown
}

@Test
public void consumerErrorsDuringRefreshArePropagated() {
HollowProducer producer = HollowProducer.withPublisher(blobStore)
.withAnnouncer(announcement)
.withBlobStager(new HollowInMemoryBlobStager())
.build();
long v1 = runCycle(producer, 1);

InMemoryBlobStore otherBlobStore = new InMemoryBlobStore();
HollowConsumer consumer = HollowConsumer.withBlobRetriever(otherBlobStore)
.withAnnouncementWatcher(announcement)
.build();

try {
consumer.triggerAsyncRefresh().toCompletableFuture().join();
Assert.fail("Expected exception to be thrown by async refresh.");
} catch (Exception e) {
Assert.assertTrue(e instanceof CompletionException);
Assert.assertTrue(e.getCause() instanceof IllegalArgumentException);
}
}

private long runCycle(HollowProducer producer, final int cycleNumber) {
return producer.runCycle(state -> state.add(cycleNumber));
}
Expand Down