CircuitBreakerRpcClient extends AbstractCircuitBreakerClient<RpcRequest, RpcResponse> implements RpcClient { public static Function<? super RpcClient, CircuitBreakerRpcClient> newPerHostDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent) { return newDecorator(CircuitBreakerMapping.perHost(factory), ruleWithContent); } CircuitBreakerRpcClient(RpcClient delegate, CircuitBreakerMapping mapping,
                            CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static Function<? super RpcClient, CircuitBreakerRpcClient> newDecorator(CircuitBreaker circuitBreaker, CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static Function<? super RpcClient, CircuitBreakerRpcClient> newDecorator(CircuitBreakerMapping mapping, CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static Function<? super RpcClient, CircuitBreakerRpcClient> newPerMethodDecorator(Function<String, ? extends CircuitBreaker> factory,
                          CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static Function<? super RpcClient, CircuitBreakerRpcClient> newPerHostDecorator(Function<String, ? extends CircuitBreaker> factory,
                        CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static Function<? super RpcClient, CircuitBreakerRpcClient> newPerHostAndMethodDecorator(BiFunction<String, String, ? extends CircuitBreaker> factory,
                                 CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent); static CircuitBreakerRpcClientBuilder builder(
            CircuitBreakerRuleWithContent<RpcResponse> ruleWithContent);  }
@Test void testPerHostDecorator() { final CircuitBreaker circuitBreaker = mock(CircuitBreaker.class); when(circuitBreaker.canRequest()).thenReturn(false); @SuppressWarnings("unchecked") final Function<String, CircuitBreaker> factory = mock(Function.class); when(factory.apply(any())).thenReturn(circuitBreaker); final int COUNT = 2; failFastInvocation(CircuitBreakerRpcClient.newPerHostDecorator(factory, rule()), COUNT); verify(circuitBreaker, times(COUNT)).canRequest(); verify(factory, times(1)).apply("dummyhost:8080"); }