Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jja725 committed Apr 22, 2024
1 parent 8bd15c4 commit 636b222
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -215,16 +185,28 @@ 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);
loadFullCache();
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
Expand Down

0 comments on commit 636b222

Please sign in to comment.