@Test public void testRefreshAfterFailure() throws Exception { underTest = new OAuthCredentialsCache(executorService, mockCredentials); final AccessToken accessToken = new AccessToken("hi", new Date(HeaderCacheElement.TOKEN_STALENESS_MS + 1)); Mockito.when(mockCredentials.refreshAccessToken()) .thenThrow(new IOException()) .thenReturn(accessToken); OAuthCredentialsCache.HeaderToken token1 = underTest.getHeader(TIMEOUT_SECONDS, TimeUnit.SECONDS); Assert.assertFalse(token1.getStatus().isOk()); OAuthCredentialsCache.HeaderToken token2 = underTest.getHeader(TIMEOUT_SECONDS, TimeUnit.SECONDS); Assert.assertTrue(token2.getStatus().isOk()); Assert.assertThat(token2.getHeader(), containsString("hi")); Mockito.verify(mockCredentials, times(2)).refreshAccessToken(); }
HeaderToken getHeader(long timeout, TimeUnit timeUnit) { try { return getHeaderUnsafe(timeout, timeUnit).getToken(); } catch (Exception e) { LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e); Status status = Status.UNAUTHENTICATED.withDescription("Unexpected failure get auth token").withCause(e); return new HeaderToken(status, null); } }
OAuthCredentialsCache { HeaderToken getHeader(long timeout, TimeUnit timeUnit) { try { return getHeaderUnsafe(timeout, timeUnit).getToken(); } catch (Exception e) { LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e); Status status = Status.UNAUTHENTICATED.withDescription("Unexpected failure get auth token").withCause(e); return new HeaderToken(status, null); } } }
OAuthCredentialsCache { HeaderToken getHeader(long timeout, TimeUnit timeUnit) { try { return getHeaderUnsafe(timeout, timeUnit).getToken(); } catch (Exception e) { LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e); Status status = Status.UNAUTHENTICATED.withDescription("Unexpected failure get auth token").withCause(e); return new HeaderToken(status, null); } } OAuthCredentialsCache(ExecutorService scheduler, OAuth2Credentials credentials); }
OAuthCredentialsCache { HeaderToken getHeader(long timeout, TimeUnit timeUnit) { try { return getHeaderUnsafe(timeout, timeUnit).getToken(); } catch (Exception e) { LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e); Status status = Status.UNAUTHENTICATED.withDescription("Unexpected failure get auth token").withCause(e); return new HeaderToken(status, null); } } OAuthCredentialsCache(ExecutorService scheduler, OAuth2Credentials credentials);  }
OAuthCredentialsCache { HeaderToken getHeader(long timeout, TimeUnit timeUnit) { try { return getHeaderUnsafe(timeout, timeUnit).getToken(); } catch (Exception e) { LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e); Status status = Status.UNAUTHENTICATED.withDescription("Unexpected failure get auth token").withCause(e); return new HeaderToken(status, null); } } OAuthCredentialsCache(ExecutorService scheduler, OAuth2Credentials credentials);   }