diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java index cea10ebd..7e251e7 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/MultithreadedTestUtil.java +++ 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 {} } /** diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java index 989192d..8692db4 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/TestAcidGuarantees.java @@ -115,6 +115,7 @@ public class TestAcidGuarantees implements Tool { byte data[] = new byte[10]; byte targetRows[][]; byte targetFamilies[][]; + Connection connection; Table table; AtomicLong numWritten = new AtomicLong(); @@ -123,7 +124,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 { @@ -141,6 +142,15 @@ public class TestAcidGuarantees implements Tool { table.put(p); numWritten.getAndIncrement(); } + + @Override + public void workDone() throws IOException { + try { + table.close(); + } finally { + connection.close(); + } + } } /** @@ -150,6 +160,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(); @@ -159,7 +170,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); } @@ -188,6 +199,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("!"); @@ -210,6 +230,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(); @@ -217,7 +238,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); } @@ -246,6 +267,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("!");