guluo2016 commented on PR #6947:
URL: https://github.com/apache/hbase/pull/6947#issuecomment-2943659626

   For `TestSnapshotRegionSizeCalculator`,i think we need to test for two 
scenarios
   1. table has no data, and region size is 0
   2. table has some data, and region size is greater than 0
   
   This is a test case I've written, for your reference.
   ```java
   @Test
     public void test() throws IOException {
       TableName tableName = TableName.valueOf("test_table");
       String snapshotName = "test_snapshot";
   
       // table has no data
       TEST_UTIL.createTable(tableName, Bytes.toBytes("info"));
       admin.snapshot(snapshotName, tableName);
       Path snapshotDir =
         SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, 
TEST_UTIL.getDefaultRootDirPath());
       SnapshotDescription snapshotDesc = 
SnapshotDescriptionUtils.readSnapshotInfo(TEST_UTIL.getTestFileSystem(), 
snapshotDir);
       SnapshotManifest manifest = 
SnapshotManifest.open(TEST_UTIL.getConfiguration(), 
TEST_UTIL.getTestFileSystem(), snapshotDir, snapshotDesc);
       SnapshotRegionSizeCalculator calculator = new 
SnapshotRegionSizeCalculator(TEST_UTIL.getConfiguration(), manifest);
       Map<String, Long> regionSizes = calculator.calculateRegionSizes();
       for (Map.Entry<String, Long> entry : regionSizes.entrySet()) {
         assertTrue("Region size should be 0.", entry.getValue() == 0);
       }
   
       admin.deleteSnapshot(snapshotName);
   
       // table has some data
       TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), 
Bytes.toBytes("info"));
       admin.snapshot(snapshotName, tableName);
       snapshotDir = 
SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, 
TEST_UTIL.getDefaultRootDirPath());
       snapshotDesc = 
SnapshotDescriptionUtils.readSnapshotInfo(TEST_UTIL.getTestFileSystem(), 
snapshotDir);
       manifest = SnapshotManifest.open(TEST_UTIL.getConfiguration(), 
TEST_UTIL.getTestFileSystem(), snapshotDir, snapshotDesc);
       calculator = new 
SnapshotRegionSizeCalculator(TEST_UTIL.getConfiguration(), manifest);
       regionSizes = calculator.calculateRegionSizes();
       for (Map.Entry<String, Long> entry : regionSizes.entrySet()) {
         assertTrue("Region size should be greater than 0.", entry.getValue() 
>= 0);
       }
   
       TEST_UTIL.deleteTable(tableName);
     }
   ```


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to