Skip to content

Commit

Permalink
HBASE-13179 TestMasterObserver deleteTable is flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Bertozzi committed Mar 9, 2015
1 parent 948746c commit fb5e6b3
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -77,6 +77,7 @@ public class TestMasterObserver {
private static final Log LOG = LogFactory.getLog(TestMasterObserver.class);

public static CountDownLatch tableCreationLatch = new CountDownLatch(1);
public static CountDownLatch tableDeletionLatch = new CountDownLatch(1);

public static class CPMasterObserver implements MasterObserver {

Expand Down Expand Up @@ -876,6 +877,7 @@ public void postDeleteTableHandler(
ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName)
throws IOException {
postDeleteTableHandlerCalled = true;
tableDeletionLatch.countDown();
}

public boolean wasDeleteTableHandlerCalled() {
Expand Down Expand Up @@ -1274,7 +1276,7 @@ public void testTableOperations() throws Exception {
// delete table
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
admin.deleteTable(tableName);
deleteTable(admin, tableName);
assertFalse("Test table should have been deleted",
admin.tableExists(tableName));
// preDeleteTable can't bypass default action.
Expand Down Expand Up @@ -1357,7 +1359,7 @@ public void testTableOperations() throws Exception {
assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
assertFalse("Delete table handler should not be called.",
cp.wasDeleteTableHandlerCalled());
admin.deleteTable(tableName);
deleteTable(admin, tableName);
assertFalse("Test table should have been deleted",
admin.tableExists(tableName));
assertTrue("Coprocessor should have been called on table delete",
Expand Down Expand Up @@ -1410,7 +1412,7 @@ public void testSnapshotOperations() throws Exception {
cp.wasRestoreSnapshotCalled());
admin.disableTable(TEST_CLONE);
assertTrue(admin.isTableDisabled(tableName));
admin.deleteTable(TEST_CLONE);
deleteTable(admin, TEST_CLONE);

// Test restore operation
cp.resetStates();
Expand All @@ -1424,7 +1426,7 @@ public void testSnapshotOperations() throws Exception {
assertTrue("Coprocessor should have been called on snapshot delete",
cp.wasDeleteSnapshotCalled());
} finally {
admin.deleteTable(tableName);
deleteTable(admin, tableName);
}
}

Expand Down Expand Up @@ -1604,7 +1606,9 @@ public void testRegionTransitionOperations() throws Exception {
assertTrue("Coprocessor should be called on region rebalancing",
cp.wasBalanceCalled());
} finally {
UTIL.deleteTable(tableName);
Admin admin = UTIL.getHBaseAdmin();
admin.disableTable(tableName);
deleteTable(admin, tableName);
}
}

Expand Down Expand Up @@ -1651,4 +1655,13 @@ public void testTableNamesEnumeration() throws Exception {
assertTrue("Coprocessor should be called on table names request",
cp.wasGetTableNamesCalled());
}

private void deleteTable(Admin admin, TableName tableName) throws Exception {
// NOTE: We need a latch because admin is not sync,
// so the postOp coprocessor method may be called after the admin operation returned.
tableDeletionLatch = new CountDownLatch(1);
admin.deleteTable(tableName);
tableDeletionLatch.await();
tableDeletionLatch = new CountDownLatch(1);
}
}

0 comments on commit fb5e6b3

Please sign in to comment.