Hadoop 2.7.1 使用minicluster进行单元测试
目的是要跑通这个单元测试:hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestClose.java

这个Java文件比较简单:
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdfs; import static org.junit.Assert.fail; import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.ClosedChannelException; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; public class TestClose { @Test
public void testWriteAfterClose() throws IOException {
Configuration conf = new Configuration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
.build(); try {
final byte[] data = "foo".getBytes(); FileSystem fs = FileSystem.get(conf);
OutputStream out = fs.create(new Path("/test")); out.write(data);
out.close();
try {
// Should fail.
out.write(data);
fail("Should not have been able to write more data after file is closed.");
} catch (ClosedChannelException cce) {
// We got the correct exception. Ignoring.
}
// Should succeed. Double closes are OK.
out.close();
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
} }
通过实例化一个minicluster来测试hdfs的关闭功能是否正常。
直接运行Junit,将会报错,因为在CLASSPATH中找不到webapps/hdfs。

正确的做法(https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/CLIMiniCluster.html )
要现在~/CVS/hadoop目录下执行如下两条命令:
hadoop@ubuntu:~/CVS/hadoop$ mvn clean install –DskipTests
hadoop@ubuntu:~/CVS/hadoop$ mvn package -Pdist -Dtar -DskipTests -Dmaven.javadoc.skip
执行完这两条命令后,会在如下目录生成webapps目录:

也就是说这个webapps目录是通过上面两条命令生成的,如果没有执行上面两条命令,那么这个目录下就不会有这个文件,导致java在运行时无法在CLASSPATH中找到这个文件夹。一切准备就绪,运行Junit,可以看到单元测试成功通过:

Hadoop 2.7.1 使用minicluster进行单元测试的更多相关文章
- Hadoop百度百科
http://baike.baidu.com/link?url=-lfWMjGNGBJxKC1QKKhefXvB7Wou6Ztn8mgeZf8u-1iH5fcf25lbRfqpW1SGwOmQL0JI ...
- Hadoop Brief
Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储. [1] Hadoop实现了一个分布 ...
- 杂项:Hadoop
ylbtech-杂项:Hadoop Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Ha ...
- 吴裕雄--天生自然Hadoop学习笔记:Hadoop简介
Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop实现了一个分布式文件系统(H ...
- Java操作Hadoop集群
mavenhdfsMapReduce 1. 配置maven环境 2. 创建maven项目 2.1 pom.xml 依赖 2.2 单元测试 3. hdfs文件操作 3.1 文件上传和下载 3.2 RPC ...
- 使用MRUnit,Mockito和PowerMock进行Hadoop MapReduce作业的单元测试
0.preliminary 环境搭建 Setup development environment Download the latest version of MRUnit jar from Apac ...
- Hadoop CLI MiniCluster
CLI MiniCluster Use the climonicluster, users can simply start and stop a single-node hadoop cluster ...
- 在HADOOP中使用MRUNIT进行单元测试
在HADOOP中使用MRUNIT进行单元测试 前提 1. 了解JUnit4.x的使用. 2. 了解Mock的概念在单元测试中的应用. 3. 了解Hadoop中MapReduce的编程模型. 如果您对J ...
- hadoop编程技巧(8)---Unit Testing (单元测试)
所需的环境: Hadoop相关jar包裹(下载版本的官方网站上可以): 下载junit包裹(新以及). 下载mockito包裹: 下载mrunit包裹: 下载powermock-mockito包裹: ...
随机推荐
- 【09_242】Valid Anagram
Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...
- 第35讲:List的map、flatMap、foreach、filter操作代码实战
List类的高阶方法 val fmap = List( 1,2 ,3). map { _ + 1 } //List(2, 3, 4) val fruit_rev2 = frui ...
- EJB到底是什么,真的那么神秘吗??
1. 我们不禁要问,什么是"服务集群"?什么是"企业级开发"? 既然说了EJB 是为了"服务集群"和"企业级开发",那么 ...
- HTML锁定Table中某一列
1. 2. 3. function ChangeTable() { var type = document.getElementById("ddl_ReportType").val ...
- 【Python自动化运维之路Day7】
1. configparser模块 import configparser config = configparser.ConfigParser() #先把config应用一下configparser ...
- Arcgis for Javascript 在VS2012中的智能提示
官方地址: https://developers.arcgis.com/en/javascript/jsapi/api_codeassist.html 安装步骤 Visual Studio 2010 ...
- CBA 赛程的笔记 - 北京首钢
2014-11-01 19:35 北京首钢 103:89 广东宏远 结束 技术统计 发挥不错,打的比较好! 2014-11-05 19:35 八一双鹿 89:100 北京首钢 结束 技术统计 第一 ...
- 02-Vue入门之数据绑定
2.1. 什么是双向绑定? Vue框架很核心的功能就是双向的数据绑定. 双向是指:HTML标签数据 绑定到 Vue对象,另外反方向数据也是绑定的.通俗点说就是,Vue对象的改变会直接影响到HTML的标 ...
- Intellij IDEA13无法使用SVN
症状:在公司里面idea13工作正常,到了家里后idea的svn就是无法正常工作,单独使用tortoisesvn一切正常,后来在网上看到有网友解决了这个问题,看了之后明白了为啥公司的正常,家里的不行, ...
- Null 与 “” 的区别
说明:很多人有时候对于 null 和 "" 不是很清楚,结合其他人的文章,今天做下解释. String str1 = null; str引用为空 String str2 = &qu ...