/* ------------------------------------------------------------ */ @Test @Slow public void testDateCache() throws Exception { // @WAS: Test t = new Test("org.eclipse.jetty.util.DateCache"); // 012345678901234567890123456789 DateCache dc = new DateCache("EEE, dd MMM yyyy HH:mm:ss zzz ZZZ", Locale.US); dc.setTimeZone(TimeZone.getTimeZone("GMT")); Thread.sleep(2000); long now = System.currentTimeMillis(); long end = now + 3000; String f = dc.format(now); String last = f; int hits = 0; int misses = 0; while (now < end) { last = f; f = dc.format(now); // System.err.printf("%s %s%n",f,last==f); if (last == f) hits++; else misses++; TimeUnit.MILLISECONDS.sleep(50); now = System.currentTimeMillis(); } Assert.assertTrue(hits / 10 > misses); }
@Test public void testFormat() { DateCache dc = new DateCache("yyyyMMdd", 86400000); String str = dc.formatFor(16067); assertEquals("20131228", str); String str1 = dc.formatFor(1); assertEquals("19700102", str1); }
@Test public void testFormatMillis() { String format = "yyyyMMddHHmmss"; SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); DateCache dc = new DateCache(format, 1000); int now = (int) (System.currentTimeMillis() / 1000); for (int i = 0; i < 10000; i++) { int now2 = now + i; String str2 = sdf.format(new Date(now2 * 1000L)); String str = dc.formatFor(now2); assertEquals("i: " + i, str2, str); } }