Author: liyin Date: Wed Apr 23 18:18:28 2014 New Revision: 1589482 URL: http://svn.apache.org/r1589482 Log: [Master] Make TestRegionChecker more stable.
Author: elliott Summary: TestRegionChecker was unstable because region movement could take a while and could be sporadic in number. This had all been dealt with in TestRegionPlacement. So I extracted the needed parts into a new testing util. Test Plan: bin/test/loop_tests.sh -t TestRegionChecker Reviewers: liyintang, daviddeng, rshroff Reviewed By: daviddeng CC: hbase-eng@ Differential Revision: https://phabricator.fb.com/D1285388 Task ID: 3297398 Added: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionMovementTestHelper.java Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionChecker.java hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacementDestructive.java Added: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionMovementTestHelper.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionMovementTestHelper.java?rev=1589482&view=auto ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionMovementTestHelper.java (added) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionMovementTestHelper.java Wed Apr 23 18:18:28 2014 @@ -0,0 +1,186 @@ +/** + * Copyright The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.master; + +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.MiniHBaseCluster; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.util.Bytes; + +import java.io.IOException; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class RegionMovementTestHelper extends HBaseTestingUtility { + + private static final Log LOG = LogFactory.getLog(RegionMovementTestHelper.class); + + private static int sleepTime = 10; + private int lastRegionOpenedCount = 0; + + public RegionMovementTestHelper() { + super(); + sleepTime = 3 * this.getConfiguration(). + getInt("hbase.regionserver.msginterval", 1000); + } + + /** + * Create a table with specified table name and region number. + * + * @param table name of the table + * @param regionNum number of regions to create. + * @throws java.io.IOException + */ + public void createTable(String table, int regionNum) + throws IOException, InterruptedException { + byte[] tableName = Bytes.toBytes(table); + byte[][] splitKeys = new byte[regionNum - 1][]; + byte[][] putKeys = new byte[regionNum - 1][]; + for (int i = 1; i < regionNum; i++) { + byte splitKey = (byte) i; + splitKeys[i - 1] = new byte[] { splitKey, splitKey, splitKey }; + putKeys[i - 1] = new byte[] { splitKey, splitKey, (byte) (i - 1) }; + } + + HTableDescriptor desc = new HTableDescriptor(tableName); + desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); + new HBaseAdmin(getConfiguration()).createTable(desc, splitKeys); + + HTable ht = new HTable(getConfiguration(), tableName); + Map<HRegionInfo, HServerAddress> regions = ht.getRegionsInfo(); + assertEquals("Tried to create " + regionNum + " regions " + + "but only found " + regions.size(), regionNum, regions.size()); + + // Try and make sure that everything is up and assigned + waitForTableConsistent(); + // Try and make sure that everything is assigned to their final destination. + waitOnStableRegionMovement(); + + try { + for (byte[] rk : putKeys) { + Put p = new Put(rk); + p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes(0L), Bytes.toBytes("testValue")); + ht.put(p); + } + } finally { + ht.close(); + } + } + + public void waitOnTable(String tableName) throws IOException { + + waitForTableConsistent(); + + HTable ht = new HTable(getConfiguration(), tableName); + Scan s = new Scan(); + ResultScanner rs = null; + try { + rs = ht.getScanner(s); + Result r = null; + do { + r = rs.next(); + } while (r != null); + } finally { + if (rs != null) rs.close(); + if (ht != null) ht.close(); + } + } + + + public void waitOnStableRegionMovement() throws IOException, InterruptedException { + int first = -1; + int second = 0; + + int attempt = 0; + waitForTableConsistent(); + while (first != second && attempt < 10) { + first = second; + second = getHBaseCluster().getMaster().getMetrics().getRegionsOpened(); + Thread.sleep((++attempt) * sleepTime); + } + } + /** + * Verify the number of region movement is expected + * + * @param expected + * @throws InterruptedException + */ + public void verifyRegionMovementNum(int expected) + throws InterruptedException { + MiniHBaseCluster cluster = getHBaseCluster(); + HMaster m = cluster.getMaster(); + + int retry = 10; + int attempt = 0; + int currentRegionOpened, regionMovement; + do { + currentRegionOpened = m.getMetrics().getRegionsOpened(); + regionMovement = currentRegionOpened - lastRegionOpenedCount; + LOG.debug("There are " + regionMovement + "/" + expected + + " regions moved after " + attempt + " attempts"); + Thread.sleep((++attempt) * sleepTime); + } while (regionMovement < expected && attempt <= retry); + + // update the lastRegionOpenedCount + resetLastOpenedRegionCount(currentRegionOpened); + + assertTrue("There are only " + regionMovement + " instead of " + + expected + " region movement for " + attempt + " attempts", + expected <= regionMovement + ); + + int maxExpected = (int) (expected * 1.5f); + + // Because of how over-loaded some jvm's are during tests, region open can take quite a while + // this will cause extra assignments as the region will get assigned to an intermediate + // region server before being moved to the preferred server. This check allows for some of that + // but not too much. 1.5x expected is pretty generous, but makes sure that some of the regions + // made it to their preferred destination in one move. + // + // On a real cluster this is less likely to happen as there will be more region servers and they + // will be less resource constrained. + assertTrue("There are " + regionMovement + " expecting max of " + + maxExpected + " after " + attempt + " attempts", + maxExpected >= regionMovement + ); + } + public void resetLastOpenedRegionCount() { + resetLastOpenedRegionCount(getHBaseCluster().getMaster().getMetrics().getRegionsOpened()); + } + + public void resetLastOpenedRegionCount(int newCount) { + this.lastRegionOpenedCount = newCount; + } +} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java?rev=1589482&r1=1589481&r2=1589482&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java Wed Apr 23 18:18:28 2014 @@ -55,7 +55,7 @@ import static org.junit.Assert.assertNul import static org.junit.Assert.assertTrue; public class RegionPlacementTestBase { - protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + protected final static RegionMovementTestHelper TEST_UTIL = new RegionMovementTestHelper(); protected final static int META_REGION_OVERHEAD = 1; protected final static int ROOT_REGION_OVERHEAD = 1; final static Log LOG = LogFactory.getLog(RegionPlacementTestBase.class); @@ -66,50 +66,7 @@ public class RegionPlacementTestBase { protected int lastRegionOnPrimaryRSCount = 0; protected int REGION_NUM = 10; - private int lastRegionOpenedCount = 0; - /** - * Create a table with specified table name and region number. - * - * @param table name of the table - * @param regionNum number of regions to create. - * @throws java.io.IOException - */ - protected void createTable(String table, int regionNum) - throws IOException, InterruptedException { - byte[] tableName = Bytes.toBytes(table); - byte[][] splitKeys = new byte[regionNum - 1][]; - byte[][] putKeys = new byte[regionNum - 1][]; - for (int i = 1; i < regionNum; i++) { - byte splitKey = (byte) i; - splitKeys[i - 1] = new byte[] { splitKey, splitKey, splitKey }; - putKeys[i - 1] = new byte[] { splitKey, splitKey, (byte) (i - 1) }; - } - - 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<HRegionInfo, HServerAddress> regions = ht.getRegionsInfo(); - assertEquals("Tried to create " + regionNum + " regions " - + "but only found " + regions.size(), regionNum, regions.size()); - - // Try and make sure that everything is up and assigned - TEST_UTIL.waitForTableConsistent(); - // Try and make sure that everything is assigned to their final destination. - waitOnStableRegionMovement(); - - try { - for (byte[] rk : putKeys) { - Put p = new Put(rk); - p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes(0L), Bytes.toBytes("testValue")); - ht.put(p); - } - } finally { - ht.close(); - } - } protected static void setUpCluster(int numSlaves) throws IOException, InterruptedException { Configuration conf = TEST_UTIL.getConfiguration(); @@ -125,41 +82,10 @@ public class RegionPlacementTestBase { TEST_UTIL.startMiniCluster(numSlaves); sleepTime = 3 * TEST_UTIL.getConfiguration(). getInt("hbase.regionserver.msginterval", 1000); - admin = new HBaseAdmin(conf); + admin = TEST_UTIL.getHBaseAdmin(); rp = new RegionPlacement(conf); } - protected void waitOnTable(String tableName) throws IOException { - - TEST_UTIL.waitForTableConsistent(); - - HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); - Scan s = new Scan(); - ResultScanner rs = null; - try { - rs = ht.getScanner(s); - Result r = null; - do { - r = rs.next(); - } while (r != null); - } finally { - if (rs != null) rs.close(); - if (ht != null) ht.close(); - } - } - - protected void waitOnStableRegionMovement() throws IOException, InterruptedException { - int first = -1; - int second = 0; - - int attempt = 0; - while (first != second && attempt < 10) { - first = second; - second = TEST_UTIL.getHBaseCluster().getMaster().getMetrics().getRegionsOpened(); - Thread.sleep((++attempt) * sleepTime); - } - } - /** * To verify the region assignment status. * It will check the assignment plan consistency between META and @@ -180,7 +106,7 @@ public class RegionPlacementTestBase { verifyMETAUpdated(plan); // Verify the number of region movement is expected - verifyRegionMovementNum(regionMovementNum); + TEST_UTIL.verifyRegionMovementNum(regionMovementNum); // Verify the number of regions is assigned to the primary region server // based on the plan is expected @@ -218,7 +144,7 @@ public class RegionPlacementTestBase { server.kill(); // Verify the user regions previously on the killed rs are reassigned. - verifyRegionMovementNum(expectedRegionMovement); + TEST_UTIL.verifyRegionMovementNum(expectedRegionMovement); // Verify only expectedRegionOnPrimary of the user regions are assigned // to the primary region server based on the plan. @@ -262,64 +188,12 @@ public class RegionPlacementTestBase { return null; } - /** - * Verify the number of region movement is expected - * - * @param expected - * @throws InterruptedException - */ - protected void verifyRegionMovementNum(int expected) - throws InterruptedException { - MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - HMaster m = cluster.getMaster(); - - int retry = 10; - int attempt = 0; - int currentRegionOpened, regionMovement; - do { - currentRegionOpened = m.getMetrics().getRegionsOpened(); - regionMovement = currentRegionOpened - lastRegionOpenedCount; - LOG.debug("There are " + regionMovement + "/" + expected + - " regions moved after " + attempt + " attempts"); - Thread.sleep((++attempt) * sleepTime); - } while (regionMovement < expected && attempt <= retry); - - // update the lastRegionOpenedCount - resetLastOpenedRegionCount(currentRegionOpened); - - assertTrue("There are only " + regionMovement + " instead of " - + expected + " region movement for " + attempt + " attempts", - expected <= regionMovement - ); - - int maxExpected = (int) (expected * 1.5f); - - // Because of how over-loaded some jvm's are during tests, region open can take quite a while - // this will cause extra assignments as the region will get assigned to an intermediate - // region server before being moved to the preferred server. This check allows for some of that - // but not too much. 1.5x expected is pretty generous, but makes sure that some of the regions - // made it to their preferred destination in one move. - // - // On a real cluster this is less likely to happen as there will be more region servers and they - // will be less resource constrained. - assertTrue("There are " + regionMovement + " expecting max of " - + maxExpected + " after " + attempt + " attempts", - maxExpected >= regionMovement - ); - } - protected void resetLastRegionOnPrimary() throws IOException { this.lastRegionOnPrimaryRSCount = getNumRegionisOnPrimaryRS(); } - protected void resetLastOpenedRegionCount() { - resetLastOpenedRegionCount( - TEST_UTIL.getHBaseCluster().getMaster().getMetrics().getRegionsOpened()); - } - private void resetLastOpenedRegionCount(int newCount) { - this.lastRegionOpenedCount = newCount; - } + /** * Shuffle the assignment plan by switching two favored node positions. @@ -572,9 +446,9 @@ public class RegionPlacementTestBase { } } - waitOnStableRegionMovement(); - resetLastOpenedRegionCount(); + TEST_UTIL.waitOnStableRegionMovement(); + TEST_UTIL.resetLastOpenedRegionCount(); resetLastRegionOnPrimary(); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnStableRegionMovement(); } } Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionChecker.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionChecker.java?rev=1589482&r1=1589481&r2=1589482&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionChecker.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionChecker.java Wed Apr 23 18:18:28 2014 @@ -3,14 +3,13 @@ package org.apache.hadoop.hbase.master; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.*; -import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.master.RegionChecker.RegionAvailabilityInfo; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.After; import org.junit.Test; import java.io.IOException; @@ -19,20 +18,18 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class TestRegionChecker { final static Log LOG = LogFactory.getLog(TestRegionChecker.class); - private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private final static RegionMovementTestHelper TEST_UTIL = new RegionMovementTestHelper(); private final static int SLAVES = 4; - private static int lastRegionOpenedCount = 0; - private static HBaseAdmin admin; private static int REGION_NUM = 10; - private static int META_REGION_NUM = 2; private static RegionChecker regionChecker; private static MiniHBaseCluster cluster; private static final String TABLE_NAME_BASE = "testRegionAssignment"; - private static boolean firstTableCreated = false; /* EPS is small enough and fits for comparing availabilities @@ -48,13 +45,11 @@ public class TestRegionChecker { */ private final double EPS = 1e-9; - @BeforeClass - public static void setupBeforeClass() throws Exception { - init(true); - // ONLY meta regions, ROOT and META, are assigned at beginning. - verifyRegionMovementNum(META_REGION_NUM); - } - + /** + * Set up the cluster. This will start a mini cluster and enable or disable the region checker + * @param enableRegionChecker if the region checker should run on the master. + * @throws Exception + */ public static void init(boolean enableRegionChecker) throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); @@ -69,14 +64,13 @@ public class TestRegionChecker { TEST_UTIL.startMiniCluster(SLAVES); - admin = new HBaseAdmin(conf); - cluster = TEST_UTIL.getHBaseCluster(); regionChecker = cluster.getActiveMaster().getServerManager().getRegionChecker(); } - @AfterClass - public static void tearDownAfterClass() throws Exception { + @After + public void cleanUp() throws Exception { + TEST_UTIL.resetLastOpenedRegionCount(); TEST_UTIL.shutdownMiniCluster(); } @@ -98,7 +92,7 @@ public class TestRegionChecker { // Create a table with REGION_NUM regions. String tableName = TABLE_NAME_BASE + "testAvailabilityGoesDownWithRegionFail"; - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); Set<HRegionInfo> allRegions = ht.getRegionsInfo().keySet(); final int regionsMove = 1; @@ -114,22 +108,26 @@ public class TestRegionChecker { } } + TEST_UTIL.waitOnStableRegionMovement(); + TEST_UTIL.resetLastOpenedRegionCount(); + LOG.debug("killing '" + regionToKill.getRegionNameAsString() + "' region"); cluster.getRegionServer(serverId).closeRegion(regionToKill, true); - verifyRegionMovementNum(regionsMove); + TEST_UTIL.verifyRegionMovementNum(regionsMove); LOG.debug("killed '" + regionToKill.getRegionNameAsString() + "' region"); check(allRegions, regionsToKill); - deleteTable(tableName, regionsMove); + TEST_UTIL.deleteTable(Bytes.toBytes(tableName)); + TEST_UTIL.resetLastOpenedRegionCount(); } - @Test(timeout = 180000) + @Test(timeout = 360000) public void testAvailabilityGoesDownWithRegionServerCleanFail() throws Exception { testAvailabilityGoesDownWithRegionServerFail(true); } - @Test(timeout = 180000) + @Test(timeout = 360000) public void testAvailabilityGoesDownWithRegionServerUncleanFail() throws Exception { testAvailabilityGoesDownWithRegionServerFail(false); } @@ -140,7 +138,7 @@ public class TestRegionChecker { // Create a table with REGION_NUM regions. String tableName = TABLE_NAME_BASE + "testAvailabilityGoesDownWithRegionServerFail" + isFailClean; - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName); Set<HRegionInfo> allRegions = ht.getRegionsInfo().keySet(); @@ -152,6 +150,8 @@ public class TestRegionChecker { regionsToKill.add(info.getRegionNameAsString()); } + TEST_UTIL.resetLastOpenedRegionCount(); + int regionCnt = cluster.getRegionServer(serverId).getOnlineRegions().size(); if(isFailClean) { @@ -165,11 +165,12 @@ public class TestRegionChecker { LOG.debug("killed regionServer unclean"); } - verifyRegionMovementNum(regionCnt); + TEST_UTIL.verifyRegionMovementNum(regionCnt); check(allRegions, regionsToKill); - deleteTable(tableName, regionCnt); + TEST_UTIL.deleteTable(Bytes.toBytes(tableName)); + TEST_UTIL.resetLastOpenedRegionCount(); } private void check(Set<HRegionInfo> allRegions, List<String> regionsToKill) @@ -210,7 +211,7 @@ public class TestRegionChecker { for (HRegionInfo info : allRegions) { String region = info.getRegionNameAsString(); if (avDetDayAfter.containsKey(region) && !regionsToKill.contains(region)) { - fail("Detailed availibility map shouldn't contain such a key " + region + ", because this region wasn't killed"); + fail("Detailed availability map shouldn't contain such a key " + region + ", because this region wasn't killed"); } } @@ -218,95 +219,23 @@ public class TestRegionChecker { for (HRegionInfo info : allRegions) { String region = info.getRegionNameAsString(); if (avDetWeekAfter.containsKey(region) && !regionsToKill.contains(region)) { - fail("Detailed availibility map shouldn't contain such a key " + region + ", because this region wasn't killed"); + fail("Detailed availability map shouldn't contain such a key " + region + ", because this region wasn't killed"); } } } - /** Get the region server - * who is currently hosting ROOT - * @return - * @throws IOException + /** + * Get a region server currently hosting a user region */ private int getRegionServerId() throws IOException { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); for (int i = 0; i < SLAVES; i++) { - if (cluster.getRegionServer(i).getRegionsAssignment().length > 0) { + // Find a region server with more than 2 regions. + // 2 because of root and meta. + if (cluster.getRegionServer(i).getRegionsAssignment().length > 2) { return i; } } return -1; } - - /** - * Verify the number of region movement is expected - * @param expected - * @throws InterruptedException - */ - private static void verifyRegionMovementNum(int expected) throws InterruptedException { - MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - HMaster m = cluster.getActiveMaster(); - - int retry = 10; - long sleep = 3 * TEST_UTIL.getConfiguration().getInt("hbase.regionserver.msginterval", 1000); - int attempt = 0; - int currentRegionOpened, regionMovement; - do { - currentRegionOpened = m.getMetrics().getRegionsOpened(); - regionMovement = currentRegionOpened - lastRegionOpenedCount; - LOG.debug("There are " + regionMovement + "/" + expected + " regions moved after " + attempt - + " attempts"); - Thread.sleep((++attempt) * sleep); - } while (regionMovement != expected && attempt <= retry); - - // update the lastRegionOpenedCount - lastRegionOpenedCount = currentRegionOpened; - - assertEquals("There are only " + regionMovement + " instead of " + expected - + " region movement for " + attempt + " attempts", regionMovement, expected); - } - - /** - * Create a table with specified table name and region number. - * @param table - * @param regionNum - * @return - * @throws IOException - * @throws InterruptedException - */ - private static void createTable(String table, int regionNum) - throws IOException, InterruptedException { - - byte[] tableName = Bytes.toBytes(table); - int expectedRegions = regionNum; - byte[][] splitKeys = new byte[expectedRegions - 1][]; - for (int i = 1; i < expectedRegions; i++) { - byte splitKey = (byte) i; - splitKeys[i - 1] = new byte[] { splitKey, splitKey, splitKey }; - } - - 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<HRegionInfo, HServerAddress> regions = ht.getRegionsInfo(); - assertEquals( - "Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), - expectedRegions, regions.size()); - - if(firstTableCreated == false) - { - firstTableCreated = true; - verifyRegionMovementNum(REGION_NUM); - } - - return; - } - - private static void deleteTable(String tableName, final int regionsMove) throws IOException { - admin.disableTable(tableName); - admin.deleteTable(tableName); - lastRegionOpenedCount -= regionsMove; - } } Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java?rev=1589482&r1=1589481&r2=1589482&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java Wed Apr 23 18:18:28 2014 @@ -86,10 +86,10 @@ public class TestRegionPlacement extends final String tableNameTwo = "testPrimaryPlacement2"; // Create a table with REGION_NUM regions. - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); AssignmentPlan plan = rp.getExistingAssignmentPlan(); @@ -100,21 +100,21 @@ public class TestRegionPlacement extends expected.put(3, 2); expected.put(2, 2); - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); assertTrue(verifyNumPrimaries(expected, plan)); //create additional table with 5 regions - createTable(tableNameTwo, 6); + TEST_UTIL.createTable(tableNameTwo, 6); expected.clear(); // after this we expect 4 regionservers with 4 regions expected.put(4, 4); - waitOnTable(tableName); - waitOnTable(tableNameTwo); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnTable(tableNameTwo); + TEST_UTIL.waitOnStableRegionMovement(); plan = rp.getExistingAssignmentPlan(); assertTrue(verifyNumPrimaries(expected, plan)); @@ -129,17 +129,17 @@ public class TestRegionPlacement extends AssignmentPlan currentPlan; // Reset all of the counters. - resetLastOpenedRegionCount(); + TEST_UTIL.resetLastOpenedRegionCount(); resetLastRegionOnPrimary(); // Create a table with REGION_NUM regions. final String tableName = "testRegionAssignment"; - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); - verifyRegionMovementNum(REGION_NUM); + TEST_UTIL.verifyRegionMovementNum(REGION_NUM); // Get the assignment plan from scanning the META table currentPlan = rp.getExistingAssignmentPlan(); @@ -168,16 +168,16 @@ public class TestRegionPlacement extends public void testRegionPlacementShuffle() throws Exception { // Create a table with REGION_NUM regions. final String tableName = "testRegionPlacementShuffle"; - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); AssignmentPlan currentPlan = rp.getExistingAssignmentPlan(); // Wait on everything to settle down - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); // Reset the counts so that previous tests don't impact this. - resetLastOpenedRegionCount(); + TEST_UTIL.resetLastOpenedRegionCount(); resetLastRegionOnPrimary(); // Shuffle the secondary with tertiary favored nodes @@ -200,8 +200,8 @@ public class TestRegionPlacement extends rp.updateAssignmentPlan(shuffledPlan); // Really really wait for the table. - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); verifyRegionAssignment(shuffledPlan, REGION_NUM, REGION_NUM); } @@ -216,7 +216,7 @@ public class TestRegionPlacement extends public void testPinnedTable() throws Exception { String tableName = "testPinnedTable"; - resetLastOpenedRegionCount(); + TEST_UTIL.resetLastOpenedRegionCount(); resetLastRegionOnPrimary(); try { @@ -237,12 +237,12 @@ public class TestRegionPlacement extends admin.createTable(htd, Bytes.toBytes("aaaa"), Bytes.toBytes("zzzz"), REGION_NUM); // Wait for things to stabilize - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); // Reset all of the counters. resetLastRegionOnPrimary(); - resetLastOpenedRegionCount(); + TEST_UTIL.resetLastOpenedRegionCount(); verifyRegionAssignment(rp.getExistingAssignmentPlan(), 0, REGION_NUM); assertPinned(tableName, cluster, servers, unusedServer); @@ -251,8 +251,8 @@ public class TestRegionPlacement extends rp.updateAssignmentPlan(rp.getNewAssignmentPlan()); // Wait for things to stabilize - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); // Verify current plan verifyRegionAssignment(rp.getExistingAssignmentPlan(), 0, REGION_NUM); @@ -323,7 +323,7 @@ public class TestRegionPlacement extends */ @Test public void testJsonToAP() throws Exception { - createTable("testJsonAssignmentPlan", 3); + TEST_UTIL.createTable("testJsonAssignmentPlan", 3); AssignmentPlan currentPlan = rp.getExistingAssignmentPlan(); RegionPlacement.printAssignmentPlan(currentPlan); Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacementDestructive.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacementDestructive.java?rev=1589482&r1=1589481&r2=1589482&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacementDestructive.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacementDestructive.java Wed Apr 23 18:18:28 2014 @@ -42,16 +42,16 @@ public class TestRegionPlacementDestruct public void testRegionPlacementKillMeta() throws Exception { // Create a table with REGION_NUM regions. final String tableName = "testRegionPlacementKillMeta"; - createTable(tableName, REGION_NUM); + TEST_UTIL.createTable(tableName, REGION_NUM); AssignmentPlan currentPlan = rp.getExistingAssignmentPlan(); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnStableRegionMovement(); // Check to make sure the new table is on it's primaries. verifyRegionOnPrimaryRS(REGION_NUM); - resetLastOpenedRegionCount(); + TEST_UTIL.resetLastOpenedRegionCount(); resetLastRegionOnPrimary(); HRegionServer meta = this.getRegionServerWithMETA(); @@ -65,8 +65,8 @@ public class TestRegionPlacementDestruct verifyKillRegionServerWithMetaOrRoot(meta, expectedRegionOnPrimaryRS); RegionPlacement.printAssignmentPlan(currentPlan); - waitOnTable(tableName); - waitOnStableRegionMovement(); + TEST_UTIL.waitOnTable(tableName); + TEST_UTIL.waitOnStableRegionMovement(); // Start Root RS Kill Test HRegionServer root = this.getRegionServerWithROOT();
