diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java index b6b792474ee..92e1d9dd4fa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotasObserver.java @@ -137,6 +137,38 @@ public class TestMasterQuotasObserver { assertEquals(0, getThrottleQuotas()); } + @Test + public void testTableSpaceAndRPCQuotaRemoved() throws Exception { + final Connection conn = TEST_UTIL.getConnection(); + final Admin admin = conn.getAdmin(); + final TableName tn = TableName.valueOf(testName.getMethodName()); + // Drop the table if it somehow exists + if (admin.tableExists(tn)) { + dropTable(admin, tn); + } + + createTable(admin, tn); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + + // Set Both quotas + QuotaSettings settings = + QuotaSettingsFactory.limitTableSpace(tn, 1024L, SpaceViolationPolicy.NO_INSERTS); + admin.setQuota(settings); + + settings = + QuotaSettingsFactory.throttleTable(tn, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + admin.setQuota(settings); + + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + // Delete the table and observe the quotas being automatically deleted as well + dropTable(admin, tn); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + } + @Test public void testNamespaceSpaceQuotaRemoved() throws Exception { final Connection conn = TEST_UTIL.getConnection(); @@ -189,6 +221,41 @@ public class TestMasterQuotasObserver { assertEquals(0, getThrottleQuotas()); } + @Test + public void testNamespaceSpaceAndRPCQuotaRemoved() throws Exception { + final Connection conn = TEST_UTIL.getConnection(); + final Admin admin = conn.getAdmin(); + final TableName tn = TableName.valueOf(testName.getMethodName()); + final String ns = testName.getMethodName(); + // Drop the ns if it somehow exists + if (namespaceExists(ns)) { + admin.deleteNamespace(ns); + } + + // Create the ns + NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); + admin.createNamespace(desc); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + + // Set Both quotas + QuotaSettings settings = + QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); + admin.setQuota(settings); + + settings = + QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); + admin.setQuota(settings); + + assertEquals(1, getNumSpaceQuotas()); + assertEquals(1, getThrottleQuotas()); + + // Delete the namespace and observe the quotas being automatically deleted as well + admin.deleteNamespace(ns); + assertEquals(0, getNumSpaceQuotas()); + assertEquals(0, getThrottleQuotas()); + } + @Test public void testObserverAddedByDefault() throws Exception { final HMaster master = TEST_UTIL.getHBaseCluster().getMaster();