@Test
  public void testMobFileCleanerChore() throws InterruptedException, IOException {
    loadData(table, 0, 10);
    loadData(table, 10, 10);
    // loadData(20, 10);
    long num = getNumberOfMobFiles(conf, table.getName(), new String(fam));
    assertEquals(2, num);
    // Major compact
    admin.majorCompact(tableDescriptor.getTableName(), fam);
    // wait until compaction is complete
    while (admin.getCompactionState(tableDescriptor.getTableName()) != CompactionState.NONE) {
      Thread.sleep(100);
    }

    num = getNumberOfMobFiles(conf, table.getName(), new String(fam));
    assertEquals(3, num);
    // We have guarantee, that compcated file discharger will run during this pause
    // because it has interval less than this wait time
    LOG.info("Waiting for {}ms", minAgeToArchive + 1000);

    Thread.sleep(minAgeToArchive + 1000);
    LOG.info("Cleaning up MOB files");

    ServerName serverUsed = null;
    List<RegionInfo> serverRegions = null;
    for (ServerName sn : admin.getRegionServers()) {
      serverRegions = admin.getRegions(sn);
      if (serverRegions != null && serverRegions.size() > 0) {
        // filtering out non test table regions
        serverRegions = serverRegions.stream().filter(r -> r.getTable() == table.getName())
          .collect(Collectors.toList());
        // if such one is found use this rs
        if (serverRegions.size() > 0) {
          serverUsed = sn;
        }
        break;
      }
    }

    chore = HTU.getMiniHBaseCluster().getRegionServer(serverUsed).getRSMobFileCleanerChore();

    chore.chore();

    num = getNumberOfMobFiles(conf, table.getName(), new String(fam));
    assertEquals(3 - serverRegions.size(), num);

    long scanned = scanTable();
    assertEquals(20, scanned);

    // creating a MOB file not referenced from the current RS
    Path extraMOBFile = MobTestUtil.generateMOBFileForRegion(conf, table.getName(),
      familyDescriptor, "nonExistentRegion");

    // verifying the new MOBfile is added
    num = getNumberOfMobFiles(conf, table.getName(), new String(fam));
    assertEquals(4 - serverRegions.size(), num);

    FileSystem fs = FileSystem.get(conf);
    assertTrue(fs.exists(extraMOBFile));

    LOG.info("Waiting for {}ms", minAgeToArchive + 1000);

    Thread.sleep(minAgeToArchive + 1000);
    LOG.info("Cleaning up MOB files");

    // running chore again
    chore.chore();

    // the chore should only archive old MOB files that were referenced from the current RS
    // the unrelated MOB file is still there
    num = getNumberOfMobFiles(conf, table.getName(), new String(fam));
    assertEquals(4 - serverRegions.size(), num);

    assertTrue(fs.exists(extraMOBFile));

    scanned = scanTable();
    assertEquals(20, scanned);
  }
Mob file cleaner chore test. 1. Creates MOB table 2. Load MOB data and flushes it N times 3. Runs
major MOB compaction 4. Verifies that number of MOB files in a mob directory is N+1 5. Waits for
a period of time larger than minimum age to archive 6. Runs Mob cleaner chore 7 Verifies that
every old MOB file referenced from current RS was archived
hbase-server/src/test/java/org/apache/hadoop/hbase/mob/TestRSMobFileCleanerChore.java