Index: src/test/java/org/apache/hadoop/hbase/master/TestHBase5937.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/master/TestHBase5937.java (revision 0) +++ src/test/java/org/apache/hadoop/hbase/master/TestHBase5937.java (revision 0) @@ -0,0 +1,141 @@ +package org.apache.hadoop.hbase.master; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.text.DecimalFormat; +import java.util.Map; +import java.util.NavigableMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.HServerAddress; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.LargeTests; +import org.apache.hadoop.hbase.MediumTests; +import org.apache.hadoop.hbase.MiniHBaseCluster; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.master.AssignmentManager.RegionState; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hdfs.MiniDFSCluster; +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; + +/** + * Re-produce the problem of HBASE-5937. + */ +@Category(LargeTests.class) +public class TestHBase5937 { + private static final Log LOG = LogFactory.getLog(TestRollingRestart.class); + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private MiniDFSCluster dfsCluster; + private HBaseAdmin admin; + private MiniHBaseCluster cluster; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + TEST_UTIL.getConfiguration().setInt("hbase.master.assignment.timeoutmonitor.timeout", 90000); + } + + @AfterClass + public static void afterAllTests() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Before + public void setUp() throws Exception { + TEST_UTIL.startMiniCluster(3); + + cluster = TEST_UTIL.getHBaseCluster(); + dfsCluster = TEST_UTIL.getDFSCluster(); + admin = TEST_UTIL.getHBaseAdmin(); + cluster.getMaster().balanceSwitch(false); + } + + @After + public void tearDown() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Test (timeout=3000000) + public void test5937() throws Exception { + final byte[] tableName = Bytes.toBytes("testHBase5937"); + DecimalFormat df = new DecimalFormat("000"); + byte[][] splitKeys = new byte[100][]; + int index = 0; + for (int j = 0; j < 100; j++) { + splitKeys[index] = Bytes.toBytes(df.format(j)); + index++; + } + int expectedRegions = splitKeys.length + 1; + // 1. Create a new table with many regions. + HTableDescriptor desc = new HTableDescriptor(tableName); + desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); + admin.createTable(desc, splitKeys); + + HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); + Map regions = ht.getRegionsInfo(); + assertEquals("Tried to create " + expectedRegions + " regions " + + "but only found " + regions.size(), + expectedRegions, regions.size()); + + // 2. Disable table. + Thread t1 = new Thread() { + public void run() { + try { + admin.disableTable(tableName); + } catch (IOException e) { + // TODO Auto-generated catch block + LOG.warn("IOE during disabling table."); + } + } + }; + t1.start(); + + // 3. Kill one HRegionServer. + Thread.sleep(100); + + Thread t2 = new Thread() { + public void run() { + cluster.stopRegionServer(0); + } + }; + t2.start(); + t2.join(); + // 4. Monitor the regions in RIT. It can re-produce that issue with high + // probability. + Thread t3 = new Thread() { + public void run() { + HMaster master = cluster.getMaster(); + int waitTimes = 0; + do { + NavigableMap map = master.getAssignmentManager() + .getRegionsInTransition(); + LOG.info("Current regions in RIT: " + map.size()); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (waitTimes == 45 && map.size() > 0) { + LOG.info("HBase-5937 probably reproduced."); + } + waitTimes++; + } while (waitTimes < 46); + } + }; + t3.start(); + t1.join(); + t3.join(); + } +} Property changes on: src\test\java\org\apache\hadoop\hbase\master\TestHBase5937.java ___________________________________________________________________ Added: svn:needs-lock + *