@Test public void staleCacheFileDoesntExist() throws Exception { final File cachedfile = fakeFile("/cache/fake-file"); when(cachedfile.lastModified()).thenReturn(0L); assertTrue("File is stale", staleCacheFile(null, 0, 10, cachedfile)); verify(cachedfile).lastModified(); }
private static boolean staleCacheFile(final HttpQuery query, final long end_time, final long max_age, final File cachedfile) { final long mtime = cachedfile.lastModified() / 1000; if (mtime <= 0) { return true; } final long now = System.currentTimeMillis() / 1000; final long staleness = now - mtime; if (staleness < 0) { logWarn(query, "Not using file @ " + cachedfile + " with weird" + " mtime in the future: " + mtime); return true; } if (0 < end_time && end_time < now) { return mtime < end_time; } if (staleness > max_age) { logInfo(query, "Cached file @ " + cachedfile.getPath() + " is " + staleness + "s stale, which is more than its limit of " + max_age + "s, and needs to be regenerated."); return true; } return false; }
GraphHandler implements HttpRpc { private static boolean staleCacheFile(final HttpQuery query, final long end_time, final long max_age, final File cachedfile) { final long mtime = cachedfile.lastModified() / 1000; if (mtime <= 0) { return true; } final long now = System.currentTimeMillis() / 1000; final long staleness = now - mtime; if (staleness < 0) { logWarn(query, "Not using file @ " + cachedfile + " with weird" + " mtime in the future: " + mtime); return true; } if (0 < end_time && end_time < now) { return mtime < end_time; } if (staleness > max_age) { logInfo(query, "Cached file @ " + cachedfile.getPath() + " is " + staleness + "s stale, which is more than its limit of " + max_age + "s, and needs to be regenerated."); return true; } return false; } }
GraphHandler implements HttpRpc { private static boolean staleCacheFile(final HttpQuery query, final long end_time, final long max_age, final File cachedfile) { final long mtime = cachedfile.lastModified() / 1000; if (mtime <= 0) { return true; } final long now = System.currentTimeMillis() / 1000; final long staleness = now - mtime; if (staleness < 0) { logWarn(query, "Not using file @ " + cachedfile + " with weird" + " mtime in the future: " + mtime); return true; } if (0 < end_time && end_time < now) { return mtime < end_time; } if (staleness > max_age) { logInfo(query, "Cached file @ " + cachedfile.getPath() + " is " + staleness + "s stale, which is more than its limit of " + max_age + "s, and needs to be regenerated."); return true; } return false; } GraphHandler(); }
GraphHandler implements HttpRpc { private static boolean staleCacheFile(final HttpQuery query, final long end_time, final long max_age, final File cachedfile) { final long mtime = cachedfile.lastModified() / 1000; if (mtime <= 0) { return true; } final long now = System.currentTimeMillis() / 1000; final long staleness = now - mtime; if (staleness < 0) { logWarn(query, "Not using file @ " + cachedfile + " with weird" + " mtime in the future: " + mtime); return true; } if (0 < end_time && end_time < now) { return mtime < end_time; } if (staleness > max_age) { logInfo(query, "Cached file @ " + cachedfile.getPath() + " is " + staleness + "s stale, which is more than its limit of " + max_age + "s, and needs to be regenerated."); return true; } return false; } GraphHandler(); void execute(final TSDB tsdb, final HttpQuery query); void shutdown(); static void collectStats(final StatsCollector collector); }
GraphHandler implements HttpRpc { private static boolean staleCacheFile(final HttpQuery query, final long end_time, final long max_age, final File cachedfile) { final long mtime = cachedfile.lastModified() / 1000; if (mtime <= 0) { return true; } final long now = System.currentTimeMillis() / 1000; final long staleness = now - mtime; if (staleness < 0) { logWarn(query, "Not using file @ " + cachedfile + " with weird" + " mtime in the future: " + mtime); return true; } if (0 < end_time && end_time < now) { return mtime < end_time; } if (staleness > max_age) { logInfo(query, "Cached file @ " + cachedfile.getPath() + " is " + staleness + "s stale, which is more than its limit of " + max_age + "s, and needs to be regenerated."); return true; } return false; } GraphHandler(); void execute(final TSDB tsdb, final HttpQuery query); void shutdown(); static void collectStats(final StatsCollector collector);  }