@Test public void doNotRetryWhenResponseIsCancelled() throws Exception { final HelloService.Iface client = new ClientBuilder(server.uri(BINARY, "/thrift")) .rpcDecorator(new RetryingRpcClientBuilder(retryAlways).newDecorator()) .rpcDecorator((delegate, ctx, req) -> { final RpcResponse res = delegate.execute(ctx, req); res.cancel(true); return res; }) .build(HelloService.Iface.class); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); assertThatThrownBy(() -> client.hello("hello")).isInstanceOf(CancellationException.class); await().untilAsserted(() -> verify(serviceHandler, only()).hello("hello")); // Sleep 1 second more to check if there was another retry. TimeUnit.SECONDS.sleep(1); verify(serviceHandler, only()).hello("hello"); } }