HBASE-13138 Clean up TestMasterObserver (debug, trying to figure why fails)

This commit is contained in:
stack 2015-03-02 10:53:30 -08:00
parent b3ebca633a
commit c4acac561c
2 changed files with 52 additions and 42 deletions

View File

@ -224,12 +224,19 @@ public class DisableTableHandler extends EventHandler {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
long remaining = timeout; long remaining = timeout;
List<HRegionInfo> regions = null; List<HRegionInfo> regions = null;
long lastLogTime = startTime;
while (!server.isStopped() && remaining > 0) { while (!server.isStopped() && remaining > 0) {
Thread.sleep(waitingTimeForEvents); Thread.sleep(waitingTimeForEvents);
regions = assignmentManager.getRegionStates().getRegionsOfTable(tableName); 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; if (regions.isEmpty()) break;
remaining = timeout - (System.currentTimeMillis() - startTime); remaining = timeout - (now - startTime);
} }
return regions != null && regions.isEmpty(); return regions != null && regions.isEmpty();
} }

View File

@ -61,8 +61,10 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.util.Threads;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
/** /**
* Tests invocation of the {@link org.apache.hadoop.hbase.coprocessor.MasterObserver} * Tests invocation of the {@link org.apache.hadoop.hbase.coprocessor.MasterObserver}
@ -1092,11 +1094,10 @@ public class TestMasterObserver {
private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static byte[] TEST_SNAPSHOT = Bytes.toBytes("observed_snapshot"); 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 TableName TEST_CLONE = TableName.valueOf("observed_clone");
private static byte[] TEST_FAMILY = Bytes.toBytes("fam1"); private static byte[] TEST_FAMILY = Bytes.toBytes("fam1");
private static byte[] TEST_FAMILY2 = Bytes.toBytes("fam2"); private static byte[] TEST_FAMILY2 = Bytes.toBytes("fam2");
private static byte[] TEST_FAMILY3 = Bytes.toBytes("fam3"); @Rule public TestName name = new TestName();
@BeforeClass @BeforeClass
public static void setupBeforeClass() throws Exception { public static void setupBeforeClass() throws Exception {
@ -1140,7 +1141,7 @@ public class TestMasterObserver {
@Test (timeout=180000) @Test (timeout=180000)
public void testTableOperations() throws Exception { public void testTableOperations() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster(); MiniHBaseCluster cluster = UTIL.getHBaseCluster();
final TableName tableName = TableName.valueOf(name.getMethodName());
HMaster master = cluster.getMaster(); HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost(); MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor( CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
@ -1150,7 +1151,7 @@ public class TestMasterObserver {
assertFalse("No table created yet", cp.wasCreateTableCalled()); assertFalse("No table created yet", cp.wasCreateTableCalled());
// create a table // create a table
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE); HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
Admin admin = UTIL.getHBaseAdmin(); Admin admin = UTIL.getHBaseAdmin();
@ -1165,8 +1166,8 @@ public class TestMasterObserver {
cp.wasCreateTableHandlerCalled()); cp.wasCreateTableHandlerCalled());
tableCreationLatch = new CountDownLatch(1); tableCreationLatch = new CountDownLatch(1);
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
// preDisableTable can't bypass default action. // preDisableTable can't bypass default action.
assertTrue("Coprocessor should have been called on table disable", assertTrue("Coprocessor should have been called on table disable",
cp.wasDisableTableCalled()); cp.wasDisableTableCalled());
@ -1175,45 +1176,45 @@ public class TestMasterObserver {
// enable // enable
assertFalse(cp.wasEnableTableCalled()); assertFalse(cp.wasEnableTableCalled());
admin.enableTable(TEST_TABLE); admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(TEST_TABLE)); assertTrue(admin.isTableEnabled(tableName));
// preEnableTable can't bypass default action. // preEnableTable can't bypass default action.
assertTrue("Coprocessor should have been called on table enable", assertTrue("Coprocessor should have been called on table enable",
cp.wasEnableTableCalled()); cp.wasEnableTableCalled());
assertTrue("Enable table handler should be called.", assertTrue("Enable table handler should be called.",
cp.wasEnableTableHandlerCalled()); cp.wasEnableTableHandlerCalled());
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
// modify table // modify table
htd.setMaxFileSize(512 * 1024 * 1024); htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, TEST_TABLE, htd); modifyTableSync(admin, tableName, htd);
// preModifyTable can't bypass default action. // preModifyTable can't bypass default action.
assertTrue("Test table should have been modified", assertTrue("Test table should have been modified",
cp.wasModifyTableCalled()); cp.wasModifyTableCalled());
// add a column family // 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", assertTrue("New column family shouldn't have been added to test table",
cp.preAddColumnCalledOnly()); cp.preAddColumnCalledOnly());
// modify a column family // modify a column family
HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2); HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2);
hcd1.setMaxVersions(25); hcd1.setMaxVersions(25);
admin.modifyColumn(TEST_TABLE, hcd1); admin.modifyColumn(tableName, hcd1);
assertTrue("Second column family should be modified", assertTrue("Second column family should be modified",
cp.preModifyColumnCalledOnly()); cp.preModifyColumnCalledOnly());
// truncate table // truncate table
admin.truncateTable(TEST_TABLE, false); admin.truncateTable(tableName, false);
// delete table // delete table
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
admin.deleteTable(TEST_TABLE); admin.deleteTable(tableName);
assertFalse("Test table should have been deleted", assertFalse("Test table should have been deleted",
admin.tableExists(TEST_TABLE)); admin.tableExists(tableName));
// preDeleteTable can't bypass default action. // preDeleteTable can't bypass default action.
assertTrue("Coprocessor should have been called on table delete", assertTrue("Coprocessor should have been called on table delete",
cp.wasDeleteTableCalled()); cp.wasDeleteTableCalled());
@ -1235,8 +1236,8 @@ public class TestMasterObserver {
// disable // disable
assertFalse(cp.wasDisableTableCalled()); assertFalse(cp.wasDisableTableCalled());
assertFalse(cp.wasDisableTableHandlerCalled()); assertFalse(cp.wasDisableTableHandlerCalled());
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
assertTrue("Coprocessor should have been called on table disable", assertTrue("Coprocessor should have been called on table disable",
cp.wasDisableTableCalled()); cp.wasDisableTableCalled());
assertTrue("Disable table handler should be called.", assertTrue("Disable table handler should be called.",
@ -1244,11 +1245,11 @@ public class TestMasterObserver {
// modify table // modify table
htd.setMaxFileSize(512 * 1024 * 1024); htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, TEST_TABLE, htd); modifyTableSync(admin, tableName, htd);
assertTrue("Test table should have been modified", assertTrue("Test table should have been modified",
cp.wasModifyTableCalled()); cp.wasModifyTableCalled());
// add a column family // 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", assertTrue("New column family should have been added to test table",
cp.wasAddColumnCalled()); cp.wasAddColumnCalled());
assertTrue("Add column handler should be called.", assertTrue("Add column handler should be called.",
@ -1257,7 +1258,7 @@ public class TestMasterObserver {
// modify a column family // modify a column family
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
hcd.setMaxVersions(25); hcd.setMaxVersions(25);
admin.modifyColumn(TEST_TABLE, hcd); admin.modifyColumn(tableName, hcd);
assertTrue("Second column family should be modified", assertTrue("Second column family should be modified",
cp.wasModifyColumnCalled()); cp.wasModifyColumnCalled());
assertTrue("Modify table handler should be called.", assertTrue("Modify table handler should be called.",
@ -1266,23 +1267,23 @@ public class TestMasterObserver {
// enable // enable
assertFalse(cp.wasEnableTableCalled()); assertFalse(cp.wasEnableTableCalled());
assertFalse(cp.wasEnableTableHandlerCalled()); assertFalse(cp.wasEnableTableHandlerCalled());
admin.enableTable(TEST_TABLE); admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(TEST_TABLE)); assertTrue(admin.isTableEnabled(tableName));
assertTrue("Coprocessor should have been called on table enable", assertTrue("Coprocessor should have been called on table enable",
cp.wasEnableTableCalled()); cp.wasEnableTableCalled());
assertTrue("Enable table handler should be called.", assertTrue("Enable table handler should be called.",
cp.wasEnableTableHandlerCalled()); cp.wasEnableTableHandlerCalled());
// disable again // disable again
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
// delete column // delete column
assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled()); assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled());
assertFalse("Delete table column handler should not be called.", assertFalse("Delete table column handler should not be called.",
cp.wasDeleteColumnHandlerCalled()); cp.wasDeleteColumnHandlerCalled());
admin.deleteColumn(TEST_TABLE, TEST_FAMILY2); admin.deleteColumn(tableName, TEST_FAMILY2);
HTableDescriptor tableDesc = admin.getTableDescriptor(TEST_TABLE); HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
assertNull("'"+Bytes.toString(TEST_FAMILY2)+"' should have been removed", assertNull("'"+Bytes.toString(TEST_FAMILY2)+"' should have been removed",
tableDesc.getFamily(TEST_FAMILY2)); tableDesc.getFamily(TEST_FAMILY2));
assertTrue("Coprocessor should have been called on column delete", assertTrue("Coprocessor should have been called on column delete",
@ -1294,9 +1295,9 @@ public class TestMasterObserver {
assertFalse("No table deleted yet", cp.wasDeleteTableCalled()); assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
assertFalse("Delete table handler should not be called.", assertFalse("Delete table handler should not be called.",
cp.wasDeleteTableHandlerCalled()); cp.wasDeleteTableHandlerCalled());
admin.deleteTable(TEST_TABLE); admin.deleteTable(tableName);
assertFalse("Test table should have been deleted", assertFalse("Test table should have been deleted",
admin.tableExists(TEST_TABLE)); admin.tableExists(tableName));
assertTrue("Coprocessor should have been called on table delete", assertTrue("Coprocessor should have been called on table delete",
cp.wasDeleteTableCalled()); cp.wasDeleteTableCalled());
assertTrue("Delete table handler should be called.", assertTrue("Delete table handler should be called.",
@ -1305,6 +1306,7 @@ public class TestMasterObserver {
@Test (timeout=180000) @Test (timeout=180000)
public void testSnapshotOperations() throws Exception { public void testSnapshotOperations() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
MiniHBaseCluster cluster = UTIL.getHBaseCluster(); MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster(); HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost(); MasterCoprocessorHost host = master.getMasterCoprocessorHost();
@ -1313,7 +1315,7 @@ public class TestMasterObserver {
cp.resetStates(); cp.resetStates();
// create a table // create a table
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE); HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
Admin admin = UTIL.getHBaseAdmin(); Admin admin = UTIL.getHBaseAdmin();
@ -1322,14 +1324,14 @@ public class TestMasterObserver {
tableCreationLatch.await(); tableCreationLatch.await();
tableCreationLatch = new CountDownLatch(1); tableCreationLatch = new CountDownLatch(1);
admin.disableTable(TEST_TABLE); admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
try { try {
// Test snapshot operation // Test snapshot operation
assertFalse("Coprocessor should not have been called yet", assertFalse("Coprocessor should not have been called yet",
cp.wasSnapshotCalled()); cp.wasSnapshotCalled());
admin.snapshot(TEST_SNAPSHOT, TEST_TABLE); admin.snapshot(TEST_SNAPSHOT, tableName);
assertTrue("Coprocessor should have been called on snapshot", assertTrue("Coprocessor should have been called on snapshot",
cp.wasSnapshotCalled()); cp.wasSnapshotCalled());
@ -1340,7 +1342,7 @@ public class TestMasterObserver {
assertFalse("Coprocessor restore should not have been called on snapshot clone", assertFalse("Coprocessor restore should not have been called on snapshot clone",
cp.wasRestoreSnapshotCalled()); cp.wasRestoreSnapshotCalled());
admin.disableTable(TEST_CLONE); admin.disableTable(TEST_CLONE);
assertTrue(admin.isTableDisabled(TEST_TABLE)); assertTrue(admin.isTableDisabled(tableName));
admin.deleteTable(TEST_CLONE); admin.deleteTable(TEST_CLONE);
// Test restore operation // Test restore operation
@ -1355,7 +1357,7 @@ public class TestMasterObserver {
assertTrue("Coprocessor should have been called on snapshot delete", assertTrue("Coprocessor should have been called on snapshot delete",
cp.wasDeleteSnapshotCalled()); cp.wasDeleteSnapshotCalled());
} finally { } finally {
admin.deleteTable(TEST_TABLE); admin.deleteTable(tableName);
} }
} }
@ -1448,6 +1450,7 @@ public class TestMasterObserver {
@Test (timeout=180000) @Test (timeout=180000)
public void testRegionTransitionOperations() throws Exception { public void testRegionTransitionOperations() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
MiniHBaseCluster cluster = UTIL.getHBaseCluster(); MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster(); HMaster master = cluster.getMaster();
@ -1457,10 +1460,10 @@ public class TestMasterObserver {
cp.enableBypass(false); cp.enableBypass(false);
cp.resetStates(); cp.resetStates();
HTable table = UTIL.createMultiRegionTable(TEST_TABLE, TEST_FAMILY); HTable table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY);
try { try {
UTIL.waitUntilAllRegionsAssigned(TEST_TABLE); UTIL.waitUntilAllRegionsAssigned(tableName);
NavigableMap<HRegionInfo, ServerName> regions = table.getRegionLocations(); NavigableMap<HRegionInfo, ServerName> regions = table.getRegionLocations();
Map.Entry<HRegionInfo, ServerName> firstGoodPair = null; Map.Entry<HRegionInfo, ServerName> firstGoodPair = null;
@ -1534,7 +1537,7 @@ public class TestMasterObserver {
assertTrue("Coprocessor should be called on region rebalancing", assertTrue("Coprocessor should be called on region rebalancing",
cp.wasBalanceCalled()); cp.wasBalanceCalled());
} finally { } finally {
UTIL.deleteTable(TEST_TABLE); UTIL.deleteTable(tableName);
} }
} }