saintstack commented on a change in pull request #333: [HBASE-22606] : 
BucketCache additional tests
URL: https://github.com/apache/hbase/pull/333#discussion_r296838170
 
 

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
 ##########
 @@ -277,28 +311,49 @@ 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());
+  }
+
+  @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(testDir, ioEngineName);
+  }
 
-    // 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 };
+  @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,
-        smallBucketSizes, writeThreads, writerQLen, persistencePath);
-    assertFalse(new File(persistencePath).exists());
+            constructedBlockSizes, writeThreads, writerQLen, null);
     assertEquals(0, bucketCache.getAllocator().getUsedSize());
-    assertEquals(0, bucketCache.backingMap.size());
-
+    bucketCache.shutdown();
 
 Review comment:
   Should this be in a finally block?

----------------------------------------------------------------
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