@Test
  public void testBucketingFilesToSnapshots() throws Exception {
    // Create a table and set a quota
    TableName tn1 = helper.createTableWithRegions(1);
    admin.setQuota(QuotaSettingsFactory.limitTableSpace(tn1, SpaceQuotaHelperForTests.ONE_GIGABYTE,
      SpaceViolationPolicy.NO_INSERTS));

    // Write some data and flush it
    helper.writeData(tn1, 256L * SpaceQuotaHelperForTests.ONE_KILOBYTE);
    admin.flush(tn1);

    final AtomicReference<Long> lastSeenSize = new AtomicReference<>();
    // Wait for the Master chore to run to see the usage (with a fudge factor)
    TEST_UTIL.waitFor(30_000, new SpaceQuotaSnapshotPredicate(conn, tn1) {
      @Override
      boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception {
        lastSeenSize.set(snapshot.getUsage());
        return snapshot.getUsage() > 230L * SpaceQuotaHelperForTests.ONE_KILOBYTE;
      }
    });

    // Create a snapshot on the table
    final String snapshotName1 = tn1 + "snapshot1";
    admin.snapshot(new SnapshotDescription(snapshotName1, tn1, SnapshotType.SKIPFLUSH));
    // Major compact the table to force a rewrite
    TEST_UTIL.compact(tn1, true);

    // Make sure that the snapshot owns the size
    final Table quotaTable = conn.getTable(QuotaUtil.QUOTA_TABLE_NAME);
    TEST_UTIL.waitFor(30_000, new Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        Get g = QuotaTableUtil.makeGetForSnapshotSize(tn1, snapshotName1);
        Result r = quotaTable.get(g);
        if (r == null || r.isEmpty()) {
          return false;
        }
        r.advance();
        Cell c = r.current();
        // The compaction result file has an additional compaction event tracker
        return lastSeenSize.get() <= QuotaTableUtil.parseSnapshotSize(c);
      }
    });

    // Create another snapshot on the table
    final String snapshotName2 = tn1 + "snapshot2";
    admin.snapshot(new SnapshotDescription(snapshotName2, tn1, SnapshotType.SKIPFLUSH));
    // Major compact the table to force a rewrite
    TEST_UTIL.compact(tn1, true);

    // Make sure that the snapshot owns the size
    TEST_UTIL.waitFor(30_000, new Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        Get g = QuotaTableUtil.makeGetForSnapshotSize(tn1, snapshotName2);
        Result r = quotaTable.get(g);
        if (r == null || r.isEmpty()) {
          return false;
        }
        r.advance();
        Cell c = r.current();
        // The compaction result file has an additional compaction event tracker
        return lastSeenSize.get() <= QuotaTableUtil.parseSnapshotSize(c);
      }
    });

    Get g = QuotaTableUtil.createGetNamespaceSnapshotSize(tn1.getNamespaceAsString());
    Result r = quotaTable.get(g);
    assertNotNull(r);
    assertFalse(r.isEmpty());
    r.advance();
    long size = QuotaTableUtil.parseSnapshotSize(r.current());
    assertTrue(lastSeenSize.get() * 2 <= size);
  }
Test class for the {@link SnapshotQuotaObserverChore}.
hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSnapshotQuotaObserverChore.java