private void setupMiniDfsAndMrClusters() {
    try {
      final int dataNodes = 1;     // There will be 4 data nodes
      final int taskTrackers = 1;  // There will be 4 task tracker nodes
      Configuration config = new Configuration();

      // Builds and starts the mini dfs and mapreduce clusters
      if(System.getProperty("hadoop.log.dir") == null) {
        System.setProperty("hadoop.log.dir", "target/tmp/logs/");
      }
      m_dfs = new MiniDFSCluster(config, dataNodes, true, null);

      m_fileSys = m_dfs.getFileSystem();
      m_mr = new MiniMRCluster(taskTrackers, m_fileSys.getUri().toString(), 1);

      // Create the configuration hadoop-site.xml file
      File conf_dir = new File(System.getProperty("user.home"), "pigtest/conf/");
      conf_dir.mkdirs();
      File conf_file = new File(conf_dir, "hadoop-site.xml");

      // Write the necessary config info to hadoop-site.xml
      m_conf = m_mr.createJobConf();
      m_conf.setInt("mapred.submit.replication", 1);
      m_conf.set("dfs.datanode.address", IPStackUtils.concatWildcardAddressPort(0));
      m_conf.set("dfs.datanode.http.address", IPStackUtils.concatWildcardAddressPort(0));
      m_conf.writeXml(new FileOutputStream(conf_file));

      // Set the system properties needed by Pig
      System.setProperty("cluster", m_conf.get("mapred.job.tracker"));
      System.setProperty("namenode", m_conf.get("fs.default.name"));
      System.setProperty("junit.hadoop.conf", conf_dir.getPath());
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
This class builds a single instance of itself with the Singleton
design pattern. While building the single instance, it sets up a
mini cluster that actually consists of a mini DFS cluster and a
mini MapReduce cluster on the local machine and also sets up the
environment for Pig to run on top of the mini cluster.
hcatalog/core/src/test/java/org/apache/hive/hcatalog/MiniCluster.java