@Test(expected = CachingResolver.StaleResolverException.class) public void getTuplesExceptionalTest() throws Exception { final CompletableFuture<Collection<ResolverTuple>> fut = new CompletableFuture<>(); final List<ResolverTuple> RESULT = new ArrayList<>(); when(mockedAsyncResolver.getTuples()).thenReturn((CompletableFuture) fut); try (CachingResolver cr = new CachingResolver(mockedAsyncResolver, Duration.standardMinutes(10), Duration.standardMinutes(60))) { fut.completeExceptionally(new TestException()); cr.getTuples(); } }
@Override public synchronized Collection<ResolverTuple> getTuples() throws Exception { if (closed) throw new IllegalStateException("resolver is closed"); final Refresh refresh = getRefresh(); Collection<ResolverTuple> result; switch (refresh) { case REUSE: case MAY_REFRESH: result = tuples; break; case MUST_REFRESH: if (exception == null) throw new StaleResolverException(); else throw new StaleResolverException(exception); default: assert(false); throw new IllegalStateException("unreachable statement"); } return result; }
CachingResolver implements Resolver { @Override public synchronized Collection<ResolverTuple> getTuples() throws Exception { if (closed) throw new IllegalStateException("resolver is closed"); final Refresh refresh = getRefresh(); Collection<ResolverTuple> result; switch (refresh) { case REUSE: case MAY_REFRESH: result = tuples; break; case MUST_REFRESH: if (exception == null) throw new StaleResolverException(); else throw new StaleResolverException(exception); default: assert(false); throw new IllegalStateException("unreachable statement"); } return result; } }
CachingResolver implements Resolver { @Override public synchronized Collection<ResolverTuple> getTuples() throws Exception { if (closed) throw new IllegalStateException("resolver is closed"); final Refresh refresh = getRefresh(); Collection<ResolverTuple> result; switch (refresh) { case REUSE: case MAY_REFRESH: result = tuples; break; case MUST_REFRESH: if (exception == null) throw new StaleResolverException(); else throw new StaleResolverException(exception); default: assert(false); throw new IllegalStateException("unreachable statement"); } return result; } CachingResolver(@NonNull AsyncResolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge);  CachingResolver(@NonNull Resolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge); }
CachingResolver implements Resolver { @Override public synchronized Collection<ResolverTuple> getTuples() throws Exception { if (closed) throw new IllegalStateException("resolver is closed"); final Refresh refresh = getRefresh(); Collection<ResolverTuple> result; switch (refresh) { case REUSE: case MAY_REFRESH: result = tuples; break; case MUST_REFRESH: if (exception == null) throw new StaleResolverException(); else throw new StaleResolverException(exception); default: assert(false); throw new IllegalStateException("unreachable statement"); } return result; } CachingResolver(@NonNull AsyncResolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge);  CachingResolver(@NonNull Resolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge); @Override int getTupleWidth(); @Override synchronized Collection<ResolverTuple> getTuples(); @Override String configString(); @Override synchronized void close(); }
CachingResolver implements Resolver { @Override public synchronized Collection<ResolverTuple> getTuples() throws Exception { if (closed) throw new IllegalStateException("resolver is closed"); final Refresh refresh = getRefresh(); Collection<ResolverTuple> result; switch (refresh) { case REUSE: case MAY_REFRESH: result = tuples; break; case MUST_REFRESH: if (exception == null) throw new StaleResolverException(); else throw new StaleResolverException(exception); default: assert(false); throw new IllegalStateException("unreachable statement"); } return result; } CachingResolver(@NonNull AsyncResolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge);  CachingResolver(@NonNull Resolver underlying, @NonNull Duration minAge, @NonNull Duration maxAge); @Override int getTupleWidth(); @Override synchronized Collection<ResolverTuple> getTuples(); @Override String configString(); @Override synchronized void close();  }