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

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
 ##########
 @@ -255,51 +269,128 @@ public void run() {
 
   @Test
   public void testRetrieveFromFile() throws Exception {
-    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
-    Path testDir = TEST_UTIL.getDataTestDir();
-    TEST_UTIL.getTestFileSystem().mkdirs(testDir);
-
+    Path testDir = createAndGetTestDir();
     String ioEngineName = "file:" + testDir + "/bucket.cache";
+    testRetrievalUtils(testDir, ioEngineName);
+    int[] smallBucketSizes = new int[]{3 * 1024, 5 * 1024};
     String persistencePath = testDir + "/bucket.persistence";
+    BucketCache 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());
+    HBASE_TESTING_UTILITY.cleanupTestDir();
+  }
 
+  @Test
+  public void testRetrieveFromMMap() throws Exception {
+    final Path testDir = createAndGetTestDir();
+    final String ioEngineName = "mmap:" + testDir + "/bucket.cache";
+    testRetrievalUtils(testDir, ioEngineName);
+  }
+
+  @Test
+  public void testRetrieveFromPMem() throws Exception {
+    final Path testDir = createAndGetTestDir();
+    final String ioEngineName = "pmem:" + testDir + "/bucket.cache";
+    testRetrievalUtils(testDir, ioEngineName);
+    int[] smallBucketSizes = new int[]{3 * 1024, 5 * 1024};
+    String persistencePath = testDir + "/bucket.persistence";
     BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
-        constructedBlockSizes, writeThreads, writerQLen, persistencePath);
-    long usedSize = bucketCache.getAllocator().getUsedSize();
-    assertEquals(0, usedSize);
-
-    HFileBlockPair[] blocks = 
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
-    // Add blocks
-    for (HFileBlockPair block : blocks) {
-      bucketCache.cacheBlock(block.getBlockName(), block.getBlock());
-    }
-    for (HFileBlockPair block : blocks) {
-      cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), 
block.getBlock());
+            smallBucketSizes, writeThreads, writerQLen, persistencePath);
+    assertFalse(new File(persistencePath).exists());
+    assertEquals(0, bucketCache.getAllocator().getUsedSize());
+    assertEquals(0, bucketCache.backingMap.size());
+    HBASE_TESTING_UTILITY.cleanupTestDir();
+  }
+
+  private void testRetrievalUtils(Path testDir, String ioEngineName)
+          throws IOException, InterruptedException {
+    final String persistencePath = testDir + "/bucket.persistence";
+    BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
+            constructedBlockSizes, writeThreads, writerQLen, persistencePath);
+    try {
+      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();
+      assertTrue(new File(persistencePath).exists());
+      bucketCache = new BucketCache(ioEngineName, capacitySize, 
constructedBlockSize,
+              constructedBlockSizes, writeThreads, writerQLen, 
persistencePath);
+      assertFalse(new File(persistencePath).exists());
+      assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
+    } finally {
+      bucketCache.shutdown();
     }
-    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);
-    assertFalse(new File(persistencePath).exists());
-    assertEquals(usedSize, bucketCache.getAllocator().getUsedSize());
-    // persist cache to file
-    bucketCache.shutdown();
-    assertTrue(new File(persistencePath).exists());
+  @Test
 
 Review comment:
   Apart from this, the patch lgtm.

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