@Test public void ignoresIfUnsuccessful() throws IOException { Response unsuccessful = response.newBuilder().code(500).build(); when(chain.proceed(request)).thenReturn(unsuccessful); assertThat(interceptor.intercept(chain)).isEqualTo(unsuccessful); verify(listener).onIgnore(); }
@Override public Response intercept(Chain chain) throws IOException { ConcurrencyLimiterListener limiterListenerTag = chain.request().tag(ConcurrencyLimiterListener.class); if (limiterListenerTag == null) { return chain.proceed(chain.request()); } ListenableFuture<Limiter.Listener> limiterFuture = limiterListenerTag.limiterListener(); Preconditions.checkState(limiterFuture.isDone(), "Limit listener future should have been fulfilled."); Limiter.Listener listener = Futures.getUnchecked(limiterFuture); try { Response response = chain.proceed(chain.request()); if (DROPPED_CODES.contains(response.code())) { listener.onDropped(); return response; } else if (!response.isSuccessful() || response.isRedirect()) { listener.onIgnore(); return response; } else { return wrapResponse(listener, response); } } catch (IOException e) { listener.onIgnore(); throw e; } }
ConcurrencyLimitingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { ConcurrencyLimiterListener limiterListenerTag = chain.request().tag(ConcurrencyLimiterListener.class); if (limiterListenerTag == null) { return chain.proceed(chain.request()); } ListenableFuture<Limiter.Listener> limiterFuture = limiterListenerTag.limiterListener(); Preconditions.checkState(limiterFuture.isDone(), "Limit listener future should have been fulfilled."); Limiter.Listener listener = Futures.getUnchecked(limiterFuture); try { Response response = chain.proceed(chain.request()); if (DROPPED_CODES.contains(response.code())) { listener.onDropped(); return response; } else if (!response.isSuccessful() || response.isRedirect()) { listener.onIgnore(); return response; } else { return wrapResponse(listener, response); } } catch (IOException e) { listener.onIgnore(); throw e; } } }
ConcurrencyLimitingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { ConcurrencyLimiterListener limiterListenerTag = chain.request().tag(ConcurrencyLimiterListener.class); if (limiterListenerTag == null) { return chain.proceed(chain.request()); } ListenableFuture<Limiter.Listener> limiterFuture = limiterListenerTag.limiterListener(); Preconditions.checkState(limiterFuture.isDone(), "Limit listener future should have been fulfilled."); Limiter.Listener listener = Futures.getUnchecked(limiterFuture); try { Response response = chain.proceed(chain.request()); if (DROPPED_CODES.contains(response.code())) { listener.onDropped(); return response; } else if (!response.isSuccessful() || response.isRedirect()) { listener.onIgnore(); return response; } else { return wrapResponse(listener, response); } } catch (IOException e) { listener.onIgnore(); throw e; } } ConcurrencyLimitingInterceptor(); }
ConcurrencyLimitingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { ConcurrencyLimiterListener limiterListenerTag = chain.request().tag(ConcurrencyLimiterListener.class); if (limiterListenerTag == null) { return chain.proceed(chain.request()); } ListenableFuture<Limiter.Listener> limiterFuture = limiterListenerTag.limiterListener(); Preconditions.checkState(limiterFuture.isDone(), "Limit listener future should have been fulfilled."); Limiter.Listener listener = Futures.getUnchecked(limiterFuture); try { Response response = chain.proceed(chain.request()); if (DROPPED_CODES.contains(response.code())) { listener.onDropped(); return response; } else if (!response.isSuccessful() || response.isRedirect()) { listener.onIgnore(); return response; } else { return wrapResponse(listener, response); } } catch (IOException e) { listener.onIgnore(); throw e; } } ConcurrencyLimitingInterceptor(); @Override Response intercept(Chain chain); }
ConcurrencyLimitingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { ConcurrencyLimiterListener limiterListenerTag = chain.request().tag(ConcurrencyLimiterListener.class); if (limiterListenerTag == null) { return chain.proceed(chain.request()); } ListenableFuture<Limiter.Listener> limiterFuture = limiterListenerTag.limiterListener(); Preconditions.checkState(limiterFuture.isDone(), "Limit listener future should have been fulfilled."); Limiter.Listener listener = Futures.getUnchecked(limiterFuture); try { Response response = chain.proceed(chain.request()); if (DROPPED_CODES.contains(response.code())) { listener.onDropped(); return response; } else if (!response.isSuccessful() || response.isRedirect()) { listener.onIgnore(); return response; } else { return wrapResponse(listener, response); } } catch (IOException e) { listener.onIgnore(); throw e; } } ConcurrencyLimitingInterceptor(); @Override Response intercept(Chain chain);  }