java之在 Windows 7 上使用 Hadoop 2.2 运行 JUnit 测试

mfrbuaa 阅读:14 2024-08-05 10:48:10 评论:0

我正在尝试使用 Hadoop 2.2 运行一个简单的 JUnit 测试。在我的 Windows 7 机器上。
我在 http://grepalex.com/2012/10/20/hadoop-unit-testing-with-minimrcluster/ 有一个示例性测试可用所以我使用 ClusterMapReduceTestCase 作为基类来启动 MiniDFSCluster。

运行测试时,我得到(在控制台中):

2013-11-15 11:59:24,636 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(303)) - Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:278) at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:300) at org.apache.hadoop.util.Shell.(Shell.java:293) at org.apache.hadoop.util.StringUtils.(StringUtils.java:76) (...)



并在 JUnit 输出中:

java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z at org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method) at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:435) at org.apache.hadoop.fs.FileUtil.canWrite(FileUtil.java:996) at org.apache.hadoop.hdfs.server.common.Storage$StorageDirectory.analyzeStorage(Storage.java:451) at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverStorageDirs(FSImage.java:282) at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:200) (...)



我已阅读以下线程: Failed to locate the winutils binary in the hadoop binary pathRunning Apache Hadoop 2.1.0 on Windows
我还查看了 http://www.srccodes.com/p/article/38/build-install-configure-run-apache-hadoop-2.2.0-microsoft-windows-os 中可用的可能解决方案。和 http://www.srccodes.com/p/article/39/error-util-shell-failed-locate-winutils-binary-hadoop-binary-path

不幸的是,在 JUnit 测试的情况下,这不起作用。如果我编写 junit 测试,我希望它们独立于开发环境(这样你就可以在每台开发人员机器上毫无问题地运行)。因此,我正在使用 maven,我不想自己构建所需的库并将它们放在 Hadoop bin 文件夹等中。

任何建议在这种情况下最好的解决方案是什么?

请您参考如下方法:

在答案发布后的时间里,Hadoop 3 已经出来了。但是,重点仍然放在非 Windows 系统上。基于 this页面甚至 Microsoft 的分发不再在 Windows 上可用。
虽然测试是另一回事,但结果是 Windows 的测试不太可能受到很多人的喜爱,并且仍然需要一种解决方法。
This answer ,被接受回答一个非常相似的问题,关键步骤:

  • http://public-repo-1.hortonworks.com/hdp-win-alpha/winutils.exe 下载 winutils.exe .
  • 设置您的 HADOOP_HOME操作系统级别的环境变量或以编程方式:System.setProperty("hadoop.home.dir", "full path to the folder with winutils");

  • 如果这对人们来说仍然是一个重要的话题,请注意在堆栈溢出上发布可能无济于事(如果有更好的解决方案,那么现在可能已经有人发布了)。相反,我建议他们在 hadoop jira 上记录请求。 ,并在此处的评论中添加指向它的链接以避免重复。


    标签:java
    声明

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    关注我们

    一个IT知识分享的公众号