From fc7a6a64c2b5c250fee3b9dadb2bed99904b4a74 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Mon, 15 Oct 2018 21:28:34 +0800 Subject: [PATCH] HBASE-21311 Split TestRestoreSnapshotFromClient --- ...omClientAfterSplittingRegionsTestBase.java | 52 +++ ...apshotFromClientAfterTruncateTestBase.java | 48 +++ ...estoreSnapshotFromClientCloneTestBase.java | 65 +++ ...tFromClientGetCompactionStateTestBase.java | 44 ++ ...napshotFromClientSchemaChangeTestBase.java | 105 +++++ ...storeSnapshotFromClientSimpleTestBase.java | 80 ++++ .../RestoreSnapshotFromClientTestBase.java | 150 +++++++ ...apshotFromClientAfterSplittingRegions.java | 67 +++ ...estoreSnapshotFromClientAfterTruncate.java | 67 +++ ...TestMobRestoreSnapshotFromClientClone.java | 66 +++ ...eSnapshotFromClientGetCompactionState.java | 67 +++ ...estoreSnapshotFromClientSchemaChange.java} | 33 +- ...estMobRestoreSnapshotFromClientSimple.java | 67 +++ .../client/TestRestoreSnapshotFromClient.java | 396 ------------------ ...apshotFromClientAfterSplittingRegions.java | 53 +++ ...estoreSnapshotFromClientAfterTruncate.java | 53 +++ .../TestRestoreSnapshotFromClientClone.java | 52 +++ ...eSnapshotFromClientGetCompactionState.java | 53 +++ ...RestoreSnapshotFromClientSchemaChange.java | 53 +++ .../TestRestoreSnapshotFromClientSimple.java | 52 +++ ...eSnapshotFromClientWithRegionReplicas.java | 13 +- 21 files changed, 1214 insertions(+), 422 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterSplittingRegionsTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterTruncateTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientCloneTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientGetCompactionStateTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSchemaChangeTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSimpleTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientTestBase.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterSplittingRegions.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterTruncate.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientClone.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientGetCompactionState.java rename hbase-server/src/test/java/org/apache/hadoop/hbase/client/{TestMobRestoreSnapshotFromClient.java => TestMobRestoreSnapshotFromClientSchemaChange.java} (72%) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSimple.java delete mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterSplittingRegions.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterTruncate.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientClone.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientGetCompactionState.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSchemaChange.java create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSimple.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterSplittingRegionsTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterSplittingRegionsTestBase.java new file mode 100644 index 00000000000..59f0fd41087 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterSplittingRegionsTestBase.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import java.util.List; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.junit.Test; + +public class RestoreSnapshotFromClientAfterSplittingRegionsTestBase + extends RestoreSnapshotFromClientTestBase { + + @Test + public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException { + List regionInfos = admin.getRegions(tableName); + RegionReplicaUtil.removeNonDefaultRegions(regionInfos); + + // Split the first region + splitRegion(regionInfos.get(0)); + + // Take a snapshot + admin.snapshot(snapshotName1, tableName); + + // Load more data + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); + + // Split the second region + splitRegion(regionInfos.get(1)); + + // Restore the snapshot + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName1); + admin.enableTable(tableName); + + verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterTruncateTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterTruncateTestBase.java new file mode 100644 index 00000000000..11fd6f196c1 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientAfterTruncateTestBase.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.junit.Test; + +public class RestoreSnapshotFromClientAfterTruncateTestBase + extends RestoreSnapshotFromClientTestBase { + + @Test + public void testRestoreSnapshotAfterTruncate() throws Exception { + TableName tableName = TableName.valueOf(getValidMethodName()); + SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); + int numOfRows = 0; + + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { + numOfRows = countRows(table); + } + // take snapshot + admin.snapshot("snap", tableName); + admin.disableTable(tableName); + admin.truncateTable(tableName, false); + admin.disableTable(tableName); + admin.restoreSnapshot("snap"); + + admin.enableTable(tableName); + verifyRowCount(TEST_UTIL, tableName, numOfRows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientCloneTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientCloneTestBase.java new file mode 100644 index 00000000000..07625f9638f --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientCloneTestBase.java @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.junit.Test; + +public class RestoreSnapshotFromClientCloneTestBase extends RestoreSnapshotFromClientTestBase { + + @Test + public void testCloneSnapshotOfCloned() throws IOException, InterruptedException { + TableName clonedTableName = + TableName.valueOf(getValidMethodName() + "-" + System.currentTimeMillis()); + admin.cloneSnapshot(snapshotName0, clonedTableName); + verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas()); + admin.disableTable(clonedTableName); + admin.snapshot(snapshotName2, clonedTableName); + TEST_UTIL.deleteTable(clonedTableName); + waitCleanerRun(); + + admin.cloneSnapshot(snapshotName2, clonedTableName); + verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas()); + TEST_UTIL.deleteTable(clonedTableName); + } + + @Test + public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException { + TEST_UTIL.deleteTable(tableName); + waitCleanerRun(); + + admin.cloneSnapshot(snapshotName0, tableName); + verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + waitCleanerRun(); + + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName0); + admin.enableTable(tableName); + verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + } + + private void waitCleanerRun() throws InterruptedException { + TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting(); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientGetCompactionStateTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientGetCompactionStateTestBase.java new file mode 100644 index 00000000000..03c908fd068 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientGetCompactionStateTestBase.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import org.junit.Test; + +public class RestoreSnapshotFromClientGetCompactionStateTestBase + extends RestoreSnapshotFromClientTestBase { + + @Test + public void testGetCompactionStateAfterRestoringSnapshot() + throws IOException, InterruptedException { + // Take a snapshot + admin.snapshot(snapshotName1, tableName); + + // Restore the snapshot + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName1); + + // Get the compaction state of the restored table + CompactionState compactionState = admin.getCompactionState(tableName); + + // The compactionState should be NONE because the table is disabled + assertEquals(CompactionState.NONE, compactionState); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSchemaChangeTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSchemaChangeTestBase.java new file mode 100644 index 00000000000..7f88f6ed3cc --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSchemaChangeTestBase.java @@ -0,0 +1,105 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.master.MasterFileSystem; +import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSUtils; +import org.junit.Test; + +public class RestoreSnapshotFromClientSchemaChangeTestBase + extends RestoreSnapshotFromClientTestBase { + + private Set getFamiliesFromFS(final TableName tableName) throws IOException { + MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); + Set families = new HashSet<>(); + Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), tableName); + for (Path regionDir : FSUtils.getRegionDirs(mfs.getFileSystem(), tableDir)) { + for (Path familyDir : FSUtils.getFamilyDirs(mfs.getFileSystem(), regionDir)) { + families.add(familyDir.getName()); + } + } + return families; + } + + protected ColumnFamilyDescriptor getTestRestoreSchemaChangeHCD() { + return ColumnFamilyDescriptorBuilder.of(TEST_FAMILY2); + } + + @Test + public void testRestoreSchemaChange() throws Exception { + Table table = TEST_UTIL.getConnection().getTable(tableName); + + // Add one column family and put some data in it + admin.disableTable(tableName); + admin.addColumnFamily(tableName, getTestRestoreSchemaChangeHCD()); + admin.enableTable(tableName); + assertEquals(2, table.getDescriptor().getColumnFamilyCount()); + TableDescriptor htd = admin.getDescriptor(tableName); + assertEquals(2, htd.getColumnFamilyCount()); + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, TEST_FAMILY2); + long snapshot2Rows = snapshot1Rows + 500L; + assertEquals(snapshot2Rows, countRows(table)); + assertEquals(500, countRows(table, TEST_FAMILY2)); + Set fsFamilies = getFamiliesFromFS(tableName); + assertEquals(2, fsFamilies.size()); + + // Take a snapshot + admin.disableTable(tableName); + admin.snapshot(snapshotName2, tableName); + + // Restore the snapshot (without the cf) + admin.restoreSnapshot(snapshotName0); + admin.enableTable(tableName); + assertEquals(1, table.getDescriptor().getColumnFamilyCount()); + try { + countRows(table, TEST_FAMILY2); + fail("family '" + Bytes.toString(TEST_FAMILY2) + "' should not exists"); + } catch (NoSuchColumnFamilyException e) { + // expected + } + assertEquals(snapshot0Rows, countRows(table)); + htd = admin.getDescriptor(tableName); + assertEquals(1, htd.getColumnFamilyCount()); + fsFamilies = getFamiliesFromFS(tableName); + assertEquals(1, fsFamilies.size()); + + // Restore back the snapshot (with the cf) + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName2); + admin.enableTable(tableName); + htd = admin.getDescriptor(tableName); + assertEquals(2, htd.getColumnFamilyCount()); + assertEquals(2, table.getDescriptor().getColumnFamilyCount()); + assertEquals(500, countRows(table, TEST_FAMILY2)); + assertEquals(snapshot2Rows, countRows(table)); + fsFamilies = getFamiliesFromFS(tableName); + assertEquals(2, fsFamilies.size()); + table.close(); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSimpleTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSimpleTestBase.java new file mode 100644 index 00000000000..f4f2698a948 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientSimpleTestBase.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import java.io.IOException; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Test; + +public class RestoreSnapshotFromClientSimpleTestBase extends RestoreSnapshotFromClientTestBase { + + @Test + public void testRestoreSnapshot() throws IOException { + verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); + admin.disableTable(tableName); + admin.snapshot(snapshotName1, tableName); + // Restore from snapshot-0 + admin.restoreSnapshot(snapshotName0); + admin.enableTable(tableName); + verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + + // Restore from emptySnapshot + admin.disableTable(tableName); + admin.restoreSnapshot(emptySnapshot); + admin.enableTable(tableName); + verifyRowCount(TEST_UTIL, tableName, 0); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + + // Restore from snapshot-1 + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName1); + admin.enableTable(tableName); + verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + + // Restore from snapshot-1 + TEST_UTIL.deleteTable(tableName); + admin.restoreSnapshot(snapshotName1); + verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + } + + @Test + public void testCorruptedSnapshot() throws IOException, InterruptedException { + SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, Bytes.toString(snapshotName0)); + TableName cloneName = + TableName.valueOf(getValidMethodName() + "-" + System.currentTimeMillis()); + try { + admin.cloneSnapshot(snapshotName0, cloneName); + fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()"); + } catch (CorruptedSnapshotException e) { + // Got the expected corruption exception. + // check for no references of the cloned table. + assertFalse(admin.tableExists(cloneName)); + } catch (Exception e) { + fail("Expected CorruptedSnapshotException got: " + e); + } + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientTestBase.java new file mode 100644 index 00000000000..047640fe7d7 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/RestoreSnapshotFromClientTestBase.java @@ -0,0 +1,150 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; +import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.rules.TestName; + +/** + * Base class for testing restore snapshot + */ +public class RestoreSnapshotFromClientTestBase { + protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + + protected final byte[] FAMILY = Bytes.toBytes("cf"); + protected final byte[] TEST_FAMILY2 = Bytes.toBytes("cf2"); + + protected TableName tableName; + protected byte[] emptySnapshot; + protected byte[] snapshotName0; + protected byte[] snapshotName1; + protected byte[] snapshotName2; + protected int snapshot0Rows; + protected int snapshot1Rows; + protected Admin admin; + + @Rule + public TestName name = new TestName(); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); + TEST_UTIL.getConfiguration().setInt("hbase.hstore.compactionThreshold", 10); + TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); + TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); + TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); + TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + /** + * Initialize the tests with a table filled with some data and two snapshots (snapshotName0, + * snapshotName1) of different states. The tableName, snapshotNames and the number of rows in the + * snapshot are initialized. + */ + @Before + public void setup() throws Exception { + this.admin = TEST_UTIL.getAdmin(); + + long tid = System.currentTimeMillis(); + tableName = TableName.valueOf(getValidMethodName() + "-" + tid); + emptySnapshot = Bytes.toBytes("emptySnaptb-" + tid); + snapshotName0 = Bytes.toBytes("snaptb0-" + tid); + snapshotName1 = Bytes.toBytes("snaptb1-" + tid); + snapshotName2 = Bytes.toBytes("snaptb2-" + tid); + + // create Table and disable it + createTable(); + admin.disableTable(tableName); + + // take an empty snapshot + admin.snapshot(emptySnapshot, tableName); + + // enable table and insert data + admin.enableTable(tableName); + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { + snapshot0Rows = countRows(table); + } + admin.disableTable(tableName); + + // take a snapshot + admin.snapshot(snapshotName0, tableName); + + // enable table and insert more data + admin.enableTable(tableName); + SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { + snapshot1Rows = countRows(table); + } + } + + protected void createTable() throws Exception { + SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @After + public void tearDown() throws Exception { + TEST_UTIL.deleteTable(tableName); + SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getAdmin()); + SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL); + } + + protected int getNumReplicas() { + return 1; + } + + protected int countRows(Table table, byte[]... families) throws IOException { + return TEST_UTIL.countRows(table, families); + } + + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + SnapshotTestingUtils.verifyRowCount(util, tableName, expectedRows); + } + + protected final void splitRegion(RegionInfo regionInfo) throws IOException { + byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1); + admin.split(regionInfo.getTable(), splitPoints[1]); + } + + protected final String getValidMethodName() { + return name.getMethodName().replaceAll("[^0-9A-Za-z_]", "_"); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterSplittingRegions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterSplittingRegions.java new file mode 100644 index 00000000000..1135bd3e0a5 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterSplittingRegions.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.mob.MobConstants; +import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; + +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientAfterSplittingRegions + extends RestoreSnapshotFromClientAfterSplittingRegionsTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientAfterSplittingRegions.class); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + RestoreSnapshotFromClientTestBase.setupConf(conf); + TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); + } + + @Override + protected void createTable() throws Exception { + MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @Override + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); + } + + @Override + protected int countRows(Table table, byte[]... families) throws IOException { + return MobSnapshotTestingUtils.countMobRows(table, families); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterTruncate.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterTruncate.java new file mode 100644 index 00000000000..0abe83d8937 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientAfterTruncate.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.mob.MobConstants; +import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; + +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientAfterTruncate + extends RestoreSnapshotFromClientAfterTruncateTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientAfterTruncate.class); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + RestoreSnapshotFromClientTestBase.setupConf(conf); + TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); + } + + @Override + protected void createTable() throws Exception { + MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @Override + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); + } + + @Override + protected int countRows(Table table, byte[]... families) throws IOException { + return MobSnapshotTestingUtils.countMobRows(table, families); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientClone.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientClone.java new file mode 100644 index 00000000000..475236f821a --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientClone.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.mob.MobConstants; +import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; + +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientClone extends RestoreSnapshotFromClientCloneTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientClone.class); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + RestoreSnapshotFromClientTestBase.setupConf(conf); + TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); + } + + @Override + protected void createTable() throws Exception { + MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @Override + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); + } + + @Override + protected int countRows(Table table, byte[]... families) throws IOException { + return MobSnapshotTestingUtils.countMobRows(table, families); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientGetCompactionState.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientGetCompactionState.java new file mode 100644 index 00000000000..c4d6ec3ab29 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientGetCompactionState.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.mob.MobConstants; +import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; + +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientGetCompactionState + extends RestoreSnapshotFromClientGetCompactionStateTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientGetCompactionState.class); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + RestoreSnapshotFromClientTestBase.setupConf(conf); + TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); + } + + @Override + protected void createTable() throws Exception { + MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @Override + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); + } + + @Override + protected int countRows(Table table, byte[]... families) throws IOException { + return MobSnapshotTestingUtils.countMobRows(table, families); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSchemaChange.java similarity index 72% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClient.java rename to hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSchemaChange.java index ae8175c3c7d..3e3233170ec 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSchemaChange.java @@ -21,7 +21,6 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.mob.MobConstants; import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; @@ -31,15 +30,13 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.experimental.categories.Category; -/** - * Test restore snapshots from the client - */ -@Category({ClientTests.class, LargeTests.class}) -public class TestMobRestoreSnapshotFromClient extends TestRestoreSnapshotFromClient { +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientSchemaChange + extends RestoreSnapshotFromClientSchemaChangeTestBase { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClient.class); + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientSchemaChange.class); @BeforeClass public static void setupCluster() throws Exception { @@ -48,7 +45,7 @@ public class TestMobRestoreSnapshotFromClient extends TestRestoreSnapshotFromCli } protected static void setupConf(Configuration conf) { - TestRestoreSnapshotFromClient.setupConf(conf); + RestoreSnapshotFromClientTestBase.setupConf(conf); TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); } @@ -58,21 +55,19 @@ public class TestMobRestoreSnapshotFromClient extends TestRestoreSnapshotFromCli } @Override - protected HColumnDescriptor getTestRestoreSchemaChangeHCD() { - HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2); - hcd.setMobEnabled(true); - hcd.setMobThreshold(3L); - return hcd; - } - - @Override - protected void verifyRowCount(final HBaseTestingUtility util, final TableName tableName, - long expectedRows) throws IOException { + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); } @Override - protected int countRows(final Table table, final byte[]... families) throws IOException { + protected int countRows(Table table, byte[]... families) throws IOException { return MobSnapshotTestingUtils.countMobRows(table, families); } + + @Override + protected ColumnFamilyDescriptor getTestRestoreSchemaChangeHCD() { + return ColumnFamilyDescriptorBuilder.newBuilder(TEST_FAMILY2).setMobEnabled(true) + .setMobThreshold(3L).build(); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSimple.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSimple.java new file mode 100644 index 00000000000..c0e7379c001 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobRestoreSnapshotFromClientSimple.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.mob.MobConstants; +import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; + +@Category({ LargeTests.class, ClientTests.class }) +public class TestMobRestoreSnapshotFromClientSimple + extends RestoreSnapshotFromClientSimpleTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMobRestoreSnapshotFromClientSimple.class); + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(TEST_UTIL.getConfiguration()); + TEST_UTIL.startMiniCluster(3); + } + + protected static void setupConf(Configuration conf) { + RestoreSnapshotFromClientTestBase.setupConf(conf); + TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); + } + + @Override + protected void createTable() throws Exception { + MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + } + + @Override + protected void verifyRowCount(HBaseTestingUtility util, TableName tableName, long expectedRows) + throws IOException { + MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); + } + + @Override + protected int countRows(Table table, byte[]... families) throws IOException { + return MobSnapshotTestingUtils.countMobRows(table, families); + } +} 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 deleted file mode 100644 index 138ec44e274..00000000000 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java +++ /dev/null @@ -1,396 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.master.MasterFileSystem; -import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; -import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; -import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException; -import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; -import org.apache.hadoop.hbase.testclassification.ClientTests; -import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.FSUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; - -/** - * Test restore snapshots from the client - */ -@Category({LargeTests.class, ClientTests.class}) -public class TestRestoreSnapshotFromClient { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRestoreSnapshotFromClient.class); - - protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - - protected final byte[] FAMILY = Bytes.toBytes("cf"); - protected final byte[] TEST_FAMILY2 = Bytes.toBytes("cf2"); - - protected TableName tableName; - protected byte[] emptySnapshot; - protected byte[] snapshotName0; - protected byte[] snapshotName1; - protected byte[] snapshotName2; - protected int snapshot0Rows; - protected int snapshot1Rows; - protected Admin admin; - - @Rule - public TestName name = new TestName(); - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(TEST_UTIL.getConfiguration()); - TEST_UTIL.startMiniCluster(3); - } - - protected static void setupConf(Configuration conf) { - TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); - TEST_UTIL.getConfiguration().setInt("hbase.hstore.compactionThreshold", 10); - TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); - TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); - TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); - TEST_UTIL.getConfiguration().setBoolean( - "hbase.master.enabletable.roundrobin", true); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - TEST_UTIL.shutdownMiniCluster(); - } - - /** - * Initialize the tests with a table filled with some data - * and two snapshots (snapshotName0, snapshotName1) of different states. - * The tableName, snapshotNames and the number of rows in the snapshot are initialized. - */ - @Before - public void setup() throws Exception { - this.admin = TEST_UTIL.getAdmin(); - - long tid = System.currentTimeMillis(); - tableName = TableName.valueOf(name.getMethodName() + "-" + tid); - emptySnapshot = Bytes.toBytes("emptySnaptb-" + tid); - snapshotName0 = Bytes.toBytes("snaptb0-" + tid); - snapshotName1 = Bytes.toBytes("snaptb1-" + tid); - snapshotName2 = Bytes.toBytes("snaptb2-" + tid); - - // create Table and disable it - createTable(); - admin.disableTable(tableName); - - // take an empty snapshot - admin.snapshot(emptySnapshot, tableName); - - // enable table and insert data - admin.enableTable(tableName); - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); - try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { - snapshot0Rows = countRows(table); - } - admin.disableTable(tableName); - - // take a snapshot - admin.snapshot(snapshotName0, tableName); - - // enable table and insert more data - admin.enableTable(tableName); - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); - try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { - snapshot1Rows = countRows(table); - } - } - - protected void createTable() throws Exception { - SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); - } - - @After - public void tearDown() throws Exception { - TEST_UTIL.deleteTable(tableName); - SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getAdmin()); - SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL); - } - - @Test - public void testRestoreSnapshot() throws IOException { - verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); - admin.disableTable(tableName); - admin.snapshot(snapshotName1, tableName); - // Restore from snapshot-0 - admin.restoreSnapshot(snapshotName0); - admin.enableTable(tableName); - verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - - // Restore from emptySnapshot - admin.disableTable(tableName); - admin.restoreSnapshot(emptySnapshot); - admin.enableTable(tableName); - verifyRowCount(TEST_UTIL, tableName, 0); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - - // Restore from snapshot-1 - admin.disableTable(tableName); - admin.restoreSnapshot(snapshotName1); - admin.enableTable(tableName); - verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - - // Restore from snapshot-1 - TEST_UTIL.deleteTable(tableName); - admin.restoreSnapshot(snapshotName1); - verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - } - - protected int getNumReplicas() { - return 1; - } - - protected HColumnDescriptor getTestRestoreSchemaChangeHCD() { - return new HColumnDescriptor(TEST_FAMILY2); - } - - @Test - public void testRestoreSchemaChange() throws Exception { - Table table = TEST_UTIL.getConnection().getTable(tableName); - - // Add one column family and put some data in it - admin.disableTable(tableName); - admin.addColumnFamily(tableName, getTestRestoreSchemaChangeHCD()); - admin.enableTable(tableName); - assertEquals(2, table.getTableDescriptor().getFamilies().size()); - HTableDescriptor htd = admin.getTableDescriptor(tableName); - assertEquals(2, htd.getFamilies().size()); - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, TEST_FAMILY2); - long snapshot2Rows = snapshot1Rows + 500L; - assertEquals(snapshot2Rows, countRows(table)); - assertEquals(500, countRows(table, TEST_FAMILY2)); - Set fsFamilies = getFamiliesFromFS(tableName); - assertEquals(2, fsFamilies.size()); - - // Take a snapshot - admin.disableTable(tableName); - admin.snapshot(snapshotName2, tableName); - - // Restore the snapshot (without the cf) - admin.restoreSnapshot(snapshotName0); - admin.enableTable(tableName); - assertEquals(1, table.getTableDescriptor().getFamilies().size()); - try { - countRows(table, TEST_FAMILY2); - fail("family '" + Bytes.toString(TEST_FAMILY2) + "' should not exists"); - } catch (NoSuchColumnFamilyException e) { - // expected - } - assertEquals(snapshot0Rows, countRows(table)); - htd = admin.getTableDescriptor(tableName); - assertEquals(1, htd.getFamilies().size()); - fsFamilies = getFamiliesFromFS(tableName); - assertEquals(1, fsFamilies.size()); - - // Restore back the snapshot (with the cf) - admin.disableTable(tableName); - admin.restoreSnapshot(snapshotName2); - admin.enableTable(tableName); - htd = admin.getTableDescriptor(tableName); - assertEquals(2, htd.getFamilies().size()); - assertEquals(2, table.getTableDescriptor().getFamilies().size()); - assertEquals(500, countRows(table, TEST_FAMILY2)); - assertEquals(snapshot2Rows, countRows(table)); - fsFamilies = getFamiliesFromFS(tableName); - assertEquals(2, fsFamilies.size()); - table.close(); - } - - @Test - public void testCloneSnapshotOfCloned() throws IOException, InterruptedException { - TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + - System.currentTimeMillis()); - admin.cloneSnapshot(snapshotName0, clonedTableName); - verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas()); - admin.disableTable(clonedTableName); - admin.snapshot(snapshotName2, clonedTableName); - TEST_UTIL.deleteTable(clonedTableName); - waitCleanerRun(); - - admin.cloneSnapshot(snapshotName2, clonedTableName); - verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas()); - TEST_UTIL.deleteTable(clonedTableName); - } - - @Test - public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException { - TEST_UTIL.deleteTable(tableName); - waitCleanerRun(); - - admin.cloneSnapshot(snapshotName0, tableName); - verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - waitCleanerRun(); - - admin.disableTable(tableName); - admin.restoreSnapshot(snapshotName0); - admin.enableTable(tableName); - verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - } - - @Test - public void testCorruptedSnapshot() throws IOException, InterruptedException { - SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, Bytes.toString(snapshotName0)); - TableName cloneName = TableName.valueOf(name.getMethodName() + "-" + - System.currentTimeMillis()); - try { - admin.cloneSnapshot(snapshotName0, cloneName); - fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()"); - } catch (CorruptedSnapshotException e) { - // Got the expected corruption exception. - // check for no references of the cloned table. - assertFalse(admin.tableExists(cloneName)); - } catch (Exception e) { - fail("Expected CorruptedSnapshotException got: " + e); - } - } - - @Test - public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException { - List regionInfos = admin.getRegions(tableName); - RegionReplicaUtil.removeNonDefaultRegions(regionInfos); - - // Split the first region - splitRegion(regionInfos.get(0)); - - // Take a snapshot - admin.snapshot(snapshotName1, tableName); - - // Load more data - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); - - // Split the second region - splitRegion(regionInfos.get(1)); - - // Restore the snapshot - admin.disableTable(tableName); - admin.restoreSnapshot(snapshotName1); - admin.enableTable(tableName); - - verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); - } - - @Test - public void testRestoreSnapshotAfterTruncate() throws Exception { - TableName tableName = TableName.valueOf("testRestoreSnapshotAfterTruncate"); - SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); - SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); - int numOfRows = 0; - - try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { - numOfRows = countRows(table); - } - // take snapshot - admin.snapshot("snap", tableName); - admin.disableTable(tableName); - admin.truncateTable(tableName, false); - admin.disableTable(tableName); - admin.restoreSnapshot("snap"); - - admin.enableTable(tableName); - verifyRowCount(TEST_UTIL, tableName, numOfRows); - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); - } - - @Test(timeout = 30000) - public void testGetCompactionStateAfterRestoringSnapshot() throws IOException, - InterruptedException { - // Take a snapshot - admin.snapshot(snapshotName1, tableName); - - // Restore the snapshot - admin.disableTable(tableName); - admin.restoreSnapshot(snapshotName1); - - // Get the compaction state of the restored table - CompactionState compactionState = admin.getCompactionState(tableName); - - // The compactionState should be NONE because the table is disabled - assertEquals(CompactionState.NONE, compactionState); - } - - // ========================================================================== - // Helpers - // ========================================================================== - private void waitCleanerRun() throws InterruptedException { - TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting(); - } - - private Set getFamiliesFromFS(final TableName tableName) throws IOException { - MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); - Set families = new HashSet<>(); - Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), tableName); - for (Path regionDir: FSUtils.getRegionDirs(mfs.getFileSystem(), tableDir)) { - for (Path familyDir: FSUtils.getFamilyDirs(mfs.getFileSystem(), regionDir)) { - families.add(familyDir.getName()); - } - } - return families; - } - - protected void verifyRowCount(final HBaseTestingUtility util, final TableName tableName, - long expectedRows) throws IOException { - SnapshotTestingUtils.verifyRowCount(util, tableName, expectedRows); - } - - protected int countRows(final Table table, final byte[]... families) throws IOException { - return TEST_UTIL.countRows(table, families); - } - - protected void splitRegion(final RegionInfo regionInfo) throws IOException { - byte[][] splitPoints = Bytes.split(regionInfo.getStartKey(), regionInfo.getEndKey(), 1); - admin.split(regionInfo.getTable(), splitPoints[1]); - } -} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterSplittingRegions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterSplittingRegions.java new file mode 100644 index 00000000000..499bfc6843c --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterSplittingRegions.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientAfterSplittingRegions + extends RestoreSnapshotFromClientAfterSplittingRegionsTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientAfterSplittingRegions.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterTruncate.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterTruncate.java new file mode 100644 index 00000000000..6ce0fb3622d --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientAfterTruncate.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientAfterTruncate + extends RestoreSnapshotFromClientAfterTruncateTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientAfterTruncate.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientClone.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientClone.java new file mode 100644 index 00000000000..e9704584cf1 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientClone.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientClone extends RestoreSnapshotFromClientCloneTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientClone.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientGetCompactionState.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientGetCompactionState.java new file mode 100644 index 00000000000..85eba79d132 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientGetCompactionState.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientGetCompactionState + extends RestoreSnapshotFromClientGetCompactionStateTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientGetCompactionState.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSchemaChange.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSchemaChange.java new file mode 100644 index 00000000000..0dd9b7b879c --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSchemaChange.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientSchemaChange + extends RestoreSnapshotFromClientSchemaChangeTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientSchemaChange.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSimple.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSimple.java new file mode 100644 index 00000000000..f498e72f1f6 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientSimple.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import java.util.Arrays; +import java.util.List; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.junit.ClassRule; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientSimple extends RestoreSnapshotFromClientSimpleTestBase { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientSimple.class); + + @Parameter + public int numReplicas; + + @Parameters(name = "{index}: regionReplication={0}") + public static List params() { + return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + } + + @Override + protected int getNumReplicas() { + return numReplicas; + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientWithRegionReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientWithRegionReplicas.java index d301098693a..ea47e9d27f2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientWithRegionReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClientWithRegionReplicas.java @@ -28,14 +28,13 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; - -@Category({LargeTests.class, ClientTests.class}) -public class TestRestoreSnapshotFromClientWithRegionReplicas extends - TestRestoreSnapshotFromClient { +@Category({ LargeTests.class, ClientTests.class }) +public class TestRestoreSnapshotFromClientWithRegionReplicas + extends RestoreSnapshotFromClientTestBase { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientWithRegionReplicas.class); + HBaseClassTestRule.forClass(TestRestoreSnapshotFromClientWithRegionReplicas.class); @Override protected int getNumReplicas() { @@ -54,8 +53,8 @@ public class TestRestoreSnapshotFromClientWithRegionReplicas extends admin.snapshot(snapshotName1, tableName); // Clone the snapshot to another table - TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + - System.currentTimeMillis()); + TableName clonedTableName = + TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis()); admin.cloneSnapshot(snapshotName1, clonedTableName); verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);