Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 91EF42009FB for ; Fri, 6 May 2016 17:47:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9086D160A0E; Fri, 6 May 2016 15:47:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B26341608F8 for ; Fri, 6 May 2016 17:47:57 +0200 (CEST) Received: (qmail 32923 invoked by uid 500); 6 May 2016 15:47:53 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 31476 invoked by uid 99); 6 May 2016 15:47:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 May 2016 15:47:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 57D3CE947C; Fri, 6 May 2016 15:47:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aw@apache.org To: common-commits@hadoop.apache.org Date: Fri, 06 May 2016 15:48:07 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/28] hadoop git commit: HADOOP-13095. hadoop-hdfs unit tests for dynamic commands archived-at: Fri, 06 May 2016 15:47:58 -0000 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/e3d89a18 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e3d89a18 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e3d89a18 Branch: refs/heads/HADOOP-12930 Commit: e3d89a1886fbea48b3b1e40e04939076fda16895 Parents: 2c7aa94 Author: Allen Wittenauer Authored: Wed May 4 20:40:39 2016 -0700 Committer: Allen Wittenauer Committed: Fri May 6 08:46:54 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/e3d89a18/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 668bbfe..c8198c1 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"> - + startKdc @@ -559,5 +559,41 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + + + shelltest + + + !skipTests + + + + + + maven-antrun-plugin + + + hdfs-test-bats-driver + test + + run + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/hadoop/blob/e3d89a18/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/e3d89a18/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/e3d89a18/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