@Test public void testExecutorCorruptionDetection() throws Exception { AtomicBoolean reject = new AtomicBoolean(); Executor executor = command -> { if (reject.get()) { throw new RejectedExecutionException(); } executorService.execute(command); }; BoundedExecutor boundedExecutor = new BoundedExecutor(executor, 1); // Enforce single thread // Force the underlying executor to fail reject.set(true); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should fail"); } catch (Exception e) { } // Recover the underlying executor, but all new tasks should fail reject.set(false); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should still fail"); } catch (Exception e) { } }
@Test public void testExecutorCorruptionDetection() throws Exception { AtomicBoolean reject = new AtomicBoolean(); Executor executor = command -> { if (reject.get()) { throw new RejectedExecutionException(); } executorService.execute(command); }; BoundedExecutor boundedExecutor = new BoundedExecutor(executor, 1); // Enforce single thread // Force the underlying executor to fail reject.set(true); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should fail"); } catch (Exception e) { } // Recover the underlying executor, but all new tasks should fail reject.set(false); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should still fail"); } catch (Exception e) { } }
@Test public void testExecutorCorruptionDetection() throws Exception { AtomicBoolean reject = new AtomicBoolean(); Executor executor = command -> { if (reject.get()) { throw new RejectedExecutionException(); } executorService.execute(command); }; BoundedExecutor boundedExecutor = new BoundedExecutor(executor, 1); // Enforce single thread // Force the underlying executor to fail reject.set(true); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should fail"); } catch (Exception e) { } // Recover the underlying executor, but all new tasks should fail reject.set(false); try { boundedExecutor.execute(() -> fail("Should not be run")); fail("Execute should still fail"); } catch (Exception e) { } }