CircuitBreakerDelegate implements CircuitBreaker<ET> { @Override public ManualModeTask<ET> newManualModeTask() { return new DelegateManualModeTask<>(delegate.newManualModeTask(), eventConverter, this); } CircuitBreakerDelegate(CircuitBreaker<Del_ET> delegate, Function<ET, Del_ET> eventConverter); @Override ManualModeTask<ET> newManualModeTask(); @Override CompletableFuture<ET> executeAsyncCall(Supplier<CompletableFuture<ET>> eventFutureSupplier); @Override ET executeBlockingCall(Callable<ET> eventSupplier); @Override CircuitBreakerDelegate<ET, Del_ET> onClose(Runnable listener); @Override CircuitBreakerDelegate<ET, Del_ET> onHalfOpen(Runnable listener); @Override CircuitBreakerDelegate<ET, Del_ET> onOpen(Runnable listener); @Override String getId();  }
@Test public void newManualModeTask_returns_instance_of_DelegateManualModeTask_with_correct_fields() { CircuitBreaker.ManualModeTask<Integer> manualTask = wrapper.newManualModeTask(); assertThat(manualTask).isInstanceOf(CircuitBreakerDelegate.DelegateManualModeTask.class); CircuitBreakerDelegate.DelegateManualModeTask dmmt = (CircuitBreakerDelegate.DelegateManualModeTask)manualTask; assertThat(dmmt.delegate).isSameAs(delegateManualModeTaskMock); assertThat(dmmt.eventConverter).isSameAs(wrapper.eventConverter); assertThat(dmmt.originatingCircuitBreaker).isSameAs(wrapper); assertThat(dmmt.originatingCircuitBreaker()).isSameAs(wrapper); }
@Test public void handleEvent_should_not_explode_if_eventConverter_explodes() { final Set<Boolean> explosionHappenedContainer = new HashSet<>(); Function<Integer, String> explodingEventConverter = theInt -> { explosionHappenedContainer.add(true); throw new RuntimeException("kaboom"); }; CircuitBreakerDelegate<Integer, String> badCb = new CircuitBreakerDelegate<>(delegateMock, explodingEventConverter); CircuitBreaker.ManualModeTask<Integer> badCbManualModeTask = badCb.newManualModeTask(); Throwable cbExplosion = catchThrowable(() -> badCbManualModeTask.handleEvent(42)); assertThat(explosionHappenedContainer).contains(true); verify(delegateManualModeTaskMock, times(0)).handleEvent(anyString()); assertThat(cbExplosion).isNull(); }