@Before public void setUp() { fetcher = createMock(HttpFetcher.class); timeSource = new FakeTimeSource(); timeSource.setCurrentTimeMillis(0); loader = new TestFeatureResourceLoader(fetcher, timeSource, new DefaultFeatureFileSystem()); }
@Before public void setUp() { fetcher = createMock(HttpFetcher.class); timeSource = new FakeTimeSource(); timeSource.setCurrentTimeMillis(0); loader = new TestFeatureResourceLoader(fetcher, timeSource, new DefaultFeatureFileSystem()); }
@Test public void testTimeStamping() throws Exception { long start = 1201917724000L; long skew = 180000; int maxAge = 300; // 5 minutes int realAge = 600; // 10 minutes try { timeSource.setCurrentTimeMillis(start); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); timeSource.incrementSeconds(realAge); crypter.unwrap(blob, maxAge); fail("Blob should have expired"); } catch (BlobExpiredException e) { assertEquals(start-skew, e.minDate.getTime()); assertEquals(start+realAge*1000L, e.used.getTime()); assertEquals(start+skew+maxAge*1000L, e.maxDate.getTime()); } }
@Test public void testTimeStamping() throws Exception { long start = 1201917724000L; long skew = 180000; int maxAge = 300; // 5 minutes int realAge = 600; // 10 minutes try { timeSource.setCurrentTimeMillis(start); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); timeSource.incrementSeconds(realAge); crypter.unwrap(blob, maxAge); fail("Blob should have expired"); } catch (BlobExpiredException e) { assertEquals(start-skew, e.minDate.getTime()); assertEquals(start+realAge*1000L, e.used.getTime()); assertEquals(start+skew+maxAge*1000L, e.maxDate.getTime()); } }
@Before public void setUp() { loader = new TestFeatureResourceLoader(); timeSource = new FakeTimeSource(); timeSource.setCurrentTimeMillis(0); loader.setTimeSource(timeSource); }
@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); }