@Test public void testGeneralCacheExpiration() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); String key = "key1", val = "val1"; expiringCache.addElement(key, val, 240 * 1000); // Time is still 0: should be in the cache. assertEquals(val, expiringCache.getElement(key).obj); assertFalse(expiringCache.getElement(key).isExpired); // Time = 300 seconds: out of cache. timeSource.setCurrentTimeMillis(300 * 1000); assertEquals(val, expiringCache.getElement(key).obj); assertTrue(expiringCache.getElement(key).isExpired); }
@Test public void testGeneralCacheExpiration() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); String key = "key1", val = "val1"; expiringCache.addElement(key, val, 240 * 1000); // Time is still 0: should be in the cache. assertEquals(val, expiringCache.getElement(key).obj); assertFalse(expiringCache.getElement(key).isExpired); // Time = 300 seconds: out of cache. timeSource.setCurrentTimeMillis(300 * 1000); assertEquals(val, expiringCache.getElement(key).obj); assertTrue(expiringCache.getElement(key).isExpired); }
@Test public void testGeneralCacheExpiration() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); String key = "key1", val = "val1"; expiringCache.addElement(key, val, 240 * 1000); // Time is still 0: should be in the cache. assertEquals(val, expiringCache.getElement(key).obj); assertFalse(expiringCache.getElement(key).isExpired); // Time = 300 seconds: out of cache. timeSource.setCurrentTimeMillis(300 * 1000); assertEquals(val, expiringCache.getElement(key).obj); assertTrue(expiringCache.getElement(key).isExpired); }
@Test public void testGeneralCacheExpiration() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); String key = "key1", val = "val1"; expiringCache.addElement(key, val, 240 * 1000); // Time is still 0: should be in the cache. assertEquals(val, expiringCache.getElement(key).obj); assertFalse(expiringCache.getElement(key).isExpired); // Time = 300 seconds: out of cache. timeSource.setCurrentTimeMillis(300 * 1000); assertEquals(val, expiringCache.getElement(key).obj); assertTrue(expiringCache.getElement(key).isExpired); }
@Test public void testGeneralCacheExpiration() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); String key = "key1", val = "val1"; expiringCache.addElement(key, val, 240 * 1000); // Time is still 0: should be in the cache. assertEquals(val, expiringCache.getElement(key).obj); assertFalse(expiringCache.getElement(key).isExpired); // Time = 300 seconds: out of cache. timeSource.setCurrentTimeMillis(300 * 1000); assertEquals(val, expiringCache.getElement(key).obj); assertTrue(expiringCache.getElement(key).isExpired); }
@Test public void testMissingValue() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); assertNull(expiringCache.getElement("not set")); } }
@Test public void testMissingValue() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); assertNull(expiringCache.getElement("not set")); } }
@Test public void testMissingValue() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); assertNull(expiringCache.getElement("not set")); } }
@Test public void testMissingValue() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); assertNull(expiringCache.getElement("not set")); } }
Object obj = null; if (!query.ignoreCache) { SoftExpiringCache.CachedObject<Object> cached = cache.getElement(query.specUri.toString()); if (cached != null) { obj = cached.obj;
@Test public void testMissingValue() { SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache(); assertNull(expiringCache.getElement("not set")); } }
+ info.message.getParameter("oauth_nonce"); CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey); if (previousMessage != null) { throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
+ info.message.getParameter("oauth_nonce"); CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey); if (previousMessage != null) { throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
+ info.message.getParameter("oauth_nonce"); CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey); if (previousMessage != null) { throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL); specFactory.cache.addElement(SPEC_URL, inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecIsRefetched() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .addHeader("Pragma", "no-cache") .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .create(); HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(expiredResponse).once(); expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL); specFactory.cache.addElement(SPEC_URL, inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecIsRefetched() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .addHeader("Pragma", "no-cache") .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .create(); HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(expiredResponse).once(); expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecIsRefetched() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .addHeader("Pragma", "no-cache") .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .create(); HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML); expect(pipeline.execute(request)).andReturn(expiredResponse).once(); expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }