HBASE-4052 Use same TestMasterRestartAfterDisablingTable in branch and TRUNK
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1147357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72c89e6f3c
commit
3b0a7528c9
|
@ -20,12 +20,10 @@
|
||||||
package org.apache.hadoop.hbase.master;
|
package org.apache.hadoop.hbase.master;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NavigableSet;
|
import java.util.NavigableSet;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -35,9 +33,7 @@ import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
import org.apache.hadoop.hbase.HRegionInfo;
|
||||||
import org.apache.hadoop.hbase.MiniHBaseCluster;
|
import org.apache.hadoop.hbase.MiniHBaseCluster;
|
||||||
import org.apache.hadoop.hbase.NotServingRegionException;
|
|
||||||
import org.apache.hadoop.hbase.client.HTable;
|
import org.apache.hadoop.hbase.client.HTable;
|
||||||
import org.apache.hadoop.hbase.client.Scan;
|
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
|
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
|
||||||
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
|
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
|
||||||
|
@ -48,7 +44,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class TestMasterRestartAfterDisablingTable {
|
public class TestMasterRestartAfterDisablingTable {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(TestRollingRestart.class);
|
private static final Log LOG = LogFactory.getLog(TestMasterRestartAfterDisablingTable.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
|
public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
|
||||||
|
@ -57,8 +53,6 @@ public class TestMasterRestartAfterDisablingTable {
|
||||||
final int NUM_RS = 1;
|
final int NUM_RS = 1;
|
||||||
final int NUM_REGIONS_TO_CREATE = 4;
|
final int NUM_REGIONS_TO_CREATE = 4;
|
||||||
|
|
||||||
int expectedNumRS = 1;
|
|
||||||
|
|
||||||
// Start the cluster
|
// Start the cluster
|
||||||
log("Starting cluster");
|
log("Starting cluster");
|
||||||
Configuration conf = HBaseConfiguration.create();
|
Configuration conf = HBaseConfiguration.create();
|
||||||
|
@ -69,8 +63,7 @@ public class TestMasterRestartAfterDisablingTable {
|
||||||
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
|
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
|
||||||
log("Waiting for active/ready master");
|
log("Waiting for active/ready master");
|
||||||
cluster.waitForActiveAndReadyMaster();
|
cluster.waitForActiveAndReadyMaster();
|
||||||
ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "testmasterRestart",
|
ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "testmasterRestart", null);
|
||||||
null);
|
|
||||||
HMaster master = cluster.getMaster();
|
HMaster master = cluster.getMaster();
|
||||||
|
|
||||||
// Create a table with regions
|
// Create a table with regions
|
||||||
|
@ -87,8 +80,9 @@ public class TestMasterRestartAfterDisablingTable {
|
||||||
TEST_UTIL.getHBaseAdmin().disableTable(table);
|
TEST_UTIL.getHBaseAdmin().disableTable(table);
|
||||||
|
|
||||||
NavigableSet<String> regions = getAllOnlineRegions(cluster);
|
NavigableSet<String> regions = getAllOnlineRegions(cluster);
|
||||||
assertEquals("The number of regions for the table tableRestart should be 0 and only" +
|
assertEquals(
|
||||||
"the catalog tables should be present.", 2, regions.size());
|
"The number of regions for the table tableRestart should be 0 and only"
|
||||||
|
+ "the catalog tables should be present.", 2, regions.size());
|
||||||
|
|
||||||
List<MasterThread> masterThreads = cluster.getMasterThreads();
|
List<MasterThread> masterThreads = cluster.getMasterThreads();
|
||||||
MasterThread activeMaster = null;
|
MasterThread activeMaster = null;
|
||||||
|
@ -100,22 +94,17 @@ public class TestMasterRestartAfterDisablingTable {
|
||||||
activeMaster.getMaster().stop(
|
activeMaster.getMaster().stop(
|
||||||
"stopping the active master so that the backup can become active");
|
"stopping the active master so that the backup can become active");
|
||||||
cluster.hbaseCluster.waitOnMaster(activeMaster);
|
cluster.hbaseCluster.waitOnMaster(activeMaster);
|
||||||
|
cluster.waitForActiveAndReadyMaster();
|
||||||
|
|
||||||
log("Enabling table\n");
|
log("Enabling table\n");
|
||||||
TEST_UTIL.getHBaseAdmin().enableTable(table);
|
TEST_UTIL.getHBaseAdmin().enableTable(table);
|
||||||
log("Waiting for no more RIT\n");
|
log("Waiting for no more RIT\n");
|
||||||
blockUntilNoRIT(zkw, master);
|
blockUntilNoRIT(zkw, master);
|
||||||
log("Verifying there are " + numRegions + " assigned on cluster\n");
|
log("Verifying there are " + numRegions + " assigned on cluster\n");
|
||||||
try {
|
|
||||||
Scan s = new Scan();
|
|
||||||
ht.getScanner(s);
|
|
||||||
} catch (NotServingRegionException e) {
|
|
||||||
fail("NotServingRegionException should not be thrown after enabling the table. Hence failing"
|
|
||||||
+ "the test case");
|
|
||||||
}
|
|
||||||
regions = getAllOnlineRegions(cluster);
|
regions = getAllOnlineRegions(cluster);
|
||||||
assertRegionsAssigned(cluster, regions);
|
assertEquals(
|
||||||
assertEquals("All the regions are not onlined.",expectedNumRS, cluster.getRegionServerThreads().size());
|
"The assigned regions were not onlined after master switch except for the catalog tables.",
|
||||||
|
6, regions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(String msg) {
|
private void log(String msg) {
|
||||||
|
@ -128,50 +117,6 @@ public class TestMasterRestartAfterDisablingTable {
|
||||||
master.assignmentManager.waitUntilNoRegionsInTransition(60000);
|
master.assignmentManager.waitUntilNoRegionsInTransition(60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertRegionsAssigned(MiniHBaseCluster cluster,
|
|
||||||
Set<String> expectedRegions) throws IOException {
|
|
||||||
int numFound = 0;
|
|
||||||
for (RegionServerThread rst : cluster.getLiveRegionServerThreads()) {
|
|
||||||
numFound += rst.getRegionServer().getNumberOfOnlineRegions();
|
|
||||||
}
|
|
||||||
if (expectedRegions.size() > numFound) {
|
|
||||||
log("Expected to find " + expectedRegions.size() + " but only found"
|
|
||||||
+ " " + numFound);
|
|
||||||
NavigableSet<String> foundRegions = getAllOnlineRegions(cluster);
|
|
||||||
for (String region : expectedRegions) {
|
|
||||||
if (!foundRegions.contains(region)) {
|
|
||||||
log("Missing region: " + region);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertEquals(expectedRegions.size(), numFound);
|
|
||||||
} else if (expectedRegions.size() < numFound) {
|
|
||||||
int doubled = numFound - expectedRegions.size();
|
|
||||||
log("Expected to find " + expectedRegions.size() + " but found" + " "
|
|
||||||
+ numFound + " (" + doubled + " double assignments?)");
|
|
||||||
NavigableSet<String> doubleRegions = getDoubleAssignedRegions(cluster);
|
|
||||||
for (String region : doubleRegions) {
|
|
||||||
log("Region is double assigned: " + region);
|
|
||||||
}
|
|
||||||
assertEquals(expectedRegions.size(), numFound);
|
|
||||||
} else {
|
|
||||||
log("Success! Found expected number of " + numFound + " regions");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private NavigableSet<String> getDoubleAssignedRegions(MiniHBaseCluster cluster)
|
|
||||||
throws IOException {
|
|
||||||
NavigableSet<String> online = new TreeSet<String>();
|
|
||||||
NavigableSet<String> doubled = new TreeSet<String>();
|
|
||||||
for (RegionServerThread rst : cluster.getLiveRegionServerThreads()) {
|
|
||||||
for (HRegionInfo region : rst.getRegionServer().getOnlineRegions()) {
|
|
||||||
if (!online.add(region.getRegionNameAsString())) {
|
|
||||||
doubled.add(region.getRegionNameAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return doubled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NavigableSet<String> getAllOnlineRegions(MiniHBaseCluster cluster)
|
private NavigableSet<String> getAllOnlineRegions(MiniHBaseCluster cluster)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
NavigableSet<String> online = new TreeSet<String>();
|
NavigableSet<String> online = new TreeSet<String>();
|
||||||
|
|
Loading…
Reference in New Issue