@Test public void afterTerminateCallbackErrorAndErrorCallbackError2() { IllegalStateException afterTerminate = new IllegalStateException("afterTerminate"); IllegalArgumentException error = new IllegalArgumentException("error"); NullPointerException err = new NullPointerException(); FluxPeek<String> flux = new FluxPeek<>(Flux.error(err), null, null, e -> { throw error; }, null, () -> { throw afterTerminate; }, null, null); AssertSubscriber<String> ts = AssertSubscriber.create(); try { flux.subscribe(ts); fail("expected thrown exception"); } catch (Exception e) { assertSame(afterTerminate, e.getCause()); //afterTerminate suppressed error which itself suppressed original err assertEquals(1, afterTerminate.getSuppressed().length); assertEquals(error, afterTerminate.getSuppressed()[0]); assertEquals(1, error.getSuppressed().length); assertEquals(err, error.getSuppressed()[0]); } ts.assertNoValues(); //the subscriber still sees the 'error' message since actual.onError is called before the afterTerminate callback ts.assertErrorMessage("error"); }
@Test public void afterTerminateCallbackErrorAndErrorCallbackError2() { IllegalStateException afterTerminate = new IllegalStateException("afterTerminate"); IllegalArgumentException error = new IllegalArgumentException("error"); NullPointerException err = new NullPointerException(); FluxPeekFuseable<String> flux = new FluxPeekFuseable<>( Flux.error(err), null, null, e -> { throw error; }, null, () -> { throw afterTerminate; }, null, null); AssertSubscriber<String> ts = AssertSubscriber.create(); try { flux.subscribe(ts); fail("expected thrown exception"); } catch (Exception e) { assertSame(afterTerminate, e.getCause()); //afterTerminate suppressed error which itself suppressed original err assertEquals(1, afterTerminate.getSuppressed().length); assertEquals(error, afterTerminate.getSuppressed()[0]); assertEquals(1, error.getSuppressed().length); assertEquals(err, error.getSuppressed()[0]); } ts.assertNoValues(); //the subscriber still sees the 'error' message since actual.onError is called before the afterTerminate callback ts.assertErrorMessage("error"); }
void stop(@Observes final BeforeShutdown beforeShutdown) { final IllegalStateException ise = new IllegalStateException("Something went wrong releasing health checks"); contexts.forEach(c -> { try { c.release(); } catch (final RuntimeException re) { ise.addSuppressed(re); } }); final Throwable[] suppressed = ise.getSuppressed(); if (suppressed.length == 1) { throw RuntimeException.class.cast(suppressed[0]); } else if (suppressed.length > 1) { throw ise; } }