MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/platform/cloud/expiring_lru_cache_test.cc:25–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace {
24
25TEST(ExpiringLRUCacheTest, MaxAge) {
26 const string key = "a";
27 std::unique_ptr<NowSecondsEnv> env(new NowSecondsEnv);
28 ExpiringLRUCache<int> cache(1, 0, env.get());
29 env->SetNowSeconds(1);
30 // Verify that replacement of an existing element works, and updates the
31 // timestamp of the entry.
32 cache.Insert(key, 41);
33 env->SetNowSeconds(2);
34 cache.Insert(key, 42);
35 // 1 second after the most recent insertion, the entry is still valid.
36 env->SetNowSeconds(3);
37 int value = 0;
38 EXPECT_TRUE(cache.Lookup(key, &value));
39 EXPECT_EQ(value, 42);
40 // 2 seconds after the most recent insertion, the entry is no longer valid.
41 env->SetNowSeconds(4);
42 EXPECT_FALSE(cache.Lookup(key, &value));
43 // Re-insert the entry.
44 cache.Insert(key, 43);
45 EXPECT_TRUE(cache.Lookup(key, &value));
46 EXPECT_EQ(value, 43);
47 // The entry is valid 1 second after the insertion...
48 env->SetNowSeconds(5);
49 value = 0;
50 EXPECT_TRUE(cache.Lookup(key, &value));
51 EXPECT_EQ(value, 43);
52 // ...but is no longer valid 2 seconds after the insertion.
53 env->SetNowSeconds(6);
54 EXPECT_FALSE(cache.Lookup(key, &value));
55}
56
57TEST(ExpiringLRUCacheTest, MaxEntries) {
58 // max_age of 0 means nothing will be cached.

Callers

nothing calls this directly

Calls 7

SetNowSecondsMethod · 0.80
LookupOrComputeMethod · 0.80
getMethod · 0.45
InsertMethod · 0.45
LookupMethod · 0.45
ClearMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected