wchevreuil commented on a change in pull request #324: [HBASE-22606] : 
BucketCache improvement with additional tests
URL: https://github.com/apache/hbase/pull/324#discussion_r295822740
 
 

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
 ##########
 @@ -270,28 +287,63 @@ public void testRetrieveFromFile() throws Exception {
     }
     usedSize = bucketCache.getAllocator().getUsedSize();
     assertNotEquals(0, usedSize);
-    // persist cache to file
     bucketCache.shutdown();
     assertTrue(new File(persistencePath).exists());
-
-    // restore cache from file
     bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
-        constructedBlockSizes, writeThreads, writerQLen, persistencePath);
+            constructedBlockSizes, writeThreads, writerQLen, persistencePath);
     assertFalse(new File(persistencePath).exists());
     assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
-    // persist cache to file
     bucketCache.shutdown();
     assertTrue(new File(persistencePath).exists());
+    int[] smallBucketSizes = new int[]{2 * 1024 + 1024, 4 * 1024 + 1024};
+    bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
+            smallBucketSizes, writeThreads, writerQLen, persistencePath);
+    assertFalse(new File(persistencePath).exists());
+    assertEquals(0, bucketCache.getAllocator().getUsedSize());
+    assertEquals(0, bucketCache.backingMap.size());
+    TEST_UTIL.cleanupTestDir();
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testRetrieveFailure() throws Exception {
+    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+    Path testDir = TEST_UTIL.getDataTestDir();
+    TEST_UTIL.getTestFileSystem().mkdirs(testDir);
+    final String ioEngineName = testDir + "/bucket.cache";
+    testRetrievalUtils(TEST_UTIL, testDir, ioEngineName);
+  }
 
+  @Test
+  public void testRetrieveFromFileWithoutPersistence() throws Exception {
+    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+    Path testDir = TEST_UTIL.getDataTestDir();
+    TEST_UTIL.getTestFileSystem().mkdirs(testDir);
+    String ioEngineName = "file:" + testDir + "/bucket.cache";
+    BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
+            constructedBlockSizes, writeThreads, writerQLen, null);
+    long usedSize = bucketCache.getAllocator().getUsedSize();
+    assertEquals(0, usedSize);
+    HFileBlockPair[] blocks = 
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
+    for (HFileBlockPair block : blocks) {
+      bucketCache.cacheBlock(block.getBlockName(), block.getBlock());
+    }
+    for (HFileBlockPair block : blocks) {
+      cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), 
block.getBlock());
+    }
+    usedSize = bucketCache.getAllocator().getUsedSize();
+    assertNotEquals(0, usedSize);
+    bucketCache.shutdown();
+    bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
+            constructedBlockSizes, writeThreads, writerQLen, null);
+    assertEquals(0, bucketCache.getAllocator().getUsedSize());
+    bucketCache.shutdown();
     // reconfig buckets sizes, the biggest bucket is small than 
constructedBlockSize (8k or 16k)
     // so it can't restore cache from file
-    int[] smallBucketSizes = new int[] { 2 * 1024 + 1024, 4 * 1024 + 1024 };
+    int[] smallBucketSizes = new int[]{2 * 1024 + 1024, 4 * 1024 + 1024};
 
 Review comment:
   For testing BucketCache with no persistence, it does not seem we need this 
extra check anyways, as newly created BCs with no persistence will always be 
empty (regardless of the passed bucket sizes).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to