From 636b2228e9a26f776a999638f8cb811d410b55b6 Mon Sep 17 00:00:00 2001 From: Jianjian Date: Sun, 21 Apr 2024 22:09:12 -0700 Subject: [PATCH] fix test --- .../alluxio/client/file/MockFileInStream.java | 2 +- .../fs/LocalCacheManagerIntegrationTest.java | 48 ++++++------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/core/client/fs/src/test/java/alluxio/client/file/MockFileInStream.java b/core/client/fs/src/test/java/alluxio/client/file/MockFileInStream.java index 1df3898b1054..fbebff6edb9b 100644 --- a/core/client/fs/src/test/java/alluxio/client/file/MockFileInStream.java +++ b/core/client/fs/src/test/java/alluxio/client/file/MockFileInStream.java @@ -70,7 +70,7 @@ public long getPos() throws IOException { @Override public int positionedRead(long position, byte[] buffer, int offset, int length) throws IOException { - throw new UnsupportedOperationException("positionedRead not implemented for mock FileInStream"); + return length; } @Override diff --git a/tests/src/test/java/alluxio/client/fs/LocalCacheManagerIntegrationTest.java b/tests/src/test/java/alluxio/client/fs/LocalCacheManagerIntegrationTest.java index 49ac00cd88b3..3149a7bdf979 100644 --- a/tests/src/test/java/alluxio/client/fs/LocalCacheManagerIntegrationTest.java +++ b/tests/src/test/java/alluxio/client/fs/LocalCacheManagerIntegrationTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import alluxio.Constants; @@ -84,12 +85,6 @@ public void after() throws Exception { } } - @Test - public void newCacheRocks() throws Exception { - mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.ROCKS); - testNewCache(); - } - @Test public void newCacheLocal() throws Exception { mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); @@ -111,12 +106,6 @@ private void testPageCached(PageId pageId) { assertArrayEquals(PAGE, mBuffer); } - @Test - public void loadCacheRocks() throws Exception { - mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.ROCKS); - testLoadCache(); - } - @Test public void loadCacheLocal() throws Exception { mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); @@ -172,25 +161,6 @@ public void loadCacheMismatchedPageSize() throws Exception { testLoadCacheConfMismatch(PropertyKey.USER_CLIENT_CACHE_PAGE_SIZE, PAGE_SIZE_BYTES * 2); } - @Test - public void loadCacheMismatchedStoreTypeRocks() throws Exception { - mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); - testLoadCacheConfMismatch(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.ROCKS); - } - - @Test - public void loadCacheMismatchedStoreTypeLocal() throws Exception { - mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.ROCKS); - testLoadCacheConfMismatch(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); - } - - @Test - public void loadCacheSmallerNewCacheSizeRocks() throws Exception { - mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.ROCKS); - testLoadCacheConfMismatch(PropertyKey.USER_CLIENT_CACHE_SIZE, - String.valueOf(CACHE_SIZE_BYTES / 2)); - } - @Test public void loadCacheSmallerNewCacheSizeLocal() throws Exception { mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); @@ -215,6 +185,13 @@ public void loadCacheSmallerNewCacheSizeLocal() throws Exception { } } + /** + * Test the case that cache manager will properly handle invalid page file. + * if there is an invalid page file in the cache dir, cache manage will not recognize such + * file and will delete this file. Other valid page files are not affected + * and the cache manager should be able to read data from them normally. + * @throws Exception + */ @Test public void loadCacheWithInvalidPageFile() throws Exception { mConf.set(PropertyKey.USER_CLIENT_CACHE_STORE_TYPE, PageStoreType.LOCAL); @@ -222,9 +199,14 @@ public void loadCacheWithInvalidPageFile() throws Exception { mCacheManager.close(); // creates with an invalid page file stored String rootDir = mPageMetaStore.getStoreDirs().get(0).getRootPath().toString(); - FileUtils.createFile(Paths.get(rootDir, "invalidPageFile").toString()); + String invalidPageFileName = Paths.get(rootDir, "invalidPageFile").toString(); + FileUtils.createFile(invalidPageFileName); mCacheManager = LocalCacheManager.create(mCacheManagerOptions, mPageMetaStore); - assertEquals(0, mCacheManager.get(PAGE_ID, PAGE_SIZE_BYTES, mBuffer, 0)); + // There is an invalid file in the cache dir. But the cache manager will not recognize it as a + // valid page file and will delete it, and then will continue starting as normal. + assertEquals(PAGE_SIZE_BYTES, mCacheManager.get(PAGE_ID, PAGE_SIZE_BYTES, mBuffer, 0)); + assertArrayEquals(PAGE, mBuffer); + assertFalse(FileUtils.exists(invalidPageFileName)); } @Test