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 bc0e5fc048
commit 5728416419
2 changed files with 20 additions and 61 deletions

View File

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

View File

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