From b9f8616177ecd9425c408b560be54f08a2f1e84d Mon Sep 17 00:00:00 2001 From: stack Date: Mon, 2 Mar 2015 10:53:30 -0800 Subject: [PATCH] HBASE-13138 Clean up TestMasterObserver (debug, trying to figure why fails) --- .../master/handler/DisableTableHandler.java | 11 ++- .../hbase/coprocessor/TestMasterObserver.java | 83 ++++++++++--------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java index 993edb274b0..ee774196319 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java @@ -217,12 +217,19 @@ public class DisableTableHandler extends EventHandler { long startTime = System.currentTimeMillis(); long remaining = timeout; List regions = null; + long lastLogTime = startTime; while (!server.isStopped() && remaining > 0) { Thread.sleep(waitingTimeForEvents); regions = assignmentManager.getRegionStates().getRegionsOfTable(tableName); - LOG.debug("Disable waiting until done; " + remaining + " ms remaining; " + regions); + long now = System.currentTimeMillis(); + // Don't log more than once every ten seconds. Its obnoxious. And only log table regions + // if we are waiting a while for them to go down... + if (LOG.isDebugEnabled() && ((now - lastLogTime) > 10000)) { + lastLogTime = now; + LOG.debug("Disable waiting until done; " + remaining + " ms remaining; " + regions); + } if (regions.isEmpty()) break; - remaining = timeout - (System.currentTimeMillis() - startTime); + remaining = timeout - (now - startTime); } return regions != null && regions.isEmpty(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index 2e998dd949d..61263d61487 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -63,8 +63,10 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; /** * Tests invocation of the {@link org.apache.hadoop.hbase.coprocessor.MasterObserver} @@ -1154,11 +1156,10 @@ public class TestMasterObserver { private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static byte[] TEST_SNAPSHOT = Bytes.toBytes("observed_snapshot"); - private static TableName TEST_TABLE = TableName.valueOf("observed_table"); private static TableName TEST_CLONE = TableName.valueOf("observed_clone"); private static byte[] TEST_FAMILY = Bytes.toBytes("fam1"); private static byte[] TEST_FAMILY2 = Bytes.toBytes("fam2"); - private static byte[] TEST_FAMILY3 = Bytes.toBytes("fam3"); + @Rule public TestName name = new TestName(); @BeforeClass public static void setupBeforeClass() throws Exception { @@ -1202,7 +1203,7 @@ public class TestMasterObserver { @Test (timeout=180000) public void testTableOperations() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); - + final TableName tableName = TableName.valueOf(name.getMethodName()); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( @@ -1212,7 +1213,7 @@ public class TestMasterObserver { assertFalse("No table created yet", cp.wasCreateTableCalled()); // create a table - HTableDescriptor htd = new HTableDescriptor(TEST_TABLE); + HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); Admin admin = UTIL.getHBaseAdmin(); @@ -1227,8 +1228,8 @@ public class TestMasterObserver { cp.wasCreateTableHandlerCalled()); tableCreationLatch = new CountDownLatch(1); - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); // preDisableTable can't bypass default action. assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled()); @@ -1237,45 +1238,45 @@ public class TestMasterObserver { // enable assertFalse(cp.wasEnableTableCalled()); - admin.enableTable(TEST_TABLE); - assertTrue(admin.isTableEnabled(TEST_TABLE)); + admin.enableTable(tableName); + assertTrue(admin.isTableEnabled(tableName)); // preEnableTable can't bypass default action. assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled()); assertTrue("Enable table handler should be called.", cp.wasEnableTableHandlerCalled()); - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); // modify table htd.setMaxFileSize(512 * 1024 * 1024); - modifyTableSync(admin, TEST_TABLE, htd); + modifyTableSync(admin, tableName, htd); // preModifyTable can't bypass default action. assertTrue("Test table should have been modified", cp.wasModifyTableCalled()); // add a column family - admin.addColumn(TEST_TABLE, new HColumnDescriptor(TEST_FAMILY2)); + admin.addColumn(tableName, new HColumnDescriptor(TEST_FAMILY2)); assertTrue("New column family shouldn't have been added to test table", cp.preAddColumnCalledOnly()); // modify a column family HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2); hcd1.setMaxVersions(25); - admin.modifyColumn(TEST_TABLE, hcd1); + admin.modifyColumn(tableName, hcd1); assertTrue("Second column family should be modified", cp.preModifyColumnCalledOnly()); // truncate table - admin.truncateTable(TEST_TABLE, false); + admin.truncateTable(tableName, false); // delete table - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); - admin.deleteTable(TEST_TABLE); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); + admin.deleteTable(tableName); assertFalse("Test table should have been deleted", - admin.tableExists(TEST_TABLE)); + admin.tableExists(tableName)); // preDeleteTable can't bypass default action. assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled()); @@ -1297,8 +1298,8 @@ public class TestMasterObserver { // disable assertFalse(cp.wasDisableTableCalled()); assertFalse(cp.wasDisableTableHandlerCalled()); - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled()); assertTrue("Disable table handler should be called.", @@ -1306,11 +1307,11 @@ public class TestMasterObserver { // modify table htd.setMaxFileSize(512 * 1024 * 1024); - modifyTableSync(admin, TEST_TABLE, htd); + modifyTableSync(admin, tableName, htd); assertTrue("Test table should have been modified", cp.wasModifyTableCalled()); // add a column family - admin.addColumn(TEST_TABLE, new HColumnDescriptor(TEST_FAMILY2)); + admin.addColumn(tableName, new HColumnDescriptor(TEST_FAMILY2)); assertTrue("New column family should have been added to test table", cp.wasAddColumnCalled()); assertTrue("Add column handler should be called.", @@ -1319,7 +1320,7 @@ public class TestMasterObserver { // modify a column family HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2); hcd.setMaxVersions(25); - admin.modifyColumn(TEST_TABLE, hcd); + admin.modifyColumn(tableName, hcd); assertTrue("Second column family should be modified", cp.wasModifyColumnCalled()); assertTrue("Modify table handler should be called.", @@ -1328,23 +1329,23 @@ public class TestMasterObserver { // enable assertFalse(cp.wasEnableTableCalled()); assertFalse(cp.wasEnableTableHandlerCalled()); - admin.enableTable(TEST_TABLE); - assertTrue(admin.isTableEnabled(TEST_TABLE)); + admin.enableTable(tableName); + assertTrue(admin.isTableEnabled(tableName)); assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled()); assertTrue("Enable table handler should be called.", cp.wasEnableTableHandlerCalled()); // disable again - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); // delete column assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled()); assertFalse("Delete table column handler should not be called.", cp.wasDeleteColumnHandlerCalled()); - admin.deleteColumn(TEST_TABLE, TEST_FAMILY2); - HTableDescriptor tableDesc = admin.getTableDescriptor(TEST_TABLE); + admin.deleteColumn(tableName, TEST_FAMILY2); + HTableDescriptor tableDesc = admin.getTableDescriptor(tableName); assertNull("'"+Bytes.toString(TEST_FAMILY2)+"' should have been removed", tableDesc.getFamily(TEST_FAMILY2)); assertTrue("Coprocessor should have been called on column delete", @@ -1356,9 +1357,9 @@ public class TestMasterObserver { assertFalse("No table deleted yet", cp.wasDeleteTableCalled()); assertFalse("Delete table handler should not be called.", cp.wasDeleteTableHandlerCalled()); - admin.deleteTable(TEST_TABLE); + admin.deleteTable(tableName); assertFalse("Test table should have been deleted", - admin.tableExists(TEST_TABLE)); + admin.tableExists(tableName)); assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled()); assertTrue("Delete table handler should be called.", @@ -1367,6 +1368,7 @@ public class TestMasterObserver { @Test (timeout=180000) public void testSnapshotOperations() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); @@ -1375,7 +1377,7 @@ public class TestMasterObserver { cp.resetStates(); // create a table - HTableDescriptor htd = new HTableDescriptor(TEST_TABLE); + HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); Admin admin = UTIL.getHBaseAdmin(); @@ -1384,14 +1386,14 @@ public class TestMasterObserver { tableCreationLatch.await(); tableCreationLatch = new CountDownLatch(1); - admin.disableTable(TEST_TABLE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + admin.disableTable(tableName); + assertTrue(admin.isTableDisabled(tableName)); try { // Test snapshot operation assertFalse("Coprocessor should not have been called yet", cp.wasSnapshotCalled()); - admin.snapshot(TEST_SNAPSHOT, TEST_TABLE); + admin.snapshot(TEST_SNAPSHOT, tableName); assertTrue("Coprocessor should have been called on snapshot", cp.wasSnapshotCalled()); @@ -1407,7 +1409,7 @@ public class TestMasterObserver { assertFalse("Coprocessor restore should not have been called on snapshot clone", cp.wasRestoreSnapshotCalled()); admin.disableTable(TEST_CLONE); - assertTrue(admin.isTableDisabled(TEST_TABLE)); + assertTrue(admin.isTableDisabled(tableName)); admin.deleteTable(TEST_CLONE); // Test restore operation @@ -1422,7 +1424,7 @@ public class TestMasterObserver { assertTrue("Coprocessor should have been called on snapshot delete", cp.wasDeleteSnapshotCalled()); } finally { - admin.deleteTable(TEST_TABLE); + admin.deleteTable(tableName); } } @@ -1515,6 +1517,7 @@ public class TestMasterObserver { @Test (timeout=180000) public void testRegionTransitionOperations() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); @@ -1524,10 +1527,10 @@ public class TestMasterObserver { cp.enableBypass(false); cp.resetStates(); - HTable table = UTIL.createMultiRegionTable(TEST_TABLE, TEST_FAMILY); + HTable table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY); try { - UTIL.waitUntilAllRegionsAssigned(TEST_TABLE); + UTIL.waitUntilAllRegionsAssigned(tableName); NavigableMap regions = table.getRegionLocations(); Map.Entry firstGoodPair = null; @@ -1601,7 +1604,7 @@ public class TestMasterObserver { assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled()); } finally { - UTIL.deleteTable(TEST_TABLE); + UTIL.deleteTable(tableName); } }