@Test
  public void testTablesWithSnapshots() throws Exception {
    final Connection conn = TEST_UTIL.getConnection();
    final SpaceViolationPolicy policy = SpaceViolationPolicy.NO_INSERTS;
    final TableName tn = helper.createTableWithRegions(10);

    // 3MB limit on the table
    final long tableLimit = 3L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
    TEST_UTIL.getAdmin().setQuota(QuotaSettingsFactory.limitTableSpace(tn, tableLimit, policy));

    LOG.info("Writing first data set");
    // Write more data than should be allowed and flush it to disk
    helper.writeData(tn, 1L * SpaceQuotaHelperForTests.ONE_MEGABYTE, "q1");

    LOG.info("Creating snapshot");
    TEST_UTIL.getAdmin().snapshot(tn.toString() + "snap1", tn, SnapshotType.FLUSH);

    LOG.info("Writing second data set");
    // Write some more data
    helper.writeData(tn, 1L * SpaceQuotaHelperForTests.ONE_MEGABYTE, "q2");

    LOG.info("Flushing and major compacting table");
    // Compact the table to force the snapshot to own all of its files
    TEST_UTIL.getAdmin().flush(tn);
    TEST_UTIL.compact(tn, true);

    LOG.info("Checking for quota violation");
    // Wait to observe the quota moving into violation
    TEST_UTIL.waitFor(60_000, 1_000, new Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        Scan s = QuotaTableUtil.makeQuotaSnapshotScanForTable(tn);
        try (Table t = conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)) {
          ResultScanner rs = t.getScanner(s);
          try {
            Result r = Iterables.getOnlyElement(rs);
            CellScanner cs = r.cellScanner();
            assertTrue(cs.advance());
            Cell c = cs.current();
            SpaceQuotaSnapshot snapshot = SpaceQuotaSnapshot
              .toSpaceQuotaSnapshot(QuotaProtos.SpaceQuotaSnapshot.parseFrom(UnsafeByteOperations
                .unsafeWrap(c.getValueArray(), c.getValueOffset(), c.getValueLength())));
            LOG.info(
              snapshot.getUsage() + "/" + snapshot.getLimit() + " " + snapshot.getQuotaStatus());
            // We expect to see the table move to violation
            return snapshot.getQuotaStatus().isInViolation();
          } finally {
            if (null != rs) {
              rs.close();
            }
          }
        }
      }
    });
  }
Test class to exercise the inclusion of snapshots in space quotas
hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSpaceQuotasWithSnapshots.java