Repository: hbase
Updated Branches:
  refs/heads/master 691f266fc -> a5a603688


HBASE-17309 Fix connection leaks in TestAcidGuarantees (huaxiang sun)


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

Branch: refs/heads/master
Commit: a5a6036883d17dea822fb0cc343b2819485a7e92
Parents: 691f266
Author: tedyu <yuzhih...@gmail.com>
Authored: Wed Dec 14 20:03:44 2016 -0800
Committer: tedyu <yuzhih...@gmail.com>
Committed: Wed Dec 14 20:03:44 2016 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/MultithreadedTestUtil.java     | 10 ++++--
 .../apache/hadoop/hbase/TestAcidGuarantees.java | 36 ++++++++++++++++++--
 2 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a5a60368/hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java
index cea10ebd..7e251e7 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java
@@ -18,6 +18,7 @@
  */
 package org.apache.hadoop.hbase;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -143,12 +144,17 @@ public abstract class MultithreadedTestUtil {
     }
 
     public final void doWork() throws Exception {
-      while (ctx.shouldRun() && !stopped) {
-        doAnAction();
+      try {
+        while (ctx.shouldRun() && !stopped) {
+          doAnAction();
+        }
+      } finally {
+        workDone();
       }
     }
 
     public abstract void doAnAction() throws Exception;
+    public void workDone() throws IOException {}
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/a5a60368/hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java
index e6c7124..0c86145 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java
@@ -118,6 +118,7 @@ public class TestAcidGuarantees implements Tool {
     byte data[] = new byte[10];
     byte targetRows[][];
     byte targetFamilies[][];
+    Connection connection;
     Table table;
     AtomicLong numWritten = new AtomicLong();
 
@@ -126,7 +127,7 @@ public class TestAcidGuarantees implements Tool {
       super(ctx);
       this.targetRows = targetRows;
       this.targetFamilies = targetFamilies;
-      Connection connection = 
ConnectionFactory.createConnection(ctx.getConf());
+      connection = ConnectionFactory.createConnection(ctx.getConf());
       table = connection.getTable(TABLE_NAME);
     }
     public void doAnAction() throws Exception {
@@ -144,6 +145,15 @@ public class TestAcidGuarantees implements Tool {
       table.put(p);
       numWritten.getAndIncrement();
     }
+
+    @Override
+    public void workDone() throws IOException {
+      try {
+        table.close();
+      } finally {
+        connection.close();
+      }
+    }
   }
 
   /**
@@ -153,6 +163,7 @@ public class TestAcidGuarantees implements Tool {
   public static class AtomicGetReader extends RepeatingTestThread {
     byte targetRow[];
     byte targetFamilies[][];
+    Connection connection;
     Table table;
     int numVerified = 0;
     AtomicLong numRead = new AtomicLong();
@@ -162,7 +173,7 @@ public class TestAcidGuarantees implements Tool {
       super(ctx);
       this.targetRow = targetRow;
       this.targetFamilies = targetFamilies;
-      Connection connection = 
ConnectionFactory.createConnection(ctx.getConf());
+      connection = ConnectionFactory.createConnection(ctx.getConf());
       table = connection.getTable(TABLE_NAME);
     }
 
@@ -191,6 +202,15 @@ public class TestAcidGuarantees implements Tool {
       numRead.getAndIncrement();
     }
 
+    @Override
+    public void workDone() throws IOException {
+      try {
+        table.close();
+      } finally {
+        connection.close();
+      }
+    }
+
     private void gotFailure(byte[] expected, Result res) {
       StringBuilder msg = new StringBuilder();
       msg.append("Failed after ").append(numVerified).append("!");
@@ -213,6 +233,7 @@ public class TestAcidGuarantees implements Tool {
   public static class AtomicScanReader extends RepeatingTestThread {
     byte targetFamilies[][];
     Table table;
+    Connection connection;
     AtomicLong numScans = new AtomicLong();
     AtomicLong numRowsScanned = new AtomicLong();
 
@@ -220,7 +241,7 @@ public class TestAcidGuarantees implements Tool {
                            byte targetFamilies[][]) throws IOException {
       super(ctx);
       this.targetFamilies = targetFamilies;
-      Connection connection = 
ConnectionFactory.createConnection(ctx.getConf());
+      connection = ConnectionFactory.createConnection(ctx.getConf());
       table = connection.getTable(TABLE_NAME);
     }
 
@@ -249,6 +270,15 @@ public class TestAcidGuarantees implements Tool {
       numScans.getAndIncrement();
     }
 
+    @Override
+    public void workDone() throws IOException {
+      try {
+        table.close();
+      } finally {
+        connection.close();
+      }
+    }
+
     private void gotFailure(byte[] expected, Result res) {
       StringBuilder msg = new StringBuilder();
       msg.append("Failed after ").append(numRowsScanned).append("!");

Reply via email to