You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aw...@apache.org on 2016/05/15 14:51:05 UTC
[25/31] hadoop git commit: HADOOP-13095. hadoop-hdfs unit tests for
dynamic commands
HADOOP-13095. hadoop-hdfs unit tests for dynamic commands
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a94b33c3
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a94b33c3
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a94b33c3
Branch: refs/heads/HADOOP-12930
Commit: a94b33c306f1b3fefe82c063133ddfe085cbbed9
Parents: ef3072d
Author: Allen Wittenauer <aw...@apache.org>
Authored: Wed May 4 20:40:39 2016 -0700
Committer: Allen Wittenauer <aw...@apache.org>
Committed: Sun May 15 07:50:15 2016 -0700
----------------------------------------------------------------------
hadoop-hdfs-project/hadoop-hdfs/pom.xml | 38 ++++++++++-
.../scripts/hdfs-functions_test_helper.bash | 58 +++++++++++++++++
.../src/test/scripts/hdfs_subcommands.bats | 66 ++++++++++++++++++++
.../hadoop-hdfs/src/test/scripts/run-bats.sh | 43 +++++++++++++
4 files changed, 204 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/a94b33c3/hadoop-hdfs-project/hadoop-hdfs/pom.xml
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/pom.xml b/hadoop-hdfs-project/hadoop-hdfs/pom.xml
index 2d534bf..3696797 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/pom.xml
+++ b/hadoop-hdfs-project/hadoop-hdfs/pom.xml
@@ -417,7 +417,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</plugins>
</build>
- <profiles>
+ <profiles>
<!-- profile that starts ApacheDS KDC server -->
<profile>
<id>startKdc</id>
@@ -559,5 +559,41 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
</plugins>
</build>
</profile>
+
+ <!-- profile to test shell code -->
+ <profile>
+ <id>shelltest</id>
+ <activation>
+ <property>
+ <name>!skipTests</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>hdfs-test-bats-driver</id>
+ <phase>test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <exec dir="src/test/scripts"
+ executable="bash"
+ failonerror="true">
+ <arg value="./run-bats.sh" />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
</profiles>
</project>
http://git-wip-us.apache.org/repos/asf/hadoop/blob/a94b33c3/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs-functions_test_helper.bash
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs-functions_test_helper.bash b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs-functions_test_helper.bash
new file mode 100755
index 0000000..d3cdda4
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs-functions_test_helper.bash
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# 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.
+
+setup() {
+
+ TMP="${BATS_TEST_DIRNAME}/../../../target/test-dir/bats.$$.${RANDOM}"
+ mkdir -p "${TMP}"
+ TMP=$(cd -P -- "${TMP}" >/dev/null && pwd -P)
+ export TMP
+ TESTBINDIR="${BATS_TEST_DIRNAME}"
+ HADOOP_LIBEXEC_DIR=${TESTBINDIR}/../../main/bin
+ HADOOP_LIBEXEC_DIR=$(cd -P -- "${HADOOP_LIBEXEC_DIR}" >/dev/null && pwd -P)
+
+ # shellcheck disable=SC2034
+ HADOOP_SHELL_SCRIPT_DEBUG=true
+ unset HADOOP_CONF_DIR
+ # we unset both of these for bw compat
+ unset HADOOP_HOME
+ unset HADOOP_PREFIX
+
+ echo "bindir: ${TESTBINDIR}" 2>&1
+
+ mkdir -p "${TMP}"
+
+ # shellcheck disable=SC2034
+ QATESTMODE=true
+
+ # shellcheck disable=SC1090
+ . "${BATS_TEST_DIRNAME}/../../../../../hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh"
+ pushd "${TMP}" >/dev/null
+}
+
+teardown() {
+ popd >/dev/null
+ rm -rf "${TMP}"
+}
+
+
+strstr() {
+ if [ "${1#*$2}" != "${1}" ]; then
+ echo true
+ else
+ echo false
+ fi
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/a94b33c3/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs_subcommands.bats
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs_subcommands.bats b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs_subcommands.bats
new file mode 100755
index 0000000..33fb9aa
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/hdfs_subcommands.bats
@@ -0,0 +1,66 @@
+# 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.
+
+load hdfs-functions_test_helper
+
+# the loading of shell profiles are tested elseswhere
+# this only tests the specific subcommand parts
+
+subcommandsetup () {
+ export HADOOP_LIBEXEC_DIR="${TMP}/libexec"
+ export HADOOP_CONF_DIR="${TMP}/conf"
+ mkdir -p "${HADOOP_LIBEXEC_DIR}/shellprofile.d" "${HADOOP_CONF_DIR}/shellprofile.d"
+ cat <<-'TOKEN' > "${HADOOP_LIBEXEC_DIR}/hdfs-config.sh"
+
+hdfs_subcommand_sub () {
+ echo "unittest"
+ exit 0
+}
+
+hdfs_subcommand_cacheadmin ()
+{
+ echo cacheadmin
+ exit 0
+}
+
+hdfs_subcommand_envcheck ()
+{
+ echo ${HADOOP_SHELL_EXECNAME}
+ exit 0
+}
+TOKEN
+ chmod a+rx "${HADOOP_LIBEXEC_DIR}/hdfs-config.sh"
+
+}
+
+@test "hdfs_subcommand (addition)" {
+ subcommandsetup
+ run "${BATS_TEST_DIRNAME}/../../main/bin/hdfs" sub
+ echo ">${output}<"
+ [ "${output}" = unittest ]
+}
+
+@test "hdfs_subcommand (substitute)" {
+ subcommandsetup
+ run "${BATS_TEST_DIRNAME}/../../main/bin/hdfs" cacheadmin
+ echo ">${output}<"
+ [ "${output}" = cacheadmin ]
+}
+
+@test "hdfs_subcommand (envcheck)" {
+ subcommandsetup
+ run "${BATS_TEST_DIRNAME}/../../main/bin/hdfs" envcheck
+ [ "${output}" = hdfs ]
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/a94b33c3/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/run-bats.sh
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/run-bats.sh b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/run-bats.sh
new file mode 100755
index 0000000..566f47a
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/scripts/run-bats.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# 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.
+
+targetdir=../../../target
+mkdir -p ${targetdir}/surefire-reports ${targetdir}/tap
+
+batsexe=$(which bats) 2>/dev/null
+
+if [[ -z ${batsexe} ]]; then
+ echo "not ok - no bats executable found" > "${targetdir}/tap/shelltest.tap"
+ echo ""
+ echo ""
+ echo "ERROR: bats not installed. Skipping bash tests."
+ echo "ERROR: Please install bats as soon as possible."
+ echo ""
+ echo ""
+ exit 0
+fi
+
+for j in *.bats; do
+ echo Running bats -t "${j}"
+ bats -t "${j}" 2>&1 | tee "${targetdir}/tap/${j}.tap"
+ result=${PIPESTATUS[0]}
+ ((exitcode=exitcode+result))
+done
+
+if [[ ${exitcode} -gt 0 ]]; then
+ exit 1
+fi
+exit 0
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org