http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 6b4394f..40b1364 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -17,34 +17,6 @@ */ package org.apache.hadoop.hbase; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.UnknownHostException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.NavigableSet; -import java.util.Random; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.impl.Jdk14Logger; @@ -90,7 +62,6 @@ import org.apache.hadoop.hbase.regionserver.HStore; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException; -import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.tool.Canary; import org.apache.hadoop.hbase.util.Bytes; @@ -103,6 +74,7 @@ import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.RegionSplitter; import org.apache.hadoop.hbase.util.RetryCounter; import org.apache.hadoop.hbase.util.Threads; +import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.zookeeper.EmptyWatcher; import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; import org.apache.hadoop.hbase.zookeeper.ZKConfig; @@ -118,6 +90,34 @@ import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooKeeper.States; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.NavigableSet; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Facility for testing HBase. Replacement for * old HBaseTestCase and HBaseClusterTestCase functionality. @@ -976,7 +976,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { this.hbaseCluster = new MiniHBaseCluster(c, numMasters, numSlaves, masterClass, regionserverClass); // Don't leave here till we've done a successful scan of the hbase:meta - Table t = new HTable(c, TableName.META_TABLE_NAME); + Table t = getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner s = t.getScanner(new Scan()); while (s.next() != null) { continue; @@ -996,6 +996,10 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { * @throws IOException */ public void restartHBaseCluster(int servers) throws IOException, InterruptedException { + if(connection != null){ + connection.close(); + connection = null; + } this.hbaseCluster = new MiniHBaseCluster(this.conf, servers); // Don't leave here till we've done a successful scan of the hbase:meta Table t = new HTable(new Configuration(this.conf), TableName.META_TABLE_NAME); @@ -1276,7 +1280,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc, startKey, endKey, numRegions); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(getConfiguration(), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1315,7 +1319,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(htd, splitRows); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(htd.getTableName()); - return new HTable(getConfiguration(), htd.getTableName()); + return (HTable) getConnection().getTable(htd.getTableName()); } /** @@ -1353,7 +1357,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); - return new HTable(c, desc.getTableName()); + return (HTable) getConnection().getTable(desc.getTableName()); } /** @@ -1377,7 +1381,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(c, tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1399,7 +1403,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); - return new HTable(c, desc.getTableName()); + return (HTable) getConnection().getTable(desc.getTableName()); } /** @@ -1461,7 +1465,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(new Configuration(getConfiguration()), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1498,7 +1502,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(new Configuration(getConfiguration()), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1537,7 +1541,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(new Configuration(getConfiguration()), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1569,7 +1573,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc, splitRows); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(tableName); - return new HTable(getConfiguration(), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -1590,7 +1594,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { getHBaseAdmin().createTable(desc, splitRows); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned waitUntilAllRegionsAssigned(desc.getTableName()); - return new HTable(getConfiguration(), desc.getTableName()); + return (HTable) getConnection().getTable(desc.getTableName()); } /** @@ -1809,7 +1813,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { * @throws IOException */ public HTable deleteTableData(TableName tableName) throws IOException { - HTable table = new HTable(getConfiguration(), tableName); + HTable table = (HTable) getConnection().getTable(tableName); Scan scan = new Scan(); ResultScanner resScan = table.getScanner(scan); for(Result res : resScan) { @@ -1831,7 +1835,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { public HTable truncateTable(final TableName tableName, final boolean preserveRegions) throws IOException { Admin admin = getHBaseAdmin(); admin.truncateTable(tableName, preserveRegions); - return new HTable(getConfiguration(), tableName); + return (HTable) getConnection().getTable(tableName); } /** @@ -2271,7 +2275,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { public List<HRegionInfo> createMultiRegionsInMeta(final Configuration conf, final HTableDescriptor htd, byte [][] startKeys) throws IOException { - Table meta = new HTable(conf, TableName.META_TABLE_NAME); + Table meta = (HTable) getConnection().getTable(TableName.META_TABLE_NAME); Arrays.sort(startKeys, Bytes.BYTES_COMPARATOR); List<HRegionInfo> newRegions = new ArrayList<HRegionInfo>(startKeys.length); // add custom ones @@ -2294,7 +2298,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { */ public List<byte[]> getMetaTableRows() throws IOException { // TODO: Redo using MetaTableAccessor class - Table t = new HTable(new Configuration(this.conf), TableName.META_TABLE_NAME); + Table t = (HTable) getConnection().getTable(TableName.META_TABLE_NAME); List<byte[]> rows = new ArrayList<byte[]>(); ResultScanner s = t.getScanner(new Scan()); for (Result result : s) { @@ -2314,7 +2318,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { */ public List<byte[]> getMetaTableRows(TableName tableName) throws IOException { // TODO: Redo using MetaTableAccessor. - Table t = new HTable(new Configuration(this.conf), TableName.META_TABLE_NAME); + Table t = getConnection().getTable(TableName.META_TABLE_NAME); List<byte[]> rows = new ArrayList<byte[]>(); ResultScanner s = t.getScanner(new Scan()); for (Result result : s) { @@ -2631,7 +2635,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { monitor.close(); if (checkStatus) { - new HTable(new Configuration(conf), TableName.META_TABLE_NAME).close(); + getConnection().getTable(TableName.META_TABLE_NAME).close(); } } @@ -3140,7 +3144,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { */ public void waitUntilAllRegionsAssigned(final TableName tableName, final long timeout) throws IOException { - final Table meta = new HTable(getConfiguration(), TableName.META_TABLE_NAME); + final Table meta = getConnection().getTable(TableName.META_TABLE_NAME); try { waitFor(timeout, 200, true, new Predicate<IOException>() { @Override @@ -3548,9 +3552,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { return totalNumberOfRegions; } - public static int getMetaRSPort(Configuration conf) throws IOException { - try (Connection c = ConnectionFactory.createConnection(); - RegionLocator locator = c.getRegionLocator(TableName.META_TABLE_NAME)) { + public static int getMetaRSPort(Connection connection) throws IOException { + try (RegionLocator locator = connection.getRegionLocator(TableName.META_TABLE_NAME)) { return locator.getRegionLocation(Bytes.toBytes("")).getPort(); } }
http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java index 7524d5c..52424b3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java @@ -1020,7 +1020,7 @@ public class PerformanceEvaluation extends Configured implements Tool { if (!opts.oneCon) { this.connection = ConnectionFactory.createConnection(conf); } - this.table = new HTable(TableName.valueOf(opts.tableName), connection); + this.table = connection.getTable(TableName.valueOf(opts.tableName)); this.table.setAutoFlushTo(opts.autoFlush); latency = YammerHistogramUtils.newHistogram(new UniformSample(1024 * 500)); valueSize = YammerHistogramUtils.newHistogram(new UniformSample(1024 * 500)); @@ -1568,11 +1568,14 @@ public class PerformanceEvaluation extends Configured implements Tool { // the TestOptions introspection for us and dump the output in a readable format. LOG.info(cmd.getSimpleName() + " test run options=" + MAPPER.writeValueAsString(opts)); Admin admin = null; + Connection connection = null; try { - admin = new HBaseAdmin(getConf()); + connection = ConnectionFactory.createConnection(getConf()); + admin = connection.getAdmin(); checkTable(admin, opts); } finally { if (admin != null) admin.close(); + if (connection != null) connection.close(); } if (opts.nomapred) { doLocalClients(opts, getConf()); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java index 6b8e63d..0c331b7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java @@ -27,6 +27,8 @@ import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; @@ -149,7 +151,8 @@ public class ScanPerformanceEvaluation extends AbstractHBaseTool { Stopwatch scanTimer = new Stopwatch(); tableOpenTimer.start(); - Table table = new HTable(getConf(), TableName.valueOf(tablename)); + Connection connection = ConnectionFactory.createConnection(getConf()); + Table table = connection.getTable(TableName.valueOf(tablename)); tableOpenTimer.stop(); Scan scan = getScan(); @@ -172,6 +175,7 @@ public class ScanPerformanceEvaluation extends AbstractHBaseTool { scanTimer.stop(); scanner.close(); table.close(); + connection.close(); ScanMetrics metrics = ProtobufUtil.toScanMetrics(scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA)); long totalBytes = metrics.countOfBytesInResults.get(); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/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 3068fbf..5659f6b 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 @@ -28,6 +28,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread; import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; @@ -113,7 +115,8 @@ public class TestAcidGuarantees implements Tool { super(ctx); this.targetRows = targetRows; this.targetFamilies = targetFamilies; - table = new HTable(ctx.getConf(), TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(ctx.getConf()); + table = connection.getTable(TABLE_NAME); } public void doAnAction() throws Exception { // Pick a random row to write into @@ -148,7 +151,8 @@ public class TestAcidGuarantees implements Tool { super(ctx); this.targetRow = targetRow; this.targetFamilies = targetFamilies; - table = new HTable(ctx.getConf(), TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(ctx.getConf()); + table = connection.getTable(TABLE_NAME); } public void doAnAction() throws Exception { @@ -205,7 +209,8 @@ public class TestAcidGuarantees implements Tool { byte targetFamilies[][]) throws IOException { super(ctx); this.targetFamilies = targetFamilies; - table = new HTable(ctx.getConf(), TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(ctx.getConf()); + table = connection.getTable(TABLE_NAME); } public void doAnAction() throws Exception { http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java index 62b00d8..a72b151 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java @@ -67,7 +67,7 @@ public class TestInfoServers { @Test public void testInfoServersRedirect() throws Exception { // give the cluster time to start up - new HTable(UTIL.getConfiguration(), TableName.META_TABLE_NAME).close(); + UTIL.getConnection().getTable(TableName.META_TABLE_NAME).close(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); assertContainsContent(new URL("http://localhost:" + port + "/index.html"), "master-status"); @@ -87,7 +87,7 @@ public class TestInfoServers { @Test public void testInfoServersStatusPages() throws Exception { // give the cluster time to start up - new HTable(UTIL.getConfiguration(), TableName.META_TABLE_NAME).close(); + UTIL.getConnection().getTable(TableName.META_TABLE_NAME).close(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); assertContainsContent(new URL("http://localhost:" + port + "/master-status"), "meta"); @@ -102,7 +102,7 @@ public class TestInfoServers { TableName tableName = TableName.valueOf("testMasterServerReadOnly"); byte[] cf = Bytes.toBytes("d"); UTIL.createTable(tableName, cf); - new HTable(UTIL.getConfiguration(), tableName).close(); + UTIL.getConnection().getTable(tableName).close(); int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort(); assertDoesNotContainContent( new URL("http://localhost:" + port + "/table.jsp?name=" + tableName + "&action=split&key="), http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java index 3491d72..711d592 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMultiVersions.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -77,12 +78,7 @@ public class TestMultiVersions { @Before public void before() throws MasterNotRunningException, ZooKeeperConnectionException, IOException { - this.admin = new HBaseAdmin(UTIL.getConfiguration()); - } - - @After - public void after() throws IOException { - this.admin.close(); + this.admin = UTIL.getHBaseAdmin(); } /** @@ -101,7 +97,7 @@ public class TestMultiVersions { hcd.setMaxVersions(3); desc.addFamily(hcd); this.admin.createTable(desc); - Table table = new HTable(UTIL.getConfiguration(), desc.getTableName()); + Table table = UTIL.getConnection().getTable(desc.getTableName()); // TODO: Remove these deprecated classes or pull them in here if this is // only test using them. Incommon incommon = new HTableIncommon(table); @@ -144,16 +140,15 @@ public class TestMultiVersions { this.admin.createTable(desc); Put put = new Put(row, timestamp1); put.add(contents, contents, value1); - Table table = new HTable(UTIL.getConfiguration(), desc.getTableName()); + Table table = UTIL.getConnection().getTable(desc.getTableName()); table.put(put); // Shut down and restart the HBase cluster table.close(); UTIL.shutdownMiniHBaseCluster(); LOG.debug("HBase cluster shut down -- restarting"); UTIL.startMiniHBaseCluster(1, NUM_SLAVES); - // Make a new connection. Use new Configuration instance because old one - // is tied to an HConnection that has since gone stale. - table = new HTable(new Configuration(UTIL.getConfiguration()), desc.getTableName()); + // Make a new connection. + table = UTIL.getConnection().getTable(desc.getTableName()); // Overwrite previous value put = new Put(row, timestamp2); put.add(contents, contents, value2); @@ -207,23 +202,25 @@ public class TestMultiVersions { final byte [][] splitRows = new byte[][] {Bytes.toBytes("row_0500")}; final long [] timestamp = new long[] {100L, 1000L}; this.admin.createTable(desc, splitRows); - HTable table = new HTable(UTIL.getConfiguration(), tableName); + Table table = UTIL.getConnection().getTable(tableName); // Assert we got the region layout wanted. - NavigableMap<HRegionInfo, ServerName> locations = table.getRegionLocations(); - assertEquals(2, locations.size()); - int index = 0; - for (HRegionInfo hri: locations.keySet()) { - if (index == 0) { - assertTrue(Bytes.equals(HConstants.EMPTY_START_ROW, hri.getStartKey())); - assertTrue(Bytes.equals(hri.getEndKey(), splitRows[0])); - } else if (index == 1) { - assertTrue(Bytes.equals(splitRows[0], hri.getStartKey())); - assertTrue(Bytes.equals(hri.getEndKey(), HConstants.EMPTY_END_ROW)); + Pair<byte[][], byte[][]> keys = UTIL.getConnection() + .getRegionLocator(tableName).getStartEndKeys(); + assertEquals(2, keys.getFirst().length); + byte[][] startKeys = keys.getFirst(); + byte[][] endKeys = keys.getSecond(); + + for (int i = 0; i < startKeys.length; i++) { + if (i == 0) { + assertTrue(Bytes.equals(HConstants.EMPTY_START_ROW, startKeys[i])); + assertTrue(Bytes.equals(endKeys[i], splitRows[0])); + } else if (i == 1) { + assertTrue(Bytes.equals(splitRows[0], startKeys[i])); + assertTrue(Bytes.equals(endKeys[i], HConstants.EMPTY_END_ROW)); } - index++; } // Insert data - for (int i = 0; i < locations.size(); i++) { + for (int i = 0; i < startKeys.length; i++) { for (int j = 0; j < timestamp.length; j++) { Put put = new Put(rows[i], timestamp[j]); put.add(HConstants.CATALOG_FAMILY, null, timestamp[j], http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java index baa43fa..f47a8e0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java @@ -252,7 +252,7 @@ public class TestNamespace { } //sanity check try to write and read from table - Table table = new HTable(TEST_UTIL.getConfiguration(), desc.getTableName()); + Table table = TEST_UTIL.getConnection().getTable(desc.getTableName()); Put p = new Put(Bytes.toBytes("row1")); p.add(Bytes.toBytes("my_cf"),Bytes.toBytes("my_col"),Bytes.toBytes("value1")); table.put(p); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java index 1944b61..30ad325 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java @@ -35,11 +35,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnectionManager; -import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; @@ -127,7 +127,7 @@ public class TestZooKeeper { } } - private ZooKeeperWatcher getZooKeeperWatcher(HConnection c) + private ZooKeeperWatcher getZooKeeperWatcher(Connection c) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method getterZK = c.getClass().getDeclaredMethod("getKeepAliveZooKeeperWatcher"); getterZK.setAccessible(true); @@ -148,7 +148,7 @@ public class TestZooKeeper { // We don't want to share the connection as we will check its state c.set(HConstants.HBASE_CLIENT_INSTANCE_ID, "1111"); - HConnection connection = HConnectionManager.getConnection(c); + Connection connection = ConnectionFactory.createConnection(c); ZooKeeperWatcher connectionZK = getZooKeeperWatcher(connection); LOG.info("ZooKeeperWatcher= 0x"+ Integer.toHexString( @@ -253,15 +253,14 @@ public class TestZooKeeper { HColumnDescriptor family = new HColumnDescriptor("fam"); desc.addFamily(family); LOG.info("Creating table " + tableName); - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin admin = TEST_UTIL.getHBaseAdmin(); try { admin.createTable(desc); } finally { admin.close(); } - Table table = - new HTable(new Configuration(TEST_UTIL.getConfiguration()), desc.getTableName()); + Table table = TEST_UTIL.getConnection().getTable(desc.getTableName()); Put put = new Put(Bytes.toBytes("testrow")); put.add(Bytes.toBytes("fam"), Bytes.toBytes("col"), Bytes.toBytes("testdata")); @@ -273,11 +272,11 @@ public class TestZooKeeper { @Test public void testMultipleZK() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Table localMeta = - new HTable(new Configuration(TEST_UTIL.getConfiguration()), TableName.META_TABLE_NAME); + Table localMeta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); Configuration otherConf = new Configuration(TEST_UTIL.getConfiguration()); otherConf.set(HConstants.ZOOKEEPER_QUORUM, "127.0.0.1"); - Table ipMeta = new HTable(otherConf, TableName.META_TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(otherConf); + Table ipMeta = connection.getTable(TableName.META_TABLE_NAME); // dummy, just to open the connection final byte [] row = new byte [] {'r'}; @@ -294,6 +293,7 @@ public class TestZooKeeper { localMeta.close(); ipMeta.close(); + connection.close(); } /** @@ -494,7 +494,7 @@ public class TestZooKeeper { ZooKeeperWatcher zkw = m.getZooKeeper(); int expectedNumOfListeners = zkw.getNumberOfListeners(); // now the cluster is up. So assign some regions. - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin admin = TEST_UTIL.getHBaseAdmin(); try { byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d"), Bytes.toBytes("e"), Bytes.toBytes("f"), @@ -531,7 +531,7 @@ public class TestZooKeeper { cluster.startRegionServer(); HMaster m = cluster.getMaster(); // now the cluster is up. So assign some regions. - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin admin = TEST_UTIL.getHBaseAdmin(); Table table = null; try { byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("1"), Bytes.toBytes("2"), @@ -543,7 +543,7 @@ public class TestZooKeeper { htd.addFamily(hcd); admin.createTable(htd, SPLIT_KEYS); TEST_UTIL.waitUntilNoRegionsInTransition(60000); - table = new HTable(TEST_UTIL.getConfiguration(), htd.getTableName()); + table = TEST_UTIL.getConnection().getTable(htd.getTableName()); Put p; int numberOfPuts; for (numberOfPuts = 0; numberOfPuts < 6; numberOfPuts++) { http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java index bc36fa9..9b55acd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin1.java @@ -367,7 +367,7 @@ public class TestAdmin1 { splitKeys[1] = Bytes.toBytes(8); // Create & Fill the table - HTable table = TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY, splitKeys); + Table table = TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY, splitKeys); try { TEST_UTIL.loadNumericRows(table, HConstants.CATALOG_FAMILY, 0, 10); assertEquals(10, TEST_UTIL.countRows(table)); @@ -379,7 +379,7 @@ public class TestAdmin1 { // Truncate & Verify this.admin.disableTable(tableName); this.admin.truncateTable(tableName, preserveSplits); - table = new HTable(TEST_UTIL.getConfiguration(), tableName); + table = TEST_UTIL.getConnection().getTable(tableName); try { assertEquals(0, TEST_UTIL.countRows(table)); } finally { @@ -402,7 +402,7 @@ public class TestAdmin1 { htd.addFamily(fam2); htd.addFamily(fam3); this.admin.createTable(htd); - Table table = new HTable(TEST_UTIL.getConfiguration(), htd.getTableName()); + Table table = TEST_UTIL.getConnection().getTable(htd.getTableName()); HTableDescriptor confirmedHtd = table.getTableDescriptor(); assertEquals(htd.compareTo(confirmedHtd), 0); table.close(); @@ -585,7 +585,7 @@ public class TestAdmin1 { HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc); - HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + HTable ht = (HTable) TEST_UTIL.getConnection().getTable(tableName); Map<HRegionInfo, ServerName> regions = ht.getRegionLocations(); assertEquals("Table should have only 1 region", 1, regions.size()); ht.close(); @@ -594,7 +594,7 @@ public class TestAdmin1 { desc = new HTableDescriptor(TABLE_2); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, new byte[][]{new byte[]{42}}); - HTable ht2 = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); + HTable ht2 = (HTable) TEST_UTIL.getConnection().getTable(TABLE_2); regions = ht2.getRegionLocations(); assertEquals("Table should have only 2 region", 2, regions.size()); ht2.close(); @@ -603,7 +603,7 @@ public class TestAdmin1 { desc = new HTableDescriptor(TABLE_3); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, "a".getBytes(), "z".getBytes(), 3); - HTable ht3 = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); + HTable ht3 = (HTable) TEST_UTIL.getConnection().getTable(TABLE_3); regions = ht3.getRegionLocations(); assertEquals("Table should have only 3 region", 3, regions.size()); ht3.close(); @@ -622,7 +622,7 @@ public class TestAdmin1 { desc = new HTableDescriptor(TABLE_5); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, new byte[] {1}, new byte[] {127}, 16); - HTable ht5 = new HTable(TEST_UTIL.getConfiguration(), TABLE_5); + HTable ht5 = (HTable) TEST_UTIL.getConnection().getTable(TABLE_5); regions = ht5.getRegionLocations(); assertEquals("Table should have 16 region", 16, regions.size()); ht5.close(); @@ -653,7 +653,7 @@ public class TestAdmin1 { boolean tableAvailable = admin.isTableAvailable(tableName, splitKeys); assertTrue("Table should be created with splitKyes + 1 rows in META", tableAvailable); - HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + HTable ht = (HTable) TEST_UTIL.getConnection().getTable(tableName); Map<HRegionInfo, ServerName> regions = ht.getRegionLocations(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), @@ -710,10 +710,10 @@ public class TestAdmin1 { desc = new HTableDescriptor(TABLE_2); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + admin = TEST_UTIL.getHBaseAdmin(); admin.createTable(desc, startKey, endKey, expectedRegions); - HTable ht2 = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); + HTable ht2 = (HTable) TEST_UTIL.getConnection().getTable(TABLE_2); regions = ht2.getRegionLocations(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), @@ -766,11 +766,11 @@ public class TestAdmin1 { desc = new HTableDescriptor(TABLE_3); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + admin = TEST_UTIL.getHBaseAdmin(); admin.createTable(desc, startKey, endKey, expectedRegions); - HTable ht3 = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); + HTable ht3 = (HTable) TEST_UTIL.getConnection().getTable(TABLE_3); regions = ht3.getRegionLocations(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), @@ -792,15 +792,13 @@ public class TestAdmin1 { TableName TABLE_4 = TableName.valueOf(tableName.getNameAsString() + "_4"); desc = new HTableDescriptor(TABLE_4); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); - Admin ladmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); try { - ladmin.createTable(desc, splitKeys); + admin.createTable(desc, splitKeys); assertTrue("Should not be able to create this table because of " + "duplicate split keys", false); } catch(IllegalArgumentException iae) { // Expected } - ladmin.close(); } @Test (timeout=300000) @@ -893,7 +891,7 @@ public class TestAdmin1 { HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, splitKeys); - HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + HTable ht = (HTable) TEST_UTIL.getConnection().getTable(tableName); Map<HRegionInfo, ServerName> regions = ht.getRegionLocations(); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), expectedRegions, regions.size()); @@ -1104,7 +1102,7 @@ public class TestAdmin1 { Thread.sleep(10); } while (oldRegions.size() != 9); //3 regions * 3 replicas // write some data to the table - HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + HTable ht = (HTable) TEST_UTIL.getConnection().getTable(tableName); List<Put> puts = new ArrayList<Put>(); byte[] qualifier = "c".getBytes(); Put put = new Put(new byte[]{(byte)'1'}); @@ -1227,7 +1225,7 @@ public class TestAdmin1 { } this.admin.disableTable(tableName); try { - new HTable(TEST_UTIL.getConfiguration(), tableName); + TEST_UTIL.getConnection().getTable(tableName); } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) { //expected } http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java index 9daf685..bdf7de2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java @@ -176,7 +176,7 @@ public class TestAdmin2 { admin.createTable(htd1); admin.createTable(htd2); // Before fix, below would fail throwing a NoServerForRegionException. - new HTable(TEST_UTIL.getConfiguration(), htd2.getTableName()).close(); + TEST_UTIL.getConnection().getTable(htd2.getTableName()).close(); } /*** @@ -197,11 +197,10 @@ public class TestAdmin2 { // Use 80 bit numbers to make sure we aren't limited byte [] startKey = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; byte [] endKey = { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; - Admin hbaseadmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin hbaseadmin = TEST_UTIL.getHBaseAdmin(); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name)); htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); hbaseadmin.createTable(htd, startKey, endKey, expectedRegions); - hbaseadmin.close(); } finally { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, oldTimeout); } @@ -299,7 +298,7 @@ public class TestAdmin2 { public void testTableNotFoundExceptionWithoutAnyTables() throws IOException { TableName tableName = TableName .valueOf("testTableNotFoundExceptionWithoutAnyTables"); - Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + Table ht = TEST_UTIL.getConnection().getTable(tableName); ht.get(new Get("e".getBytes())); } @@ -466,9 +465,7 @@ public class TestAdmin2 { } private HBaseAdmin createTable(byte[] TABLENAME) throws IOException { - - Configuration config = TEST_UTIL.getConfiguration(); - HBaseAdmin admin = new HBaseAdmin(config); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLENAME)); HColumnDescriptor hcd = new HColumnDescriptor("value"); @@ -608,14 +605,13 @@ public class TestAdmin2 { private HRegionServer startAndWriteData(TableName tableName, byte[] value) throws IOException, InterruptedException { // When the hbase:meta table can be opened, the region servers are running - new HTable( - TEST_UTIL.getConfiguration(), TableName.META_TABLE_NAME).close(); + TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME).close(); // Create the test table and open it HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc); - Table table = new HTable(TEST_UTIL.getConfiguration(), tableName); + Table table = TEST_UTIL.getConnection().getTable(tableName); HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(tableName); for (int i = 1; i <= 256; i++) { // 256 writes should cause 8 log rolls @@ -716,7 +712,7 @@ public class TestAdmin2 { public void testGetRegion() throws Exception { // We use actual HBaseAdmin instance instead of going via Admin interface in // here because makes use of an internal HBA method (TODO: Fix.). - HBaseAdmin rawAdmin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + HBaseAdmin rawAdmin = TEST_UTIL.getHBaseAdmin(); final TableName tableName = TableName.valueOf("testGetRegion"); LOG.info("Started " + tableName); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationInterrupt.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationInterrupt.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationInterrupt.java index 6d58d03..072098e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationInterrupt.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationInterrupt.java @@ -82,9 +82,8 @@ public class TestClientOperationInterrupt { } admin.deleteTable(tableName); } - util.createTable(tableName, new byte[][]{dummy, test}); + Table ht = util.createTable(tableName, new byte[][]{dummy, test}); - Table ht = new HTable(conf, tableName); Put p = new Put(row1); p.add(dummy, dummy, dummy); ht.put(p); @@ -106,7 +105,7 @@ public class TestClientOperationInterrupt { @Override public void run() { try { - Table ht = new HTable(conf, tableName); + Table ht = util.getConnection().getTable(tableName); Result r = ht.get(new Get(row1)); noEx.incrementAndGet(); } catch (IOException e) { @@ -155,7 +154,7 @@ public class TestClientOperationInterrupt { Thread.sleep(1); } - Table ht = new HTable(conf, tableName); + Table ht = util.getConnection().getTable(tableName); Result r = ht.get(new Get(row1)); Assert.assertFalse(r.isEmpty()); } http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java index c04c4f2..d3986b2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientTimeouts.java @@ -98,12 +98,11 @@ public class TestClientTimeouts { // Ensure the HBaseAdmin uses a new connection by changing Configuration. Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); conf.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1)); - HBaseAdmin admin = null; + Admin admin = null; + Connection connection = null; try { - admin = new HBaseAdmin(conf); - Connection connection = admin.getConnection(); - assertFalse(connection == lastConnection); - lastConnection = connection; + connection = ConnectionFactory.createConnection(conf); + admin = connection.getAdmin(); // run some admin commands HBaseAdmin.checkHBaseAvailable(conf); admin.setBalancerRunning(false, false); @@ -112,10 +111,15 @@ public class TestClientTimeouts { // a MasterNotRunningException. It's a bug if we get other exceptions. lastFailed = true; } finally { - admin.close(); - if (admin.getConnection().isClosed()) { - rpcClient = (RandomTimeoutRpcClient) RpcClientFactory - .createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey()); + if(admin != null) { + admin.close(); + if (admin.getConnection().isClosed()) { + rpcClient = (RandomTimeoutRpcClient) RpcClientFactory + .createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey()); + } + } + if(connection != null) { + connection.close(); } } } http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java index 1e87e6e..e017bcc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java @@ -100,7 +100,7 @@ public class TestCloneSnapshotFromClient { // take an empty snapshot admin.snapshot(emptySnapshot, tableName); - HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName); + Table table = TEST_UTIL.getConnection().getTable(tableName); try { // enable table and insert data admin.enableTable(tableName); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index c6b5830..5dd691a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -182,8 +182,7 @@ public class TestFromClientSide { HTableDescriptor desc = new HTableDescriptor(TABLENAME); desc.addFamily(hcd); TEST_UTIL.getHBaseAdmin().createTable(desc); - Configuration c = TEST_UTIL.getConfiguration(); - Table h = new HTable(c, TABLENAME); + Table h = TEST_UTIL.getConnection().getTable(TABLENAME); long ts = System.currentTimeMillis(); Put p = new Put(T1, ts); @@ -415,7 +414,7 @@ public class TestFromClientSide { putRows(ht, 3, value2, keyPrefix1); putRows(ht, 3, value2, keyPrefix2); putRows(ht, 3, value2, keyPrefix3); - Table table = new HTable(TEST_UTIL.getConfiguration(), TABLE); + Table table = TEST_UTIL.getConnection().getTable(TABLE); System.out.println("Checking values for key: " + keyPrefix1); assertEquals("Got back incorrect number of rows from scan", 3, getNumberOfRows(keyPrefix1, value2, table)); @@ -641,8 +640,8 @@ public class TestFromClientSide { private Map<HRegionInfo, ServerName> splitTable(final HTable t) throws IOException, InterruptedException { // Split this table in two. - HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); - admin.split(t.getTableName()); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); + admin.split(t.getName()); admin.close(); Map<HRegionInfo, ServerName> regions = waitOnSplit(t); assertTrue(regions.size() > 1); @@ -1748,7 +1747,7 @@ public class TestFromClientSide { @Test public void testDeleteFamilyVersion() throws Exception { - HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); byte [] TABLE = Bytes.toBytes("testDeleteFamilyVersion"); byte [][] QUALIFIERS = makeNAscii(QUALIFIER, 1); @@ -1793,7 +1792,7 @@ public class TestFromClientSide { byte [][] VALUES = makeN(VALUE, 5); long [] ts = {1000, 2000, 3000, 4000, 5000}; - HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); Table ht = TEST_UTIL.createTable(TABLE, FAMILY, 5); Put put = null; Result result = null; @@ -3633,7 +3632,7 @@ public class TestFromClientSide { TableName TABLE = TableName.valueOf("testUpdatesWithMajorCompaction"); Table hTable = TEST_UTIL.createTable(TABLE, FAMILY, 10); - HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); // Write a column with values at timestamp 1, 2 and 3 byte[] row = Bytes.toBytes("row2"); @@ -3695,7 +3694,7 @@ public class TestFromClientSide { String tableName = "testMajorCompactionBetweenTwoUpdates"; byte [] TABLE = Bytes.toBytes(tableName); Table hTable = TEST_UTIL.createTable(TABLE, FAMILY, 10); - HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); // Write a column with values at timestamp 1, 2 and 3 byte[] row = Bytes.toBytes("row3"); @@ -4104,7 +4103,7 @@ public class TestFromClientSide { for (int i = 0; i < tables.length; i++) { TEST_UTIL.createTable(tables[i], FAMILY); } - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin admin = TEST_UTIL.getHBaseAdmin(); HTableDescriptor[] ts = admin.listTables(); HashSet<HTableDescriptor> result = new HashSet<HTableDescriptor>(ts.length); Collections.addAll(result, ts); @@ -4196,7 +4195,7 @@ public class TestFromClientSide { a.put(put); // open a new connection to A and a connection to b - Table newA = new HTable(TEST_UTIL.getConfiguration(), tableAname); + Table newA = TEST_UTIL.getConnection().getTable(tableAname); // copy data from A to B Scan scan = new Scan(); @@ -4216,7 +4215,7 @@ public class TestFromClientSide { } // Opening a new connection to A will cause the tables to be reloaded - Table anotherA = new HTable(TEST_UTIL.getConfiguration(), tableAname); + Table anotherA = TEST_UTIL.getConnection().getTable(tableAname); Get get = new Get(ROW); get.addFamily(HConstants.CATALOG_FAMILY); anotherA.get(get); @@ -4226,7 +4225,7 @@ public class TestFromClientSide { // to be reloaded. // Test user metadata - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration()); + Admin admin = TEST_UTIL.getHBaseAdmin(); // make a modifiable descriptor HTableDescriptor desc = new HTableDescriptor(a.getTableDescriptor()); // offline the table @@ -4984,12 +4983,9 @@ public class TestFromClientSide { public void testScanMetrics() throws Exception { TableName TABLENAME = TableName.valueOf("testScanMetrics"); - Configuration conf = TEST_UTIL.getConfiguration(); - TEST_UTIL.createTable(TABLENAME, FAMILY); - // Set up test table: // Create table: - HTable ht = new HTable(conf, TABLENAME); + HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY); // Create multiple regions for this table int numOfRegions = TEST_UTIL.createMultiRegions(ht, FAMILY); @@ -5203,7 +5199,7 @@ public class TestFromClientSide { byte [] family1 = Bytes.toBytes("f1"); byte [] family2 = Bytes.toBytes("f2"); try (HTable table = TEST_UTIL.createTable(TABLE, new byte[][] {family1, family2}, 10); - Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration())) { + Admin admin = TEST_UTIL.getHBaseAdmin()) { Map <HRegionInfo, ServerName> regionsMap = table.getRegionLocations(); assertEquals(1, regionsMap.size()); HRegionInfo regionInfo = regionsMap.keySet().iterator().next(); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java index 2729e97..680dcfb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java @@ -126,7 +126,7 @@ public class TestFromClientSide3 { int sfCount = sf.size(); // TODO: replace this api with a synchronous flush after HBASE-2949 - admin.flush(table.getTableName()); + admin.flush(table.getName()); // synchronously poll wait for a new storefile to appear (flush happened) while (ProtobufUtil.getStoreFiles( @@ -408,7 +408,7 @@ public class TestFromClientSide3 { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(Bytes.toBytes("test"))); desc.addFamily(new HColumnDescriptor(FAMILY)); admin.createTable(desc); - Table table = new HTable(TEST_UTIL.getConfiguration(), desc.getTableName()); + Table table = TEST_UTIL.getConnection().getTable(desc.getTableName()); Put put = new Put(ROW_BYTES); put.add(FAMILY, COL_QUAL, VAL_BYTES); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index 82a5c76..a86e4fa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -349,7 +349,8 @@ public class TestHCM { c2.setInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, 0); // Server do not really expire c2.setBoolean(RpcClient.SPECIFIC_WRITE_THREAD, allowsInterrupt); - final HTable table = new HTable(c2, tableName); + Connection connection = ConnectionFactory.createConnection(c2); + final HTable table = (HTable) connection.getTable(tableName); Put put = new Put(ROW); put.add(FAM_NAM, ROW, ROW); @@ -409,6 +410,7 @@ public class TestHCM { }); table.close(); + connection.close(); Assert.assertTrue("Unexpected exception is " + failed.get(), failed.get() == null); TEST_UTIL.getHBaseAdmin().setBalancerRunning(previousBalance, true); } @@ -429,7 +431,8 @@ public class TestHCM { c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); // Don't retry: retry = test failed c2.setInt(RpcClient.IDLE_TIME, idleTime); - final Table table = new HTable(c2, tableName); + Connection connection = ConnectionFactory.createConnection(c2); + final Table table = connection.getTable(tableName); Put put = new Put(ROW); put.add(FAM_NAM, ROW, ROW); @@ -465,15 +468,17 @@ public class TestHCM { LOG.info("we're done - time will change back"); table.close(); + + connection.close(); EnvironmentEdgeManager.reset(); TEST_UTIL.getHBaseAdmin().setBalancerRunning(previousBalance, true); } - /** - * Test that the connection to the dead server is cut immediately when we receive the - * notification. - * @throws Exception - */ + /** + * Test that the connection to the dead server is cut immediately when we receive the + * notification. + * @throws Exception + */ @Test public void testConnectionCut() throws Exception { if (!isJavaOk){ @@ -492,7 +497,8 @@ public class TestHCM { c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); c2.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 30 * 1000); - HTable table = new HTable(c2, tableName); + final Connection connection = ConnectionFactory.createConnection(c2); + final HTable table = (HTable) connection.getTable(tableName); Put p = new Put(FAM_NAM); p.add(FAM_NAM, FAM_NAM, FAM_NAM); @@ -538,6 +544,7 @@ public class TestHCM { } table.close(); + connection.close(); } protected static final AtomicBoolean syncBlockingFilter = new AtomicBoolean(false); @@ -597,7 +604,8 @@ public class TestHCM { TEST_UTIL.createTable(TABLE_NAME, FAM_NAM).close(); Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); - HTable table = new HTable(conf, TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(conf); + final HTable table = (HTable) connection.getTable(TABLE_NAME); TEST_UTIL.createMultiRegions(table, FAM_NAM); TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); @@ -773,6 +781,7 @@ public class TestHCM { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); table.close(); + connection.close(); } /** @@ -1240,7 +1249,7 @@ public class TestHCM { try { c1 = ConnectionManager.getConnectionInternal(config); LOG.info("HTable connection " + i + " " + c1); - Table table = new HTable(config, TABLE_NAME4, pool); + Table table = c1.getTable(TABLE_NAME4, pool); table.close(); LOG.info("HTable connection " + i + " closed " + c1); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMultiParallel.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMultiParallel.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMultiParallel.java index 47bb569..03d310f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMultiParallel.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMultiParallel.java @@ -170,7 +170,7 @@ public class TestMultiParallel { @Test(timeout=300000) public void testBatchWithGet() throws Exception { LOG.info("test=testBatchWithGet"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); // load test data List<Row> puts = constructPutRequests(); @@ -209,7 +209,7 @@ public class TestMultiParallel { @Test public void testBadFam() throws Exception { LOG.info("test=testBadFam"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); List<Row> actions = new ArrayList<Row>(); Put p = new Put(Bytes.toBytes("row1")); @@ -262,7 +262,7 @@ public class TestMultiParallel { private void doTestFlushCommits(boolean doAbort) throws Exception { // Load the data LOG.info("get new table"); - HTable table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); table.setAutoFlushTo(false); table.setWriteBufferSize(10 * 1024 * 1024); @@ -362,7 +362,7 @@ public class TestMultiParallel { @Test(timeout=300000) public void testBatchWithDelete() throws Exception { LOG.info("test=testBatchWithDelete"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); // Load some data List<Row> puts = constructPutRequests(); @@ -391,7 +391,7 @@ public class TestMultiParallel { @Test(timeout=300000) public void testHTableDeleteWithList() throws Exception { LOG.info("test=testHTableDeleteWithList"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); // Load some data List<Row> puts = constructPutRequests(); @@ -420,7 +420,7 @@ public class TestMultiParallel { @Test(timeout=300000) public void testBatchWithManyColsInOneRowGetAndPut() throws Exception { LOG.info("test=testBatchWithManyColsInOneRowGetAndPut"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); List<Row> puts = new ArrayList<Row>(); for (int i = 0; i < 100; i++) { @@ -461,7 +461,7 @@ public class TestMultiParallel { final byte[] QUAL2 = Bytes.toBytes("qual2"); final byte[] QUAL3 = Bytes.toBytes("qual3"); final byte[] QUAL4 = Bytes.toBytes("qual4"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); Delete d = new Delete(ONE_ROW); table.delete(d); Put put = new Put(ONE_ROW); @@ -583,7 +583,7 @@ public class TestMultiParallel { @Test(timeout=300000) public void testBatchWithMixedActions() throws Exception { LOG.info("test=testBatchWithMixedActions"); - Table table = new HTable(UTIL.getConfiguration(), TEST_TABLE); + Table table = UTIL.getConnection().getTable(TEST_TABLE); // Load some data to start Object[] results = table.batch(constructPutRequests()); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java index ca1254d..6d98c52 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicaWithCluster.java @@ -214,7 +214,7 @@ public class TestReplicaWithCluster { } HTU.getHBaseCluster().stopMaster(0); - Admin admin = new HBaseAdmin(HTU.getConfiguration()); + Admin admin = HTU.getHBaseAdmin(); nHdt =admin.getTableDescriptor(hdt.getTableName()); Assert.assertEquals("fams=" + Arrays.toString(nHdt.getColumnFamilies()), bHdt.getColumnFamilies().length + 1, nHdt.getColumnFamilies().length); @@ -255,7 +255,7 @@ public class TestReplicaWithCluster { Put p = new Put(row); p.add(row, row, row); - final Table table = new HTable(HTU.getConfiguration(), hdt.getTableName()); + final Table table = HTU.getConnection().getTable(hdt.getTableName()); table.put(p); HTU.getHBaseAdmin().flush(table.getName()); @@ -279,7 +279,7 @@ public class TestReplicaWithCluster { table.close(); LOG.info("stale get on the first cluster done. Now for the second."); - final Table table2 = new HTable(HTU.getConfiguration(), hdt.getTableName()); + final Table table2 = HTU.getConnection().getTable(hdt.getTableName()); Waiter.waitFor(HTU.getConfiguration(), 1000, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java index 5bbd8be..a5dce02 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java @@ -111,7 +111,7 @@ public class TestRestoreSnapshotFromClient { // take an empty snapshot admin.snapshot(emptySnapshot, tableName); - HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName); + Table table = TEST_UTIL.getConnection().getTable(tableName); // enable table and insert data admin.enableTable(tableName); SnapshotTestingUtils.loadData(TEST_UTIL, table, 500, FAMILY); @@ -175,7 +175,7 @@ public class TestRestoreSnapshotFromClient { public void testRestoreSchemaChange() throws Exception { byte[] TEST_FAMILY2 = Bytes.toBytes("cf2"); - HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName); + Table table = TEST_UTIL.getConnection().getTable(tableName); // Add one column family and put some data in it admin.disableTable(tableName); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java index 1740cc8..018bdc4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRpcControllerFactory.java @@ -131,7 +131,8 @@ public class TestRpcControllerFactory { // change one of the connection properties so we get a new HConnection with our configuration conf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT + 1); - Table table = new HTable(conf, name); + Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(name); table.setAutoFlushTo(false); byte[] row = Bytes.toBytes("row"); Put p = new Put(row); @@ -187,6 +188,7 @@ public class TestRpcControllerFactory { counter = doScan(table, scanInfo, counter); table.close(); + connection.close(); } int doScan(Table table, Scan scan, int expectedCount) throws IOException { http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java index b46312f..f9c8030 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java @@ -101,8 +101,7 @@ public class TestScannerTimeout { LOG.info("START ************ test2481"); Scan scan = new Scan(); scan.setCaching(1); - Table table = - new HTable(new Configuration(TEST_UTIL.getConfiguration()), TABLE_NAME); + Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME); ResultScanner r = table.getScanner(scan); int count = 0; try { @@ -141,7 +140,9 @@ public class TestScannerTimeout { // this new table Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT * 100); - Table higherScanTimeoutTable = new HTable(conf, TABLE_NAME); + + Connection connection = ConnectionFactory.createConnection(conf); + Table higherScanTimeoutTable = connection.getTable(TABLE_NAME); ResultScanner r = higherScanTimeoutTable.getScanner(scan); // This takes way less than SCANNER_TIMEOUT*100 rs.abort("die!"); @@ -149,6 +150,7 @@ public class TestScannerTimeout { assertEquals(NB_ROWS, results.length); r.close(); higherScanTimeoutTable.close(); + connection.close(); LOG.info("END ************ test2772"); } @@ -175,7 +177,8 @@ public class TestScannerTimeout { Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); conf.setInt( HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT*100); - Table table = new HTable(conf, TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(TABLE_NAME); LOG.info("START ************ TEST3686A---22"); ResultScanner r = table.getScanner(scan); @@ -193,6 +196,7 @@ public class TestScannerTimeout { assertEquals(NB_ROWS, count); r.close(); table.close(); + connection.close(); LOG.info("************ END TEST3686A"); } @@ -214,7 +218,8 @@ public class TestScannerTimeout { // this new table Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT * 100); - Table higherScanTimeoutTable = new HTable(conf, TABLE_NAME); + Connection connection = ConnectionFactory.createConnection(conf); + Table higherScanTimeoutTable = connection.getTable(TABLE_NAME); ResultScanner r = higherScanTimeoutTable.getScanner(scan); int count = 1; r.next(); @@ -226,6 +231,7 @@ public class TestScannerTimeout { assertEquals(NB_ROWS, count); r.close(); higherScanTimeoutTable.close(); + connection.close(); LOG.info("END ************ END test3686b"); } http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java index b4c6b3b..004ebee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotCloneIndependence.java @@ -18,19 +18,17 @@ package org.apache.hadoop.hbase.client; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy; import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; @@ -45,6 +43,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import java.util.List; + /** * Test to verify that the cloned table is independent of the table from which it was cloned */ @@ -211,7 +211,7 @@ public class TestSnapshotCloneIndependence { TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); admin.cloneSnapshot(snapshotName, cloneTableName); - try (Table clonedTable = new HTable(UTIL.getConfiguration(), cloneTableName)){ + try (Table clonedTable = UTIL.getConnection().getTable(cloneTableName)) { final int clonedTableRowCount = UTIL.countRows(clonedTable); Assert.assertEquals( http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java index c17da6d..079a588 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotFromClient.java @@ -149,7 +149,7 @@ public class TestSnapshotFromClient { SnapshotTestingUtils.assertNoSnapshots(admin); // put some stuff in the table - HTable table = new HTable(UTIL.getConfiguration(), TABLE_NAME); + Table table = UTIL.getConnection().getTable(TABLE_NAME); UTIL.loadTable(table, TEST_FAM); table.close(); @@ -185,7 +185,7 @@ public class TestSnapshotFromClient { SnapshotTestingUtils.assertNoSnapshots(admin); // put some stuff in the table - HTable table = new HTable(UTIL.getConfiguration(), TABLE_NAME); + Table table = UTIL.getConnection().getTable(TABLE_NAME); UTIL.loadTable(table, TEST_FAM, false); LOG.debug("FS state before disable:"); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotMetadata.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotMetadata.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotMetadata.java index 6f39d3b..e3c7ef9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotMetadata.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestSnapshotMetadata.java @@ -171,7 +171,7 @@ public class TestSnapshotMetadata { assertTrue(htd.getConfiguration().size() > 0); admin.createTable(htd); - Table original = new HTable(UTIL.getConfiguration(), originalTableName); + Table original = UTIL.getConnection().getTable(originalTableName); originalTableName = TableName.valueOf(sourceTableNameAsString); originalTableDescriptor = admin.getTableDescriptor(originalTableName); originalTableDescription = originalTableDescriptor.toStringCustomizedValues(); @@ -201,7 +201,7 @@ public class TestSnapshotMetadata { familiesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false); admin.cloneSnapshot(snapshotName, clonedTableName); - Table clonedTable = new HTable(UTIL.getConfiguration(), clonedTableName); + Table clonedTable = UTIL.getConnection().getTable(clonedTableName); HTableDescriptor cloneHtd = admin.getTableDescriptor(clonedTableName); assertEquals( originalTableDescription.replace(originalTableName.getNameAsString(),clonedTableNameAsString), @@ -265,7 +265,7 @@ public class TestSnapshotMetadata { List<byte[]> familiesWithDataList = new ArrayList<byte[]>(); List<byte[]> emptyFamiliesList = new ArrayList<byte[]>(); if (addData) { - HTable original = new HTable(UTIL.getConfiguration(), originalTableName); + Table original = UTIL.getConnection().getTable(originalTableName); UTIL.loadTable(original, familyForUpdate); // family arbitrarily chosen original.close(); @@ -310,7 +310,7 @@ public class TestSnapshotMetadata { admin.enableTable(originalTableName); // verify that the descrption is reverted - Table original = new HTable(UTIL.getConfiguration(), originalTableName); + Table original = UTIL.getConnection().getTable(originalTableName); try { assertTrue(originalTableDescriptor.equals(admin.getTableDescriptor(originalTableName))); assertTrue(originalTableDescriptor.equals(original.getTableDescriptor())); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java index 1e3d1cf..0f0baff 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java @@ -92,7 +92,7 @@ public class TestTableSnapshotScanner { Admin admin = util.getHBaseAdmin(); // put some stuff in the table - HTable table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); util.loadTable(table, FAMILIES); Path rootDir = FSUtils.getRootDir(util.getConfiguration()); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java index f4ad44c..96da03a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java @@ -82,7 +82,7 @@ public class TestConstraint { Constraints.add(desc, CheckWasRunConstraint.class); util.getHBaseAdmin().createTable(desc); - Table table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); try { // test that we don't fail on a valid put Put put = new Put(row1); @@ -114,7 +114,7 @@ public class TestConstraint { Constraints.add(desc, AllFailConstraint.class); util.getHBaseAdmin().createTable(desc); - Table table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); // test that we do fail on violation Put put = new Put(row1); @@ -157,7 +157,7 @@ public class TestConstraint { Constraints.disableConstraint(desc, AllFailConstraint.class); util.getHBaseAdmin().createTable(desc); - Table table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); try { // test that we don't fail because its disabled Put put = new Put(row1); @@ -189,7 +189,7 @@ public class TestConstraint { Constraints.disable(desc); util.getHBaseAdmin().createTable(desc); - Table table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); try { // test that we do fail on violation Put put = new Put(row1); @@ -221,7 +221,7 @@ public class TestConstraint { CheckWasRunConstraint.wasRun = false; util.getHBaseAdmin().createTable(desc); - Table table = new HTable(util.getConfiguration(), tableName); + Table table = util.getConnection().getTable(tableName); // test that we do fail on violation Put put = new Put(row1); http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java index c99a1f6..a5ee4c1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestBatchCoprocessorEndpoint.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.TreeMap; import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.testclassification.CoprocessorTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -86,14 +87,14 @@ public class TestBatchCoprocessorEndpoint { conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, ProtobufCoprocessorService.class.getName()); util.startMiniCluster(2); - Admin admin = new HBaseAdmin(conf); + Admin admin = util.getHBaseAdmin(); HTableDescriptor desc = new HTableDescriptor(TEST_TABLE); desc.addFamily(new HColumnDescriptor(TEST_FAMILY)); admin.createTable(desc, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]}); util.waitUntilAllRegionsAssigned(TEST_TABLE); admin.close(); - Table table = new HTable(conf, TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); for (int i = 0; i < ROWSIZE; i++) { Put put = new Put(ROWS[i]); put.add(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i)); @@ -109,7 +110,7 @@ public class TestBatchCoprocessorEndpoint { @Test public void testAggregationNullResponse() throws Throwable { - Table table = new HTable(util.getConfiguration(), TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); ColumnAggregationWithNullResponseProtos.SumRequest.Builder builder = ColumnAggregationWithNullResponseProtos.SumRequest .newBuilder(); @@ -162,7 +163,7 @@ public class TestBatchCoprocessorEndpoint { @Test public void testAggregationWithReturnValue() throws Throwable { - Table table = new HTable(util.getConfiguration(), TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); Map<byte[], SumResponse> results = sum(table, TEST_FAMILY, TEST_QUALIFIER, ROWS[0], ROWS[ROWS.length - 1]); int sumResult = 0; @@ -198,7 +199,7 @@ public class TestBatchCoprocessorEndpoint { @Test public void testAggregation() throws Throwable { - Table table = new HTable(util.getConfiguration(), TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); Map<byte[], SumResponse> results = sum(table, TEST_FAMILY, TEST_QUALIFIER, ROWS[0], ROWS[ROWS.length - 1]); int sumResult = 0; @@ -231,7 +232,7 @@ public class TestBatchCoprocessorEndpoint { @Test public void testAggregationWithErrors() throws Throwable { - Table table = new HTable(util.getConfiguration(), TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); final Map<byte[], ColumnAggregationWithErrorsProtos.SumResponse> results = Collections.synchronizedMap( new TreeMap<byte[], ColumnAggregationWithErrorsProtos.SumResponse>( http://git-wip-us.apache.org/repos/asf/hbase/blob/9246af8d/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorEndpoint.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorEndpoint.java index 64732b0..c04499d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorEndpoint.java @@ -94,14 +94,14 @@ public class TestCoprocessorEndpoint { conf.setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, ProtobufCoprocessorService.class.getName()); util.startMiniCluster(2); - Admin admin = new HBaseAdmin(conf); + Admin admin = util.getHBaseAdmin(); HTableDescriptor desc = new HTableDescriptor(TEST_TABLE); desc.addFamily(new HColumnDescriptor(TEST_FAMILY)); admin.createTable(desc, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]}); util.waitUntilAllRegionsAssigned(TEST_TABLE); admin.close(); - Table table = new HTable(conf, TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); for (int i = 0; i < ROWSIZE; i++) { Put put = new Put(ROWS[i]); put.add(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i)); @@ -140,7 +140,7 @@ public class TestCoprocessorEndpoint { @Test public void testAggregation() throws Throwable { - Table table = new HTable(util.getConfiguration(), TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); Map<byte[], Long> results = sum(table, TEST_FAMILY, TEST_QUALIFIER, ROWS[0], ROWS[ROWS.length-1]); int sumResult = 0; @@ -174,7 +174,7 @@ public class TestCoprocessorEndpoint { @Test public void testCoprocessorService() throws Throwable { - HTable table = new HTable(util.getConfiguration(), TEST_TABLE); + HTable table = (HTable) util.getConnection().getTable(TEST_TABLE); NavigableMap<HRegionInfo,ServerName> regions = table.getRegionLocations(); final TestProtos.EchoRequestProto request = @@ -248,7 +248,7 @@ public class TestCoprocessorEndpoint { @Test public void testCoprocessorServiceNullResponse() throws Throwable { - HTable table = new HTable(util.getConfiguration(), TEST_TABLE); + HTable table = (HTable) util.getConnection().getTable(TEST_TABLE); NavigableMap<HRegionInfo,ServerName> regions = table.getRegionLocations(); final TestProtos.EchoRequestProto request = @@ -299,7 +299,7 @@ public class TestCoprocessorEndpoint { Configuration configuration = new Configuration(util.getConfiguration()); // Make it not retry forever configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); - Table table = new HTable(configuration, TEST_TABLE); + Table table = util.getConnection().getTable(TEST_TABLE); try { CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);
