make MiniClusterTestCase more like HBaseClusterTestCase in MiniDFSCluster

handling: speeds shutdown, uses desired temporary dir


git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@916171 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2010-02-25 08:06:37 +00:00
parent 2c16fa070f
commit c9cc5f7b33
1 changed files with 14 additions and 17 deletions

View File

@ -30,9 +30,9 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.LocalHBaseCluster;
import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.MiniZooKeeperCluster; import org.apache.hadoop.hbase.MiniZooKeeperCluster;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
@ -77,27 +77,27 @@ public class MiniClusterTestCase extends TestCase {
LOG.error("MiniDFSCluster already running"); LOG.error("MiniDFSCluster already running");
return; return;
} }
Path path = new Path( // This spews a bunch of warnings about missing scheme. TODO: fix.
conf.get("test.build.data", dfsCluster = new MiniDFSCluster(0, conf, 2, true, true, true,
System.getProperty("test.build.data", "build/test/data"))); null, null, null, null);
FileSystem testFS = FileSystem.get(conf); // mangle the conf so that the fs parameter points to the minidfs we
if (testFS.exists(path)) { // just started up
testFS.delete(path, true);
}
testDir = new File(path.toString());
dfsCluster = new MiniDFSCluster(conf, 2, true, (String[])null);
FileSystem filesystem = dfsCluster.getFileSystem(); FileSystem filesystem = dfsCluster.getFileSystem();
conf.set("fs.defaultFS", filesystem.getUri().toString()); conf.set("fs.defaultFS", filesystem.getUri().toString());
Path parentdir = filesystem.getHomeDirectory(); Path parentdir = filesystem.getHomeDirectory();
conf.set(HConstants.HBASE_DIR, parentdir.toString()); conf.set(HConstants.HBASE_DIR, parentdir.toString());
filesystem.mkdirs(parentdir); filesystem.mkdirs(parentdir);
FSUtils.setVersion(filesystem, parentdir); FSUtils.setVersion(filesystem, parentdir);
LOG.info("started MiniDFSCluster in " + testDir.toString());
} }
private static void stopDFS() { private static void stopDFS() {
if (dfsCluster != null) try { if (dfsCluster != null) try {
dfsCluster.shutdown(); FileSystem fs = dfsCluster.getFileSystem();
if (fs != null) {
LOG.info("Shutting down FileSystem");
fs.close();
}
FileSystem.closeAll();
dfsCluster = null; dfsCluster = null;
} catch (Exception e) { } catch (Exception e) {
LOG.warn(StringUtils.stringifyException(e)); LOG.warn(StringUtils.stringifyException(e));
@ -136,10 +136,7 @@ public class MiniClusterTestCase extends TestCase {
private static void stopHBase() { private static void stopHBase() {
if (hbaseCluster != null) try { if (hbaseCluster != null) try {
for (LocalHBaseCluster.RegionServerThread regionThread: HConnectionManager.deleteConnectionInfo(conf, true);
hbaseCluster.getRegionThreads()) {
regionThread.getRegionServer().abort();
}
hbaseCluster.shutdown(); hbaseCluster.shutdown();
hbaseCluster = null; hbaseCluster = null;
} catch (Exception e) { } catch (Exception e) {