From 04ee3b2f250a47147d0ea47a3323d8312e552aeb Mon Sep 17 00:00:00 2001 From: larsh Date: Wed, 5 Mar 2014 18:21:37 +0000 Subject: [PATCH] HBASE-10594 Speed up TestRestoreSnapshotFromClient. git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1574602 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/client/TestRestoreSnapshotFromClient.java | 11 ++--------- .../hadoop/hbase/snapshot/SnapshotTestingUtils.java | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) 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 966a594d291..296bea69385 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 @@ -124,13 +124,6 @@ public class TestRestoreSnapshotFromClient { admin.enableTable(tableName); SnapshotTestingUtils.loadData(TEST_UTIL, table, 500, FAMILY); snapshot1Rows = TEST_UTIL.countRows(table); - admin.disableTable(tableName); - - // take a snapshot of the updated table - admin.snapshot(snapshotName1, tableName); - - // re-enable table - admin.enableTable(tableName); table.close(); } @@ -144,9 +137,9 @@ public class TestRestoreSnapshotFromClient { @Test public void testRestoreSnapshot() throws IOException { SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); - - // Restore from snapshot-0 admin.disableTable(tableName); + admin.snapshot(snapshotName1, tableName); + // Restore from snapshot-0 admin.restoreSnapshot(snapshotName0); admin.enableTable(tableName); SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java index 3133cd41ecb..681fbba17f4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java @@ -73,6 +73,7 @@ import com.google.protobuf.ServiceException; public class SnapshotTestingUtils { private static final Log LOG = LogFactory.getLog(SnapshotTestingUtils.class); + private static byte[] KEYS = Bytes.toBytes("0123456789"); /** * Assert that we don't have any snapshots lists @@ -455,14 +456,13 @@ public class SnapshotTestingUtils { HColumnDescriptor hcd = new HColumnDescriptor(family); htd.addFamily(hcd); } - byte[][] splitKeys = new byte[14][]; - byte[] hex = Bytes.toBytes("123456789abcde"); + byte[][] splitKeys = new byte[KEYS.length-2][]; for (int i = 0; i < splitKeys.length; ++i) { - splitKeys[i] = new byte[] { hex[i] }; + splitKeys[i] = new byte[] { KEYS[i+1] }; } util.getHBaseAdmin().createTable(htd, splitKeys); waitForTableToBeOnline(util, tableName); - assertEquals(15, util.getHBaseAdmin().getTableRegions(tableName).size()); + assertEquals(KEYS.length-1, util.getHBaseAdmin().getTableRegions(tableName).size()); } public static void loadData(final HBaseTestingUtility util, final TableName tableName, int rows, @@ -475,8 +475,8 @@ public class SnapshotTestingUtils { table.setAutoFlush(false, true); // Ensure one row per region - assertTrue(rows >= 16); - for (byte k0: Bytes.toBytes("0123456789abcdef")) { + assertTrue(rows >= KEYS.length); + for (byte k0: KEYS) { byte[] k = new byte[] { k0 }; byte[] value = Bytes.add(Bytes.toBytes(System.currentTimeMillis()), k); byte[] key = Bytes.add(k, Bytes.toBytes(MD5Hash.getMD5AsHex(value)));