HBASE-15123 Remove duplicate code in LocalHBaseCluster and minor formatting (Appy)

This commit is contained in:
stack 2016-01-25 13:00:08 -04:00
parent a87d9560fc
commit d6b3d838eb
2 changed files with 20 additions and 61 deletions

View File

@ -273,53 +273,32 @@ public class LocalHBaseCluster {
}
/**
* Wait for the specified region server to stop
* Removes this thread from list of running threads.
* @param serverNumber
* Wait for the specified region server to stop. Removes this thread from list of running threads.
* @return Name of region server that just went down.
*/
public String waitOnRegionServer(int serverNumber) {
JVMClusterUtil.RegionServerThread regionServerThread =
this.regionThreads.remove(serverNumber);
while (regionServerThread.isAlive()) {
try {
LOG.info("Waiting on " +
regionServerThread.getRegionServer().toString());
regionServerThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return regionServerThread.getName();
JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.get(serverNumber);
return waitOnRegionServer(regionServerThread);
}
/**
* Wait for the specified region server to stop
* Removes this thread from list of running threads.
* @param rst
* Wait for the specified region server to stop. Removes this thread from list of running threads.
* @return Name of region server that just went down.
*/
public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) {
while (rst.isAlive()) {
try {
LOG.info("Waiting on " +
rst.getRegionServer().toString());
LOG.info("Waiting on " + rst.getRegionServer().toString());
rst.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (int i=0;i<regionThreads.size();i++) {
if (regionThreads.get(i) == rst) {
regionThreads.remove(i);
break;
}
}
regionThreads.remove(rst);
return rst.getName();
}
/**
* @param serverNumber
* @return the HMaster thread
*/
public HMaster getMaster(int serverNumber) {
@ -357,8 +336,7 @@ public class LocalHBaseCluster {
* this list).
*/
public List<JVMClusterUtil.MasterThread> getLiveMasters() {
List<JVMClusterUtil.MasterThread> liveServers =
new ArrayList<JVMClusterUtil.MasterThread>();
List<JVMClusterUtil.MasterThread> liveServers = new ArrayList<>();
List<JVMClusterUtil.MasterThread> list = getMasters();
for (JVMClusterUtil.MasterThread mt: list) {
if (mt.isAlive()) {
@ -369,13 +347,19 @@ public class LocalHBaseCluster {
}
/**
* Wait for the specified master to stop
* Removes this thread from list of running threads.
* @param serverNumber
* Wait for the specified master to stop. Removes this thread from list of running threads.
* @return Name of master that just went down.
*/
public String waitOnMaster(int serverNumber) {
JVMClusterUtil.MasterThread masterThread = this.masterThreads.remove(serverNumber);
JVMClusterUtil.MasterThread masterThread = this.masterThreads.get(serverNumber);
return waitOnMaster(masterThread);
}
/**
* Wait for the specified master to stop. Removes this thread from list of running threads.
* @return Name of master that just went down.
*/
public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) {
while (masterThread.isAlive()) {
try {
LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString());
@ -384,31 +368,7 @@ public class LocalHBaseCluster {
e.printStackTrace();
}
}
return masterThread.getName();
}
/**
* Wait for the specified master to stop
* Removes this thread from list of running threads.
* @param masterThread
* @return Name of master that just went down.
*/
public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) {
while (masterThread.isAlive()) {
try {
LOG.info("Waiting on " +
masterThread.getMaster().getServerName().toString());
masterThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (int i=0;i<masterThreads.size();i++) {
if (masterThreads.get(i) == masterThread) {
masterThreads.remove(i);
break;
}
}
masterThreads.remove(masterThread);
return masterThread.getName();
}

View File

@ -75,8 +75,7 @@ public class MiniHBaseCluster extends HBaseCluster {
* @param numRegionServers initial number of region servers to start.
* @throws IOException
*/
public MiniHBaseCluster(Configuration conf, int numMasters,
int numRegionServers)
public MiniHBaseCluster(Configuration conf, int numMasters, int numRegionServers)
throws IOException, InterruptedException {
this(conf, numMasters, numRegionServers, null, null);
}
@ -108,7 +107,6 @@ public class MiniHBaseCluster extends HBaseCluster {
public static class MiniHBaseClusterRegionServer extends HRegionServer {
private Thread shutdownThread = null;
private User user = null;
public static boolean TEST_SKIP_CLOSE = false;
public MiniHBaseClusterRegionServer(Configuration conf, CoordinatedStateManager cp)
throws IOException, InterruptedException {
@ -161,6 +159,7 @@ public class MiniHBaseCluster extends HBaseCluster {
super.kill();
}
@Override
public void abort(final String reason, final Throwable cause) {
this.user.runAs(new PrivilegedAction<Object>() {
public Object run() {