miniCluster 测试

miniCluster位置:

在你项目下的build/test/data/dfs/name1/current/
有data 和 name1 name2 name3 等等
image文件就在name下的current下

nimiCluster搭建与启动:

demo:

public class ImageToHbaseTest {
  private static Configuration conf;
  private static MiniDFSCluster dfsCluster;
  private static DistributedFileSystem dfs;
  
  @BeforeClass
  public static void setUpClass() throws IOException {
    System.out.println("before class");
    conf = new Configuration();
    conf.set(HDFS_IMAGE_INPUT_DIR_KEY, imagePath);
    conf.set(HdfsRaidConfigKeys.HDFS_IMAGE_OUTPUT_DIR_KEY, resultDir);
    conf.set(HdfsRaidConfigKeys.HDFS_IMAGE_OUTPUT_FILE_KEY, resultFile);

    dfsCluster = new MiniDFSCluster.Builder(conf).build(); // 建立mini cluster
    dfsCluster.waitActive(); // ?
    dfs = dfsCluster.getFileSystem();
    fs = dfsCluster.getFileSystem();
    FSUtils.init(conf); // 一些工具
    RaidTestUtil.init(dfsCluster, conf);
    }
  @Before
  public void before() throws IOException {  //因为miniCluster每启一次就要重新构造一次,
  //所以放在before中,其他Test都能用。
    dfs.mkdirs(new Path("/foo"));  //建立一个目录
    dfs.setQuota(new Path("/foo"), 1000, 100);   //给这个目录设quota
    dfs.mkdirs(new Path("/user"));
    dfs.setQuota(new Path("/user") ,2000,200);
    //这里要是不建这两个目录的话,就只有一个根目录。
  }
  
  @AfterClass
  public static void tearDownClass() throws Exception {
    System.out.println("after class");
    dfsCluster.shutdown();
  }
  @Test
  public void testQuota2Hbase() throws Exception {
    List<String> qthFiles = new ArrayList<String>();
    runAnalyzer();
    Assert.assertEquals(qthFiles, list);
    }
    
  private void runAnalyzer() throws Exception {
    RaidTestUtil.saveImageToPath(dfsCluster, dfs, imagePath);
    ImageToHbase imageToHbase = new ImageToHbase();  
    imageToHbase.init(conf);
    ImageReader imageReader = new ImageReader(imageToHbase, conf);
    imageReader.run();
    list = imageToHbase.getList();
    }
}

这个miniCluster的用法,build起来之后,直接用fs或者dfs来调就好了,用法很简单。
但是如果不知道的话,看别人的代码还是有些吃力。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值