maven - 使用 Local Runner 在独立模式下运行 Hadoop 2.4.0 作业的单元测试

标签 maven unit-testing hadoop junit

在使用以前版本的 Hadoop 时,我通常会为整个作业(映射器和缩减器)构建 junit 测试,并通过调用 maven 或直接从 IDE 本身运行测试。系统上的任何地方都没有安装 hadoop。我使用以下属性来确保使用本地进程内运行器:

config.set("mapred.job.tracker", "local");
config.set("fs.default.name", "file:///test-fs");

这些测试运行成功。

我升级到较新版本的 Hadoop (2.4.0) 以利用新的 API。我希望能够像以前一样用我的单元做同样的事情。我现在使用的属性是:

config.set("fs.default.name", "file:///test-fs");
config.set("mapreduce.jobtracker.address", "local");
config.set("mapreduce.framework.name", "local");

我在测试中构建配置对象并将其传递给创建作业对象的实际代码。

但是,这不起作用,我收到以下错误:

java.io.IOException:无法初始化集群。请检查您的配置以获取 mapreduce.framework.name 和相应的服务器地址。 在 org.apache.hadoop.mapreduce.Cluster.initialize(Cluster.java:120) 在 org.apache.hadoop.mapreduce.Cluster.(Cluster.java:82) 在 org.apache.hadoop.mapreduce.Cluster.(Cluster.java:75) 在 org.apache.hadoop.mapreduce.Job$9.run(Job.java:1255) 在 org.apache.hadoop.mapreduce.Job$9.run(Job.java:1251) 在 java.security.AccessController.doPrivileged( native 方法) 在 javax.security.auth.Subject.doAs(Subject.java:415) 在 org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548) 在 org.apache.hadoop.mapreduce.Job.connect(Job.java:1250) 在 org.apache.hadoop.mapreduce.Job.submit(Job.java:1279) 在 org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1303) 在 com.roblox.games.retention.W1ReturnFromNewPlayersThePreviousWeekCalculatorJob1.calculateW1ReturnJob1(W1ReturnFromNewPlayersThePreviousWeekCalculatorJob1.java:68) 在 com.roblox.games.retention.W1ReturnFromNewPlayersThePreviousWeekCalculatorDriver.calculateW1Return(W1ReturnFromNewPlayersThePreviousWeekCalculatorDriver.java:74) 在 com.roblox.games.retention.W1ReturnFromNewPlayersThePreviousWeekCalculatorDriverTest.testCase(W1ReturnFromNewPlayersThePreviousWeekCalculatorDriverTest.java:89) 在 sun.reflect.NativeMethodAccessorImpl.invoke0( native 方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:606) 在 junit.framework.TestCase.runTest(TestCase.java:154) 在 junit.framework.TestCase.runBare(TestCase.java:127) 在 junit.framework.TestResult$1.protect(TestResult.java:106) 在 junit.framework.TestResult.runProtected(TestResult.java:124) 在 junit.framework.TestResult.run(TestResult.java:109) 在 junit.framework.TestCase.run(TestCase.java:118) 在 junit.framework.TestSuite.runTest(TestSuite.java:208) 在 junit.framework.TestSuite.run(TestSuite.java:203) 在 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

谁能指出我做错了什么?重申一下,我在运行这些测试的主机上没有任何 hadoop 安装或二进制文件。

最佳答案

我在 hadoop 2.7.1 上遇到了同样的问题,并通过添加一个为独立模式提供协议(protocol)实现的依赖项来修复它,该类的名称是 org.apache.hadoop.mapred.LocalClientProtocolProvider

<dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-mapreduce-client-common</artifactId>
        <version>2.7.1</version>
        <scope>test</scope>
</dependency>

您不需要设置“mapred.job.tracker”或“fs.default.name”,因为独立运行器会自动从类路径加载。

关于maven - 使用 Local Runner 在独立模式下运行 Hadoop 2.4.0 作业的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584642/

相关文章:

hadoop - Sqoop Hive 表导入,表数据类型与数据库不匹配

hadoop - 我要做什么需要 pig 圈?

arrays - Hive Array<Struct<>>插入显示null

maven - 指定 Maven 内存参数而不设置 MAVEN_OPTS 环境变量

maven - activemq 拒绝远程连接

unit-testing - 如何设计和测试具有复杂编排逻辑的方法?

java - 通过 Ant 运行 Junit 似乎没有使用自定义类运行器

python - Django 单元测试数据库没有被拆除?

maven - 在kubernetes上的Jenkinsfile Maven构建中正确覆盖 "settings.xml"吗?

java - 使用 Maven 自动验证 JavaDoc