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包裹: ...
随机推荐
- 不用ide编译java程序时调用jar包
调用特定目录下的jar包 javac -cp d:\javatest\dom4j.jar Dom4jDemo.java //这部分必须注意,d:\javatest 是Dom4jDemo.class所在 ...
- Spring的定时任务配置2(转)
spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...
- 比较有价值的参考文档-----------------URL
http://www.wendangku.net/doc/f7b4349108a1284ac85043bf.html 曙光服务器的IPMI http://noob.blog.1 ...
- Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2)
上篇我们介绍了Windows 8.1 和 WinJS 中新增控件中的 AppBarCommand.BackButton.Hub.ItemContainer,本篇我们接着来介绍 NavBar.Repea ...
- 数据库知识整理<七>
组合查询: 7.1使用子查询: 嵌套在其他查询中的查询,我们称之为子查询.子查询本身也可能包含一个子查询.子查询也称为内部查询,而包含子查询的语句也称为外部查询. 所有的子查询可以被分为两个类别:子查 ...
- 注册表(regedit)
注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息. 打开方式:1.开始>>运行.中 ...
- django CSRF token missing or incorrect
django 异步请求时提示403 按照一般情况权限问题,python文件没有问题,仔细看了下response里有一句 CSRF token missing or incorrect.这个肯定是因为安 ...
- JS代码风格指南
一.基本格式 缩进 建议每级4个空格,可以给编辑器设置tab = 4个空格,自动转换 分号 不要省略分号,防止ASI(自动插入分号)错误 行宽 每行代码不超过80个字符,过长应该用操作符手动断行 断行 ...
- Windows对象操作:浏览器窗口信息
属性(值或者子对象):opener:打开当前窗口的源窗口,如果当前窗口是首次启动浏览器打开的,则opener是null,可以利用这个属性来关闭源窗口. 属性:Windows.shuxing; 方法(函 ...
- 从MySQL 5.5到5.7看复制的演进
概要:MySQL 5.5 支持单线程模式复制,MySQL 5.6 支持库级别的并行复制,MySQL 5.7 支持事务级别并行复制.结合这个主线我们可以来分析一下MySQL以及社区发展的一个前因后果. ...