Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jja725 committed Apr 8, 2024
1 parent a835f19 commit 65ea3a4
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,29 @@ public void asyncRestoreWithMorePagesThanCapacity() throws Exception {
assertEquals(0, mCacheManager.get(pageUuid, PAGE2.length, mBuf, 0));
}

@Test
public void ttlDeleteOldPagesWhenRestore() throws Exception {
mConf.set(PropertyKey.USER_CLIENT_CACHE_TTL_THRESHOLD_SECONDS, 5);
mConf.set(PropertyKey.USER_CLIENT_CACHE_TTL_ENABLED, true);
mCacheManagerOptions = CacheManagerOptions.create(mConf);
mCacheManager.close();
PageStoreDir dir = PageStoreDir.createPageStoreDirs(mCacheManagerOptions)
.get(0); // previous page store has been closed
PageId pageUuid = new PageId(UUID.randomUUID().toString(), 0);
dir.getPageStore().put(PAGE_ID1, PAGE1);
dir.getPageStore().put(PAGE_ID2, PAGE2);

dir = PageStoreDir.createPageStoreDirs(mCacheManagerOptions).get(0);
mPageMetaStore = new DefaultPageMetaStore(ImmutableList.of(dir));
Thread.sleep(6000);
dir.getPageStore()
.put(pageUuid, BufferUtils.getIncreasingByteArray(PAGE1.length + PAGE2.length + 1));
mCacheManager = createLocalCacheManager(mConf, mPageMetaStore);
assertFalse(mCacheManager.hasPageUnsafe(PAGE_ID1));
assertFalse(mCacheManager.hasPageUnsafe(PAGE_ID2));
assertTrue(mCacheManager.hasPageUnsafe(pageUuid)); // we should have the new page
}

@Test
public void asyncCache() throws Exception {
// this must be smaller than the number of locks in the page store for the test to succeed
Expand Down

0 comments on commit 65ea3a4

Please sign in to comment.