@Test public void transportProblemAsync() throws InterruptedException { Retrofit retrofit = new Retrofit.Builder() .baseUrl(mServer.url("/")) .addConverterFactory(new ToStringConverterFactory()) .addCallAdapterFactory(buildSmartCacheFactory()) .build(); Service example = retrofit.create(Service.class); mServer.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START)); final AtomicReference<Throwable> failureRef = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); example.getString().enqueue(new Callback<String>() { @Override public void onResponse(Call<String> call, Response<String> response) { throw new AssertionError(); } @Override public void onFailure(Call<String> call, Throwable t) { failureRef.set(t); latch.countDown(); } }); assertTrue(latch.await(10, SECONDS)); Throwable failure = failureRef.get(); assertThat(failure).isInstanceOf(IOException.class); }
@Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); }
CachedCall implements Cached<T> { @Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); } }
CachedCall implements Cached<T> { @Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); } CachedCall(Executor executor, Call<T> call, Type responseType, Annotation[] annotations, Retrofit retrofit, Cache<String, byte[]> cachingSystem); }
CachedCall implements Cached<T> { @Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); } CachedCall(Executor executor, Call<T> call, Type responseType, Annotation[] annotations, Retrofit retrofit, Cache<String, byte[]> cachingSystem); @Override void enqueue(final Callback<T> callback); @Override void refresh(final Callback<T> callback); @Override Type responseType(); @Override Request request(); @Override Cached<T> clone(); @Override Response<T> execute(); @Override void remove(); @Override void cancel(); @Override boolean isCanceled(); @Override boolean isExecuted(); }
CachedCall implements Cached<T> { @Override public void enqueue(final Callback<T> callback) { if (callback == null) { throw new NullPointerException("callback == null"); } if (mExecuted || mCall.isExecuted()) { throw new IllegalStateException("Already executed."); } mExecuted = true; if (mCachingActive) { new Thread(new Runnable() { @Override public void run() { if (!cacheLoad(callback)) { networkLoad(callback, false); } } }).start(); return; } delegate(callback); } CachedCall(Executor executor, Call<T> call, Type responseType, Annotation[] annotations, Retrofit retrofit, Cache<String, byte[]> cachingSystem); @Override void enqueue(final Callback<T> callback); @Override void refresh(final Callback<T> callback); @Override Type responseType(); @Override Request request(); @Override Cached<T> clone(); @Override Response<T> execute(); @Override void remove(); @Override void cancel(); @Override boolean isCanceled(); @Override boolean isExecuted();  }