From 65ea3a448012e7aade454b57af9bcbe3c8ea434a Mon Sep 17 00:00:00 2001 From: Jianjian Date: Mon, 8 Apr 2024 11:56:18 -0700 Subject: [PATCH] add unit test --- .../file/cache/LocalCacheManagerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dora/core/client/fs/src/test/java/alluxio/client/file/cache/LocalCacheManagerTest.java b/dora/core/client/fs/src/test/java/alluxio/client/file/cache/LocalCacheManagerTest.java index e322688ea909..b7995f426f7f 100644 --- a/dora/core/client/fs/src/test/java/alluxio/client/file/cache/LocalCacheManagerTest.java +++ b/dora/core/client/fs/src/test/java/alluxio/client/file/cache/LocalCacheManagerTest.java @@ -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