@Test public void clearCalls() throws InterruptedException { RetryableCalls retryableCalls = new RetryableCalls(); MockWebServer server = new MockWebServer(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(server.url("/")) .addCallAdapterFactory(retryableCalls.getFactory()) .addConverterFactory(new ToStringConverterFactory()) .build(); Service service = retrofit.create(Service.class); final AtomicInteger responseCount = new AtomicInteger(); final AtomicInteger failureCanRetryCount = new AtomicInteger(); final CountDownLatch responseLatch = new CountDownLatch(1); final CountDownLatch responseTwiceLatch = new CountDownLatch(2); final CountDownLatch failureCanRetryLatch = new CountDownLatch(1); server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START)); RetryableCall<String> call = service.getString(); call.enqueue(new RetryableCallback<String>() { @Override public void onResponse(RetryableCall<String> call, Response<String> response) { responseCount.incrementAndGet(); responseLatch.countDown(); responseTwiceLatch.countDown(); } @Override public void onFailure(RetryableCall<String> call, Throwable t) { throw new AssertionError(); } @Override public void onFailureButCanRetry(RetryableCall<String> call, IOException e) { failureCanRetryCount.incrementAndGet(); failureCanRetryLatch.countDown(); } }); assertThat(failureCanRetryLatch.await(10, SECONDS)).isTrue(); assertThat(failureCanRetryCount.get()).isEqualTo(1); assertThat(responseCount.get()).isEqualTo(0); server.enqueue(new MockResponse().setBody("Hi")); retryableCalls.clearCalls(); retryableCalls.retryAllCalls(); assertThat(responseTwiceLatch.await(10, SECONDS)).isFalse(); assertThat(failureCanRetryCount.get()).isEqualTo(1); assertThat(responseCount.get()).isEqualTo(0); }
public void clearCalls() { synchronized (lock) { failedCalls.clear(); } }
RetryableCalls { public void clearCalls() { synchronized (lock) { failedCalls.clear(); } } }
RetryableCalls { public void clearCalls() { synchronized (lock) { failedCalls.clear(); } }  }
RetryableCalls { public void clearCalls() { synchronized (lock) { failedCalls.clear(); } }  CallAdapter.Factory getFactory(); void retryAllCalls(); void clearCalls(); }
RetryableCalls { public void clearCalls() { synchronized (lock) { failedCalls.clear(); } }  CallAdapter.Factory getFactory(); void retryAllCalls(); void clearCalls();  }