使用 mvn test
运行hadoop单元测试时,出现以下报错
[exec] ok 1 hadoop_add_classpath (simple not exist)
[exec] ok 2 hadoop_add_classpath (simple wildcard not exist)
[exec] ok 3 hadoop_add_classpath (simple exist)
[exec] ok 4 hadoop_add_classpath (simple wildcard exist)
[exec] not ok 5 hadoop_add_classpath (simple dupecheck)
[exec] # (in test file hadoop_add_classpath.bats, line 42)
[exec] # `[ "${CLASSPATH}" = "${TMP}/*" ]' failed
[exec] # bindir: /home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/src/test/scripts
[exec] # DEBUG: Append CLASSPATH: /home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/test-dir/bats.239521.1805/*
[exec] # DEBUG: Dupe CLASSPATH: /home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/test-dir/bats.239521.1805/*
[exec] # >.:/usr/lib/jvm/java-7-sun/lib:/usr/lib/jvm/java-7-sun/jre/lib:/usr/lib/jvm/java-7-sun/lib/tools.jar:/home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/test-dir/bats.239521.1805/*<
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:09 min
[INFO] Finished at: 2021-12-09T14:22:43+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (common-test-bats-driver) on project hadoop-common: An Ant BuildException has occured: exec returned: 1
[ERROR] around Ant part ...<exec failonerror="true" dir="src/test/scripts" executable="bash">... @ 4:69 in /home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/antrun/build-main.xml
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (common-test-bats-driver) on project hadoop-common: An Ant BuildException has occured: exec returned: 1
around Ant part ...<exec failonerror="true" dir="src/test/scripts" executable="bash">... @ 4:69 in /home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/antrun/build-main.xml
找到报错对应的脚本
hadoop-common-project/hadoop-common/src/test/scripts/hadoop_add_classpath.bats
...
@test "hadoop_add_classpath (simple dupecheck)" {
hadoop_add_classpath "${TMP}/*"
hadoop_add_classpath "${TMP}/*"
echo ">${CLASSPATH}<"
[ "${CLASSPATH}" = "${TMP}/*" ]
}
...
这个脚本是用来测试hadoop_add_classpath
命令的,这里的逻辑是添加${TMP}/*
到CLASSPATH,然后判断CLASSPATH是否等于${TMP}/*
但因为环境中已经有默认的CLASSPATH
echo $CLASSPATH
.:/usr/lib/jvm/java-7-sun/lib:/usr/lib/jvm/java-7-sun/jre/lib:/usr/lib/jvm/java-7-sun/lib/tools.jar
导致${TMP}/*=/home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/test-dir/bats.239521.1805/*
而${CLASSPATH}=.:/usr/lib/jvm/java-7-sun/lib:/usr/lib/jvm/java-7-sun/jre/lib:/usr/lib/jvm/java-7-sun/lib/tools.jar:/home/hadoop/tmp/hadoop3/hadoop-common-project/hadoop-common/target/test-dir/bats.239521.1805/*
两者不相等所以报错
解决
先将CLASSPATH设置为空
export CLASSPATH=