Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
gal-leib committed Aug 21, 2024
1 parent 12426c0 commit 29f2c10
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class InstrumentedExecutorServiceTest {

Expand Down Expand Up @@ -167,6 +169,32 @@ public void reportsTasksInformationForThreadPoolExecutor() throws Exception {
assertThat(poolSize.getValue()).isEqualTo(1);
}

@Test
public void reportsRejectedTasksForThreadPoolExecutor() throws Exception {
executor = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1));
instrumentedExecutorService = new InstrumentedExecutorService(executor, registry, "tp");
final Counter rejected = registry.counter("tp.rejected");
assertThat(rejected.getCount()).isEqualTo(0);

final CountDownLatch latch = new CountDownLatch(1);

Runnable runnable = () -> {
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
};

Future<?> executingFuture = instrumentedExecutorService.submit(runnable);
Future<?> queuedFuture = instrumentedExecutorService.submit(runnable);
assertThatThrownBy(() -> instrumentedExecutorService.submit(runnable))
.isInstanceOf(RejectedExecutionException.class);
latch.countDown();
assertThat(rejected.getCount()).isEqualTo(1);
}

@Test
@SuppressWarnings("unchecked")
public void reportsTasksInformationForForkJoinPool() throws Exception {
Expand Down

0 comments on commit 29f2c10

Please sign in to comment.