hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject [1/3] hbase git commit: HBASE-18807 Remove protobuf references from CP quota API calls [Forced Update!]
Date Mon, 25 Sep 2017 01:12:51 GMT
Repository: hbase
Updated Branches:
  refs/heads/HBASE-18467 51e49957c -> fabff5aa2 (forced update)


http://git-wip-us.apache.org/repos/asf/hbase/blob/15404831/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestGlobalQuotaSettings.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestGlobalQuotaSettings.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestGlobalQuotaSettings.java
new file mode 100644
index 0000000..c4213cb
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestGlobalQuotaSettings.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.quotas;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(SmallTests.class)
+public class TestGlobalQuotaSettings {
+
+  QuotaProtos.TimedQuota REQUEST_THROTTLE = QuotaProtos.TimedQuota.newBuilder()
+      .setScope(QuotaProtos.QuotaScope.MACHINE).setSoftLimit(100)
+      .setTimeUnit(HBaseProtos.TimeUnit.MINUTES).build();
+  QuotaProtos.Throttle THROTTLE = QuotaProtos.Throttle.newBuilder()
+      .setReqNum(REQUEST_THROTTLE).build();
+
+  QuotaProtos.SpaceQuota SPACE_QUOTA = QuotaProtos.SpaceQuota.newBuilder()
+      .setSoftLimit(1024L * 1024L).setViolationPolicy(QuotaProtos.SpaceViolationPolicy.NO_WRITES)
+      .build();
+
+  @Test
+  public void testMergeThrottle() throws IOException {
+    QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder()
+        .setThrottle(THROTTLE).build();
+    QuotaProtos.TimedQuota writeQuota = REQUEST_THROTTLE.toBuilder()
+        .setSoftLimit(500).build();
+    // Unset the req throttle, set a write throttle
+    QuotaProtos.ThrottleRequest writeThrottle = QuotaProtos.ThrottleRequest.newBuilder()
+        .setTimedQuota(writeQuota).setType(QuotaProtos.ThrottleType.WRITE_NUMBER).build();
+
+    GlobalQuotaSettings settings = new GlobalQuotaSettings("joe", null, null, quota);
+    GlobalQuotaSettings merged = settings.merge(
+        new ThrottleSettings("joe", null, null, writeThrottle));
+
+    QuotaProtos.Throttle mergedThrottle = merged.getThrottleProto();
+    // Verify the request throttle is in place
+    assertTrue(mergedThrottle.hasReqNum());
+    QuotaProtos.TimedQuota actualReqNum = mergedThrottle.getReqNum();
+    assertEquals(REQUEST_THROTTLE.getSoftLimit(), actualReqNum.getSoftLimit());
+
+    // Verify the write throttle is in place
+    assertTrue(mergedThrottle.hasWriteNum());
+    QuotaProtos.TimedQuota actualWriteNum = mergedThrottle.getWriteNum();
+    assertEquals(writeQuota.getSoftLimit(), actualWriteNum.getSoftLimit());
+  }
+
+  @Test
+  public void testMergeSpace() throws IOException {
+    TableName tn = TableName.valueOf("foo");
+    QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder()
+        .setSpace(SPACE_QUOTA).build();
+
+    GlobalQuotaSettings settings = new GlobalQuotaSettings(null, tn, null, quota);
+    // Switch the violation policy to DISABLE
+    GlobalQuotaSettings merged = settings.merge(
+        new SpaceLimitSettings(tn, SPACE_QUOTA.getSoftLimit(), SpaceViolationPolicy.DISABLE));
+
+    QuotaProtos.SpaceQuota mergedSpaceQuota = merged.getSpaceProto();
+    assertEquals(SPACE_QUOTA.getSoftLimit(), mergedSpaceQuota.getSoftLimit());
+    assertEquals(
+        QuotaProtos.SpaceViolationPolicy.DISABLE, mergedSpaceQuota.getViolationPolicy());
+  }
+
+  @Test
+  public void testMergeThrottleAndSpace() throws IOException {
+    final String ns = "org1";
+    QuotaProtos.Quotas quota = QuotaProtos.Quotas.newBuilder()
+        .setThrottle(THROTTLE).setSpace(SPACE_QUOTA).build();
+    GlobalQuotaSettings settings = new GlobalQuotaSettings(null, null, ns, quota);
+
+    QuotaProtos.TimedQuota writeQuota = REQUEST_THROTTLE.toBuilder()
+        .setSoftLimit(500).build();
+    // Add a write throttle
+    QuotaProtos.ThrottleRequest writeThrottle = QuotaProtos.ThrottleRequest.newBuilder()
+        .setTimedQuota(writeQuota).setType(QuotaProtos.ThrottleType.WRITE_NUMBER).build();
+
+    GlobalQuotaSettings merged = settings.merge(
+        new ThrottleSettings(null, null, ns, writeThrottle));
+    GlobalQuotaSettings finalQuota = merged.merge(new SpaceLimitSettings(
+        ns, SPACE_QUOTA.getSoftLimit(), SpaceViolationPolicy.NO_WRITES_COMPACTIONS));
+
+    // Verify both throttle quotas
+    QuotaProtos.Throttle throttle = finalQuota.getThrottleProto();
+    assertTrue(throttle.hasReqNum());
+    QuotaProtos.TimedQuota reqNumQuota = throttle.getReqNum();
+    assertEquals(REQUEST_THROTTLE.getSoftLimit(), reqNumQuota.getSoftLimit());
+
+    assertTrue(throttle.hasWriteNum());
+    QuotaProtos.TimedQuota writeNumQuota = throttle.getWriteNum();
+    assertEquals(writeQuota.getSoftLimit(), writeNumQuota.getSoftLimit());
+
+    // Verify space quota
+    QuotaProtos.SpaceQuota finalSpaceQuota = finalQuota.getSpaceProto();
+    assertEquals(SPACE_QUOTA.getSoftLimit(), finalSpaceQuota.getSoftLimit());
+    assertEquals(
+        QuotaProtos.SpaceViolationPolicy.NO_WRITES_COMPACTIONS,
+        finalSpaceQuota.getViolationPolicy());
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/15404831/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaAdmin.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaAdmin.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaAdmin.java
index b9f54ad..2a16739 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaAdmin.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaAdmin.java
@@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas;
 import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceLimitRequest;
 import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -73,6 +74,14 @@ public class TestQuotaAdmin {
     TEST_UTIL.waitTableAvailable(QuotaTableUtil.QUOTA_TABLE_NAME);
   }
 
+  @After
+  public void clearQuotaTable() throws Exception {
+    if (TEST_UTIL.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) {
+      TEST_UTIL.getAdmin().disableTable(QuotaUtil.QUOTA_TABLE_NAME);
+      TEST_UTIL.getAdmin().truncateTable(QuotaUtil.QUOTA_TABLE_NAME, false);
+    }
+  }
+
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
     TEST_UTIL.shutdownMiniCluster();
@@ -249,7 +258,7 @@ public class TestQuotaAdmin {
   @Test
   public void testSetGetRemoveSpaceQuota() throws Exception {
     Admin admin = TEST_UTIL.getAdmin();
-    final TableName tn = TableName.valueOf("table1");
+    final TableName tn = TableName.valueOf("sq_table1");
     final long sizeLimit = 1024L * 1024L * 1024L * 1024L * 5L; // 5TB
     final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_WRITES;
     QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, violationPolicy);
@@ -302,7 +311,7 @@ public class TestQuotaAdmin {
   @Test
   public void testSetModifyRemoveQuota() throws Exception {
     Admin admin = TEST_UTIL.getAdmin();
-    final TableName tn = TableName.valueOf("table1");
+    final TableName tn = TableName.valueOf("sq_table2");
     final long originalSizeLimit = 1024L * 1024L * 1024L * 1024L * 5L; // 5TB
     final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_WRITES;
     QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(

http://git-wip-us.apache.org/repos/asf/hbase/blob/15404831/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java
index 7a330fb..b1b2797 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java
@@ -514,12 +514,7 @@ public class TestQuotaThrottle {
         }
         count += tables.length;
       }
-    } catch (RetriesExhaustedWithDetailsException e) {
-      for (Throwable t: e.getCauses()) {
-        if (!(t instanceof ThrottlingException)) {
-          throw e;
-        }
-      }
+    } catch (ThrottlingException e) {
       LOG.error("put failed after nRetries=" + count, e);
     }
     return count;

http://git-wip-us.apache.org/repos/asf/hbase/blob/15404831/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
index aab7ae4..0c072b8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
@@ -57,7 +57,6 @@ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
 import org.apache.hadoop.hbase.filter.BinaryComparator;
 import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas;
 import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
@@ -793,9 +792,8 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
     verifyAllowed(new AccessTestAction() {
       @Override
       public Object run() throws Exception {
-        Quotas quotas = Quotas.newBuilder().build();
         ACCESS_CONTROLLER.preSetUserQuota(ObserverContext.createAndPrepare(CP_ENV, null),
-          "testuser", quotas);
+          "testuser", null);
         return null;
       }
     }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -804,9 +802,8 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
     verifyAllowed(new AccessTestAction() {
       @Override
       public Object run() throws Exception {
-        Quotas quotas = Quotas.newBuilder().build();
         ACCESS_CONTROLLER.preSetTableQuota(ObserverContext.createAndPrepare(CP_ENV, null),
-          TEST_TABLE.getTableName(), quotas);
+          TEST_TABLE.getTableName(), null);
         return null;
       }
     }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -815,9 +812,8 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
     verifyAllowed(new AccessTestAction() {
       @Override
       public Object run() throws Exception {
-        Quotas quotas = Quotas.newBuilder().build();
         ACCESS_CONTROLLER.preSetNamespaceQuota(ObserverContext.createAndPrepare(CP_ENV, null),
-          "test", quotas);
+          "test", null);
         return null;
       }
     }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);


Mime
View raw message