private SoftExpiringCache<String, String> makeSoftExpiringCache() { SoftExpiringCache<String, String> expiringCache = new SoftExpiringCache<String, String>(cache); expiringCache.setTimeSource(timeSource); return expiringCache; }
private SoftExpiringCache<String, String> makeSoftExpiringCache() { SoftExpiringCache<String, String> expiringCache = new SoftExpiringCache<String, String>(cache); expiringCache.setTimeSource(timeSource); return expiringCache; }
private SoftExpiringCache<String, String> makeSoftExpiringCache() { SoftExpiringCache<String, String> expiringCache = new SoftExpiringCache<String, String>(cache); expiringCache.setTimeSource(timeSource); return expiringCache; }
private SoftExpiringCache<String, String> makeSoftExpiringCache() { SoftExpiringCache<String, String> expiringCache = new SoftExpiringCache<String, String>(cache); expiringCache.setTimeSource(timeSource); return expiringCache; }
private SoftExpiringCache<String, String> makeSoftExpiringCache() { SoftExpiringCache<String, String> expiringCache = new SoftExpiringCache<String, String>(cache); expiringCache.setTimeSource(timeSource); return expiringCache; }
public FakeOAuthServiceProvider(TimeSource clock) { this.clock = clock; OAuthServiceProvider provider = new OAuthServiceProvider( REQUEST_TOKEN_URL, APPROVAL_URL, ACCESS_TOKEN_URL); signedFetchConsumer = new OAuthConsumer(null, null, null, null); signedFetchConsumer.setProperty(RSA_SHA1.X509_CERTIFICATE, CERTIFICATE_TEXT); oauthConsumer = new OAuthConsumer(null, CONSUMER_KEY, CONSUMER_SECRET, provider); tokenState = Maps.newHashMap(); validParamLocations = Sets.newHashSet(); validParamLocations.add(OAuthParamLocation.URI_QUERY); nonceCache = new SoftExpiringCache<String, OAuthMessage>(new LruCache<String, OAuthMessage>(10000)); nonceCache.setTimeSource(clock); }
public FakeOAuthServiceProvider(TimeSource clock) { this.clock = clock; OAuthServiceProvider provider = new OAuthServiceProvider( REQUEST_TOKEN_URL, APPROVAL_URL, ACCESS_TOKEN_URL); signedFetchConsumer = new OAuthConsumer(null, null, null, null); signedFetchConsumer.setProperty(RSA_SHA1.X509_CERTIFICATE, CERTIFICATE_TEXT); oauthConsumer = new OAuthConsumer(null, CONSUMER_KEY, CONSUMER_SECRET, provider); tokenState = Maps.newHashMap(); validParamLocations = Sets.newHashSet(); validParamLocations.add(OAuthParamLocation.URI_QUERY); nonceCache = new SoftExpiringCache<String, OAuthMessage>(new LruCache<String, OAuthMessage>(10000)); nonceCache.setTimeSource(clock); }
public FakeOAuthServiceProvider(TimeSource clock) { this.clock = clock; OAuthServiceProvider provider = new OAuthServiceProvider( REQUEST_TOKEN_URL, APPROVAL_URL, ACCESS_TOKEN_URL); signedFetchConsumer = new OAuthConsumer(null, null, null, null); signedFetchConsumer.setProperty(RSA_SHA1.X509_CERTIFICATE, CERTIFICATE_TEXT); oauthConsumer = new OAuthConsumer(null, CONSUMER_KEY, CONSUMER_SECRET, provider); tokenState = Maps.newHashMap(); validParamLocations = Sets.newHashSet(); validParamLocations.add(OAuthParamLocation.URI_QUERY); nonceCache = new SoftExpiringCache<String, OAuthMessage>(new LruCache<String, OAuthMessage>(10000)); nonceCache.setTimeSource(clock); }
@Test public void badResponseServedFromCache() throws Exception { HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(BASIC_BUNDLE.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(expiredResponse).once(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); final AtomicLong time = new AtomicLong(); bundleFactory.cache.setTimeSource(new TimeSource() { @Override public long currentTimeMillis() { return time.get(); } }); time.set(System.currentTimeMillis()); MessageBundle bundle0 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); time.set(time.get() + MAX_AGE + 1); MessageBundle bundle1 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); verify(pipeline); assertEquals(bundle0.getMessages().get(MSG_0_NAME), bundle1.getMessages().get(MSG_0_NAME)); }
@Test public void badResponseServedFromCache() throws Exception { HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(BASIC_BUNDLE.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(expiredResponse).once(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); final AtomicLong time = new AtomicLong(); bundleFactory.cache.setTimeSource(new TimeSource() { @Override public long currentTimeMillis() { return time.get(); } }); time.set(System.currentTimeMillis()); MessageBundle bundle0 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); time.set(time.get() + MAX_AGE + 1); MessageBundle bundle1 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER, null); verify(pipeline); assertEquals(bundle0.getMessages().get(MSG_0_NAME), bundle1.getMessages().get(MSG_0_NAME)); }
@Test public void badResponseServedFromCache() throws Exception { HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(BASIC_BUNDLE.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); HttpResponse badResponse = HttpResponse.error(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(expiredResponse).once(); expect(pipeline.execute(isA(HttpRequest.class))) .andReturn(badResponse).once(); replay(pipeline); final AtomicLong time = new AtomicLong(); bundleFactory.cache.setTimeSource(new TimeSource() { @Override public long currentTimeMillis() { return time.get(); } }); time.set(System.currentTimeMillis()); MessageBundle bundle0 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER); time.set(time.get() + MAX_AGE + 1); MessageBundle bundle1 = bundleFactory.getBundle(gadgetSpec, LOCALE, false, ContainerConfig.DEFAULT_CONTAINER); verify(pipeline); assertEquals(bundle0.getMessages().get(MSG_0_NAME), bundle1.getMessages().get(MSG_0_NAME)); }