From 677ff7e0db2e917eb678e3888160151d120686fe Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Wed, 15 Aug 2012 16:33:40 +0000 Subject: [PATCH] HBASE-6478. TestClassLoading.testClassLoadingFromLibDirInJar occasionally fails git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1373520 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/HBaseTestingUtility.java | 17 ++++++++++++-- .../hbase/coprocessor/TestClassLoading.java | 22 +++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 767202e1167..34a67b6396e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -1652,8 +1652,21 @@ public class HBaseTestingUtility { throws InterruptedException, IOException { long startWait = System.currentTimeMillis(); while (!getHBaseAdmin().isTableAvailable(table)) { - assertTrue("Timed out waiting for table " + Bytes.toStringBinary(table), - System.currentTimeMillis() - startWait < timeoutMillis); + assertTrue("Timed out waiting for table to become available " + + Bytes.toStringBinary(table), + System.currentTimeMillis() - startWait < timeoutMillis); + Thread.sleep(200); + } + } + + public void waitTableEnabled(byte[] table, long timeoutMillis) + throws InterruptedException, IOException { + long startWait = System.currentTimeMillis(); + while (!getHBaseAdmin().isTableAvailable(table) && + !getHBaseAdmin().isTableEnabled(table)) { + assertTrue("Timed out waiting for table to become available and enabled " + + Bytes.toStringBinary(table), + System.currentTimeMillis() - startWait < timeoutMillis); Thread.sleep(200); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java index 2cc10921c35..7b4ac648292 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java @@ -240,7 +240,7 @@ public class TestClassLoading { admin.deleteTable(tableName); } admin.createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + waitForTable(htd.getName()); // verify that the coprocessors were loaded boolean found1 = false, found2 = false, found2_k1 = false, @@ -283,7 +283,7 @@ public class TestClassLoading { Coprocessor.PRIORITY_USER); HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); admin.createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + waitForTable(htd.getName()); // verify that the coprocessor was loaded boolean found = false; @@ -309,7 +309,7 @@ public class TestClassLoading { Coprocessor.PRIORITY_USER); HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); admin.createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + waitForTable(htd.getName()); // verify that the coprocessor was loaded correctly boolean found = false; @@ -377,7 +377,7 @@ public class TestClassLoading { admin.deleteTable(tableName); } admin.createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + waitForTable(htd.getName()); // verify that the coprocessor was loaded boolean found_2 = false, found_1 = false, found_3 = false, @@ -482,7 +482,7 @@ public class TestClassLoading { admin.deleteTable(tableName); } admin.createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + waitForTable(htd.getName()); // verify that the coprocessors were loaded boolean found1 = false, found2 = false, found2_k1 = false, @@ -554,7 +554,8 @@ public class TestClassLoading { String userTable1 = "userTable1"; HTableDescriptor userTD1 = new HTableDescriptor(userTable1); admin.createTable(userTD1); - TEST_UTIL.waitTableAvailable(userTD1.getName(), 5000); + waitForTable(userTD1.getName()); + // table should be enabled now. assertTrue(admin.isTableEnabled(userTable1)); assertAllRegionServers(regionServerSystemAndUserCoprocessors, userTable1); @@ -573,7 +574,7 @@ public class TestClassLoading { htd2.setValue("COPROCESSOR$1", jarFile1.toString() + "|" + userTableCP + "|" + Coprocessor.PRIORITY_USER); admin.createTable(htd2); - TEST_UTIL.waitTableAvailable(htd2.getName(), 5000); + waitForTable(htd2.getName()); // table should be enabled now. assertTrue(admin.isTableEnabled(userTable2)); @@ -668,6 +669,13 @@ public class TestClassLoading { assertEquals(loadedMasterCoprocessorsVerify, loadedMasterCoprocessors); } + private void waitForTable(byte[] name) throws InterruptedException, IOException { + // First wait until all regions are online + TEST_UTIL.waitTableEnabled(name, 5000); + // Now wait a bit longer for the coprocessor hosts to load the CPs + Thread.sleep(1000); + } + @org.junit.Rule public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();