@Test
  public void testSuperUserCanStillCompact() throws Exception {
    // Create a table and write enough data to push it into quota violation
    final TableName tn = doAsSuperUser(new Callable<TableName>() {
      @Override
      public TableName call() throws Exception {
        try (Connection conn = getConnection()) {
          Admin admin = conn.getAdmin();
          final TableName tn = helper.createTableWithRegions(admin, 5);
          // Grant the normal user permissions
          try {
            AccessControlClient.grant(conn, tn, REGULARUSER_NAME, null, null, Action.READ,
              Action.WRITE);
          } catch (Throwable t) {
            if (t instanceof Exception) {
              throw (Exception) t;
            }
            throw new Exception(t);
          }
          return tn;
        }
      }
    });

    // Write a bunch of data as our end-user
    doAsRegularUser(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        try (Connection conn = getConnection()) {
          // Write way more data so that we have HFiles > numRegions after flushes
          // helper.writeData flushes itself, so no need to flush explicitly
          helper.writeData(tn, 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
          helper.writeData(tn, 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
          return null;
        }
      }
    });

    final long sizeLimit = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
    QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit,
      SpaceViolationPolicy.NO_WRITES_COMPACTIONS);

    try (Connection conn = getConnection()) {
      conn.getAdmin().setQuota(settings);
    }

    waitForTableToEnterQuotaViolation(tn);

    // Should throw an exception, unprivileged users cannot compact due to the quota
    try {
      doAsRegularUser(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          try (Connection conn = getConnection()) {
            conn.getAdmin().majorCompact(tn);
            return null;
          }
        }
      });
      fail("Expected an exception trying to compact a table with a quota violation");
    } catch (DoNotRetryIOException e) {
      // Expected Exception.
      LOG.debug("message", e);
    }

    try {
      // Should not throw an exception (superuser can do anything)
      doAsSuperUser(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          try (Connection conn = getConnection()) {
            conn.getAdmin().majorCompact(tn);
            return null;
          }
        }
      });
    } catch (Exception e) {
      // Unexpected Exception.
      LOG.debug("message", e);
      fail("Did not expect an exception to be thrown while a super user tries "
        + "to compact a table with a quota violation");
    }
    int numberOfRegions = TEST_UTIL.getAdmin().getRegions(tn).size();
    waitForHFilesCountLessorEqual(tn, Bytes.toBytes("f1"), numberOfRegions);
  }
Test class to verify that the HBase superuser can override quotas.
hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestSuperUserQuotaPermissions.java