| 69 | }; |
| 70 | |
| 71 | TEST_F(TwoLevelCacheWithExpirationTest, RemoveExpiration) { |
| 72 | auto lifetime1_before_expiration = cache_.GetOrCreateInternalCache("lifetime1", 1); |
| 73 | ASSERT_EQ(lifetime1_before_expiration->size(), 2); |
| 74 | |
| 75 | // wait for 0.3s, we expect: |
| 76 | // lifetime1 will be expired |
| 77 | // lifetime2 will not be expired |
| 78 | SleepFor(0.3); |
| 79 | // now clear expired items from the cache |
| 80 | cache_.CheckCacheForExpiredTokens(); |
| 81 | |
| 82 | // lifetime1 (with 2 items) is expired and has been removed from the cache. |
| 83 | // Now the cache create a new object which has no item. |
| 84 | auto lifetime1 = cache_.GetOrCreateInternalCache("lifetime1", 1); |
| 85 | ASSERT_EQ(lifetime1->size(), 0); |
| 86 | |
| 87 | // However, lifetime1_before_expiration can still access normally and independently |
| 88 | // from the one in cache |
| 89 | lifetime1_before_expiration->Insert("item3", 3); |
| 90 | ASSERT_EQ(lifetime1_before_expiration->size(), 3); |
| 91 | ASSERT_EQ(lifetime1->size(), 0); |
| 92 | |
| 93 | // lifetime2 is not expired and still contains 2 items. |
| 94 | std::shared_ptr<ConcurrentMap<std::string, int>> lifetime2 = |
| 95 | cache_.GetOrCreateInternalCache("lifetime2", 3); |
| 96 | ASSERT_EQ(lifetime2->size(), 2); |
| 97 | } |
| 98 | |
| 99 | TEST_F(TwoLevelCacheWithExpirationTest, CleanupPeriodOk) { |
| 100 | // wait for 0.3s, now: |
nothing calls this directly
no test coverage detected