hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecl...@apache.org
Subject [46/50] [abbrv] git commit: [master] Add test for SizeAwareThriftHRegionServer
Date Thu, 31 Jul 2014 22:08:22 GMT
[master] Add test for SizeAwareThriftHRegionServer

Summary: Add a test

Test Plan: Unit test only

Reviewers: manukranthk, rshroff

Reviewed By: manukranthk, rshroff

Subscribers: hbase-prodeng@, hbase-eng@

Differential Revision: https://phabricator.fb.com/D1409864

git-svn-id: svn+ssh://tubbs/svnhive/hadoop/branches/titan/VENDOR.hbase/hbase-trunk@43220 e7acf4d4-3532-417f-9e73-7a9ae25a1f51


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/4282d5d0
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/4282d5d0
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/4282d5d0

Branch: refs/heads/0.89-fb
Commit: 4282d5d0f2b6e5716a74eef7ae0953783c68889b
Parents: 6b30de6
Author: elliott <elliott@e7acf4d4-3532-417f-9e73-7a9ae25a1f51>
Authored: Sat Jun 28 01:34:14 2014 +0000
Committer: Elliott Clark <elliott@fb.com>
Committed: Thu Jul 31 14:44:24 2014 -0700

----------------------------------------------------------------------
 .../SizeAwareThriftHRegionServer.java           |  13 ++-
 .../TestSizeAwareThriftHRegionServer.java       | 116 +++++++++++++++++++
 2 files changed, 123 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4282d5d0/src/main/java/org/apache/hadoop/hbase/regionserver/SizeAwareThriftHRegionServer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/SizeAwareThriftHRegionServer.java
b/src/main/java/org/apache/hadoop/hbase/regionserver/SizeAwareThriftHRegionServer.java
index d2526c6..a0c4476 100644
--- a/src/main/java/org/apache/hadoop/hbase/regionserver/SizeAwareThriftHRegionServer.java
+++ b/src/main/java/org/apache/hadoop/hbase/regionserver/SizeAwareThriftHRegionServer.java
@@ -10,6 +10,7 @@ import org.apache.hadoop.hbase.client.MultiPut;
 import org.apache.hadoop.hbase.client.MultiPutResponse;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.TMultiResponse;
+import org.apache.hadoop.hbase.ipc.thrift.exceptions.ThriftHBaseException;
 
 import javax.annotation.Nullable;
 import java.util.List;
@@ -35,7 +36,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer {
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 
@@ -51,7 +52,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer {
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 
@@ -79,7 +80,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer {
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 
@@ -97,7 +98,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer {
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 
@@ -110,7 +111,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer
{
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 
@@ -126,7 +127,7 @@ public class SizeAwareThriftHRegionServer extends ThriftHRegionServer
{
       Futures.addCallback(f, new DecrementWriteSizeCallback(heapSize));
       return f;
     } else {
-      return Futures.immediateFailedFuture(new RegionOverloadedException());
+      return Futures.immediateFailedFuture(new ThriftHBaseException(new RegionOverloadedException()));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/4282d5d0/src/test/java/org/apache/hadoop/hbase/regionserver/TestSizeAwareThriftHRegionServer.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/TestSizeAwareThriftHRegionServer.java
b/src/test/java/org/apache/hadoop/hbase/regionserver/TestSizeAwareThriftHRegionServer.java
new file mode 100644
index 0000000..4b992dc
--- /dev/null
+++ b/src/test/java/org/apache/hadoop/hbase/regionserver/TestSizeAwareThriftHRegionServer.java
@@ -0,0 +1,116 @@
+/**
+ * Copyright 2008 The Apache Software Foundation
+ *
+ * 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.regionserver;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.MediumTests;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.ArrayList;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.assertTrue;
+
+@Category(MediumTests.class)
+public class TestSizeAwareThriftHRegionServer {
+
+  private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+  private ExecutorService service = Executors.newFixedThreadPool(20);
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    Configuration configuration = TEST_UTIL.getConfiguration();
+    configuration.setLong("max.callqueue.memory.size", 1024 * 5);
+    configuration.setInt("hbase.client.retries.number", 3);
+    TEST_UTIL.startMiniCluster(1);
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testSize() throws Exception {
+    String tableName = "testSizeThrottle";
+    final byte[] tableNameBytes = Bytes.toBytes(tableName);
+    final byte[] cf = Bytes.toBytes("d");
+    TEST_UTIL.createTable(tableNameBytes, cf);
+
+    HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
+    ht.setAutoFlush(false);
+    Put smallPut = new Put(Bytes.toBytes("a"));
+    smallPut.add(cf, Bytes.toBytes(0), Bytes.toBytes("1"));
+
+    // This should work.
+    ht.put(smallPut);
+    ht.flushCommits();
+
+    final AtomicBoolean threw = new AtomicBoolean(false);
+
+    final ArrayList<Future<Void>> futures = new ArrayList<>();
+
+    // Since there's so many threads some of these should fail.
+    for (int i = 0; i < 20; i++) {
+      futures.add(service.submit(new Callable<Void>() {
+        @Override public Void call() throws Exception {
+
+          HTable t = new HTable(TEST_UTIL.getConfiguration(), tableNameBytes);
+          t.setAutoFlush(false);
+          for (int y = 0; y < 100; y++) {
+            Put p = new Put(Bytes.toBytes("test"));
+            for (int x = 0; x < 1000; x++) {
+              p.add(cf, Bytes.toBytes(x), Bytes.toBytes("b"));
+            }
+            try {
+              t.put(p);
+              t.flushCommits();
+            } catch (Exception roe) {
+              threw.set(true);
+            }
+
+          }
+
+          t.close();
+
+          return null;
+        }
+      }));
+    }
+
+    for (Future<Void> f : futures) {
+      f.get();
+    }
+
+    assertTrue("Should have caught a region too busy exception", threw.get());
+  }
+}


Mime
View raw message