Skip to content

Commit

Permalink
Add test for ensuring that runtime exceptions are tolerated
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Dec 16, 2024
1 parent 6dd3402 commit 6e9cecd
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,27 @@ public void shouldTolerateAlreadyClosedExceptionInClose() {
() -> (Producer<Object>) producer);
cache.close();
}

@Test
public void shouldTolerateRuntimeExceptionInClose() {
ProducerCache cache = new ProducerCache();
Producer producer = mock(Producer.class);
when(producer.flushAsync()).thenReturn(CompletableFuture.completedFuture(null));
when(producer.closeAsync()).thenThrow(new RuntimeException("Some exception"));
cache.getOrCreateProducer(ProducerCache.CacheArea.CONTEXT_CACHE, "topic", "key",
() -> (Producer<Object>) producer);
cache.close();
}

@Test
public void shouldTolerateRuntimeExceptionInFlush() {
ProducerCache cache = new ProducerCache();
Producer producer = mock(Producer.class);
when(producer.flushAsync()).thenThrow(new RuntimeException("Some exception"));
when(producer.closeAsync()).thenReturn(CompletableFuture.completedFuture(null));
cache.getOrCreateProducer(ProducerCache.CacheArea.CONTEXT_CACHE, "topic", "key",
() -> (Producer<Object>) producer);
cache.close();
}

}

0 comments on commit 6e9cecd

Please sign in to comment.