HBASE-16714 Procedure V2 - use base class to remove duplicate set up test code in table DDL procedures (Stephen Yuan Jiang)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/db394f57 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/db394f57 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/db394f57 Branch: refs/heads/hbase-14439 Commit: db394f57dea44ab32a6670767ca8697bee26e2b7 Parents: 219c786 Author: Stephen Yuan Jiang <syuanjiang...@gmail.com> Authored: Mon Sep 26 20:41:43 2016 -0700 Committer: Stephen Yuan Jiang <syuanjiang...@gmail.com> Committed: Mon Sep 26 20:41:43 2016 -0700 ---------------------------------------------------------------------- .../procedure/TestAddColumnFamilyProcedure.java | 55 +------------ .../procedure/TestCloneSnapshotProcedure.java | 51 +----------- .../procedure/TestCreateTableProcedure.java | 64 +-------------- .../TestDeleteColumnFamilyProcedure.java | 51 +----------- .../procedure/TestDeleteTableProcedure.java | 59 +------------- .../procedure/TestDisableTableProcedure.java | 55 +------------ .../procedure/TestEnableTableProcedure.java | 55 +------------ .../TestModifyColumnFamilyProcedure.java | 55 +------------ .../procedure/TestModifyTableProcedure.java | 57 +------------ .../procedure/TestRestoreSnapshotProcedure.java | 51 ++---------- .../procedure/TestTableDDLProcedureBase.java | 86 ++++++++++++++++++++ .../procedure/TestTruncateTableProcedure.java | 61 +------------- 12 files changed, 103 insertions(+), 597 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestAddColumnFamilyProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestAddColumnFamilyProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestAddColumnFamilyProcedure.java index 384f45a..3861f51 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestAddColumnFamilyProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestAddColumnFamilyProcedure.java @@ -22,11 +22,7 @@ import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -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.InvalidFamilyOperationException; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; @@ -35,58 +31,13 @@ import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.AddColumnFamilyState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestAddColumnFamilyProcedure { +public class TestAddColumnFamilyProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestAddColumnFamilyProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout = 60000) public void testAddColumnFamily() throws Exception { final TableName tableName = TableName.valueOf("testAddColumnFamily"); @@ -284,8 +235,4 @@ public class TestAddColumnFamilyProcedure { MasterProcedureTestingUtility.validateColumnFamilyDeletion(UTIL.getHBaseCluster().getMaster(), tableName, cf6); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java index c0851a2..35a59a9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java @@ -51,62 +51,21 @@ import org.junit.experimental.categories.Category; import static org.junit.Assert.assertTrue; @Category({MasterTests.class, MediumTests.class}) -public class TestCloneSnapshotProcedure { +public class TestCloneSnapshotProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestCloneSnapshotProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - protected final byte[] CF = Bytes.toBytes("cf1"); - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - private static HBaseProtos.SnapshotDescription snapshot = null; - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - resetProcExecutorTestingKillFlag(); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - @After + @Override public void tearDown() throws Exception { - resetProcExecutorTestingKillFlag(); - TableName[] tables = UTIL.getHBaseAdmin().listTableNames(); - for (int i = 0; i < tables.length; ++i) { - UTIL.deleteTable(tables[i]); - } + super.tearDown(); SnapshotTestingUtils.deleteAllSnapshots(UTIL.getHBaseAdmin()); snapshot = null; } - private void resetProcExecutorTestingKillFlag() { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - assertTrue("expected executor to be running", procExec.isRunning()); - } - private HBaseProtos.SnapshotDescription getSnapshot() throws Exception { if (snapshot == null) { final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot"); @@ -246,8 +205,4 @@ public class TestCloneSnapshotProcedure { MasterProcedureTestingUtility.validateTableDeletion( UTIL.getHBaseCluster().getMaster(), clonedTableName); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java index 858d5ad..a7451bd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCreateTableProcedure.java @@ -18,12 +18,7 @@ package org.apache.hadoop.hbase.master.procedure; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.ProcedureInfo; @@ -31,15 +26,10 @@ import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; -import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.CreateTableState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ModifyRegionUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -47,55 +37,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @Category({MasterTests.class, MediumTests.class}) -public class TestCreateTableProcedure { - private static final Log LOG = LogFactory.getLog(TestCreateTableProcedure.class); - - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - resetProcExecutorTestingKillFlag(); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - resetProcExecutorTestingKillFlag(); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - - private void resetProcExecutorTestingKillFlag() { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - assertTrue("expected executor to be running", procExec.isRunning()); - } +public class TestCreateTableProcedure extends TestTableDDLProcedureBase { @Test(timeout=60000) public void testSimpleCreate() throws Exception { @@ -227,10 +169,6 @@ public class TestCreateTableProcedure { testRollbackAndDoubleExecution(htd); } - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } - private void testRollbackAndDoubleExecution(HTableDescriptor htd) throws Exception { // create the table final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedure.java index bbae80e..3bd90e3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteColumnFamilyProcedure.java @@ -35,58 +35,13 @@ import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.DeleteColumnFamilyState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestDeleteColumnFamilyProcedure { +public class TestDeleteColumnFamilyProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestDeleteColumnFamilyProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout = 60000) public void testDeleteColumnFamily() throws Exception { final TableName tableName = TableName.valueOf("testDeleteColumnFamily"); @@ -306,8 +261,4 @@ public class TestDeleteColumnFamilyProcedure { MasterProcedureTestingUtility.validateTableCreation( UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2", "f3", cf5); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java index c5f57fa..200a617 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDeleteTableProcedure.java @@ -20,10 +20,6 @@ package org.apache.hadoop.hbase.master.procedure; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; @@ -31,67 +27,18 @@ import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; -import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.DeleteTableState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; 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.Test; import org.junit.experimental.categories.Category; import static org.junit.Assert.assertTrue; @Category({MasterTests.class, MediumTests.class}) -public class TestDeleteTableProcedure { +public class TestDeleteTableProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestDeleteTableProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private long nonceGroup = HConstants.NO_NONCE; - private long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - assertTrue("expected executor to be running", procExec.isRunning()); - - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout=60000, expected=TableNotFoundException.class) public void testDeleteNotExistentTable() throws Exception { final TableName tableName = TableName.valueOf("testDeleteNotExistentTable"); @@ -234,8 +181,4 @@ public class TestDeleteTableProcedure { MasterProcedureTestingUtility.validateTableDeletion( UTIL.getHBaseCluster().getMaster(), tableName); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDisableTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDisableTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDisableTableProcedure.java index 6ff6a16..25b0917 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDisableTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestDisableTableProcedure.java @@ -22,10 +22,6 @@ import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotEnabledException; @@ -35,59 +31,14 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.DisableT import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestDisableTableProcedure { +public class TestDisableTableProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestDisableTableProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout = 60000) public void testDisableTable() throws Exception { final TableName tableName = TableName.valueOf("testDisableTable"); @@ -200,8 +151,4 @@ public class TestDisableTableProcedure { MasterProcedureTestingUtility.validateTableIsDisabled(UTIL.getHBaseCluster().getMaster(), tableName); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestEnableTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestEnableTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestEnableTableProcedure.java index e0709e4..d4c108c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestEnableTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestEnableTableProcedure.java @@ -22,10 +22,6 @@ import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotDisabledException; @@ -35,59 +31,14 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.EnableTa import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestEnableTableProcedure { +public class TestEnableTableProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestEnableTableProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout = 60000) public void testEnableTable() throws Exception { final TableName tableName = TableName.valueOf("testEnableTable"); @@ -212,8 +163,4 @@ public class TestEnableTableProcedure { MasterProcedureTestingUtility.validateTableIsDisabled(UTIL.getHBaseCluster().getMaster(), tableName); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyColumnFamilyProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyColumnFamilyProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyColumnFamilyProcedure.java index 27bf097..b538251 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyColumnFamilyProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyColumnFamilyProcedure.java @@ -22,11 +22,7 @@ import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -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.InvalidFamilyOperationException; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; @@ -35,58 +31,13 @@ import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.ModifyColumnFamilyState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestModifyColumnFamilyProcedure { +public class TestModifyColumnFamilyProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestModifyColumnFamilyProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout = 60000) public void testModifyColumnFamily() throws Exception { final TableName tableName = TableName.valueOf("testModifyColumnFamily"); @@ -239,8 +190,4 @@ public class TestModifyColumnFamilyProcedure { int numberOfSteps = 1; // failing at pre operation MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, numberOfSteps); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyTableProcedure.java index b19f6b8..2a843b0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestModifyTableProcedure.java @@ -22,13 +22,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.DoNotRetryIOException; -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.ProcedureInfo; @@ -38,57 +33,11 @@ import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.ModifyTableState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @Category({MasterTests.class, MediumTests.class}) -public class TestModifyTableProcedure { - private static final Log LOG = LogFactory.getLog(TestModifyTableProcedure.class); - - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } +public class TestModifyTableProcedure extends TestTableDDLProcedureBase { @Test(timeout=60000) public void testModifyTable() throws Exception { @@ -369,8 +318,4 @@ public class TestModifyTableProcedure { MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(), tableName, regions, "cf1"); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java index 4e6303a..6472178 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java @@ -24,9 +24,7 @@ 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.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.ProcedureInfo; import org.apache.hadoop.hbase.TableName; @@ -44,9 +42,7 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; 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.Test; import org.junit.experimental.categories.Category; @@ -56,11 +52,9 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @Category({MasterTests.class, MediumTests.class}) -public class TestRestoreSnapshotProcedure { +public class TestRestoreSnapshotProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestRestoreSnapshotProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - protected final TableName snapshotTableName = TableName.valueOf("testRestoreSnapshot"); protected final byte[] CF1 = Bytes.toBytes("cf1"); protected final byte[] CF2 = Bytes.toBytes("cf2"); @@ -72,55 +66,24 @@ public class TestRestoreSnapshotProcedure { protected final int rowCountCF4 = 40; protected final int rowCountCF1addition = 10; - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - private HBaseProtos.SnapshotDescription snapshot = null; private HTableDescriptor snapshotHTD = null; - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - @Before + @Override public void setup() throws Exception { - resetProcExecutorTestingKillFlag(); - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - + super.setup(); setupSnapshotAndUpdateTable(); } @After + @Override public void tearDown() throws Exception { - resetProcExecutorTestingKillFlag(); - UTIL.deleteTable(snapshotTableName); + super.tearDown(); SnapshotTestingUtils.deleteAllSnapshots(UTIL.getHBaseAdmin()); SnapshotTestingUtils.deleteArchiveDirectory(UTIL); } - private void resetProcExecutorTestingKillFlag() { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - assertTrue("expected executor to be running", procExec.isRunning()); - } - private int getNumReplicas() { return 1; } @@ -282,8 +245,4 @@ public class TestRestoreSnapshotProcedure { UTIL.getHBaseAdmin().disableTable(snapshotTableName); } } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTableDDLProcedureBase.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTableDDLProcedureBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTableDDLProcedureBase.java new file mode 100644 index 0000000..6b0f083 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTableDDLProcedureBase.java @@ -0,0 +1,86 @@ +/** + * 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.master.procedure; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; +import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import static org.junit.Assert.assertTrue; + +public abstract class TestTableDDLProcedureBase { + private static final Log LOG = LogFactory.getLog(TestTableDDLProcedureBase.class); + protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + protected static long nonceGroup; + protected static long nonce; + + private static void setupConf(Configuration conf) { + conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); + } + + @BeforeClass + public static void setupCluster() throws Exception { + setupConf(UTIL.getConfiguration()); + UTIL.startMiniCluster(1); + } + + @AfterClass + public static void cleanupTest() throws Exception { + try { + UTIL.shutdownMiniCluster(); + } catch (Exception e) { + LOG.warn("failure shutting down cluster", e); + } + } + + @Before + public void setup() throws Exception { + resetProcExecutorTestingKillFlag(); + nonceGroup = + MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); + nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); + } + + @After + public void tearDown() throws Exception { + resetProcExecutorTestingKillFlag(); + for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { + LOG.info("Tear down, remove table=" + htd.getTableName()); + UTIL.deleteTable(htd.getTableName()); + } + } + + protected void resetProcExecutorTestingKillFlag() { + final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); + ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); + assertTrue("expected executor to be running", procExec.isRunning()); + } + + protected ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { + return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/db394f57/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java index c72e3f3..423100f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestTruncateTableProcedure.java @@ -20,10 +20,6 @@ package org.apache.hadoop.hbase.master.procedure; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.ProcedureInfo; import org.apache.hadoop.hbase.TableName; @@ -31,14 +27,9 @@ import org.apache.hadoop.hbase.TableNotDisabledException; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; -import org.apache.hadoop.hbase.protobuf.generated.MasterProcedureProtos.TruncateTableState; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; 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.Test; import org.junit.experimental.categories.Category; @@ -46,55 +37,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @Category({MasterTests.class, MediumTests.class}) -public class TestTruncateTableProcedure { +public class TestTruncateTableProcedure extends TestTableDDLProcedureBase { private static final Log LOG = LogFactory.getLog(TestTruncateTableProcedure.class); - protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - - private static long nonceGroup = HConstants.NO_NONCE; - private static long nonce = HConstants.NO_NONCE; - - private static void setupConf(Configuration conf) { - conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); - } - - @BeforeClass - public static void setupCluster() throws Exception { - setupConf(UTIL.getConfiguration()); - UTIL.startMiniCluster(1); - } - - @AfterClass - public static void cleanupTest() throws Exception { - try { - UTIL.shutdownMiniCluster(); - } catch (Exception e) { - LOG.warn("failure shutting down cluster", e); - } - } - - @Before - public void setup() throws Exception { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - assertTrue("expected executor to be running", procExec.isRunning()); - - nonceGroup = - MasterProcedureTestingUtility.generateNonceGroup(UTIL.getHBaseCluster().getMaster()); - nonce = MasterProcedureTestingUtility.generateNonce(UTIL.getHBaseCluster().getMaster()); - } - - @After - public void tearDown() throws Exception { - final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); - assertTrue("expected executor to be running", procExec.isRunning()); - ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(getMasterProcedureExecutor(), false); - for (HTableDescriptor htd: UTIL.getHBaseAdmin().listTables()) { - LOG.info("Tear down, remove table=" + htd.getTableName()); - UTIL.deleteTable(htd.getTableName()); - } - } - @Test(timeout=60000) public void testTruncateNotExistentTable() throws Exception { final TableName tableName = TableName.valueOf("testTruncateNotExistentTable"); @@ -248,8 +193,4 @@ public class TestTruncateTableProcedure { UTIL.getConnection(), tableName, 50, splitKeys, families); assertEquals(50, UTIL.countRows(tableName)); } - - private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { - return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); - } }