HBASE-15078 Added ability to start/stop hbase local cluster for tests, global test_env for gtest, small changes to dockerfile and docker run.
Added check ~/.m2 folder exists; moved scripts to ./bin Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/33cabe45 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/33cabe45 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/33cabe45 Branch: refs/heads/HBASE-14850 Commit: 33cabe45a0cfce88b19c5e45aea79ccf333af8f3 Parents: 1f0d4c9 Author: Mikhail Antonov <anto...@apache.org> Authored: Wed Jan 6 15:08:21 2016 -0800 Committer: Elliott Clark <ecl...@apache.org> Committed: Fri Apr 8 12:31:26 2016 -0700 ---------------------------------------------------------------------- hbase-native-client/.buckconfig | 2 +- hbase-native-client/Dockerfile | 2 +- hbase-native-client/bin/start-docker.sh | 10 ++++- .../bin/start_local_hbase_and_wait.sh | 26 ++++++++++++ .../bin/stop_local_hbase_and_wait.sh | 26 ++++++++++++ hbase-native-client/core/BUCK | 15 +++++++ .../core/HBaseNativeClientTestEnv.cc | 42 ++++++++++++++++++++ .../core/SampleNativeClientTest.cc | 28 +++++++++++++ hbase-native-client/core/test_env.h | 30 ++++++++++++++ 9 files changed, 178 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/.buckconfig ---------------------------------------------------------------------- diff --git a/hbase-native-client/.buckconfig b/hbase-native-client/.buckconfig index 3227a2a..402ef27 100644 --- a/hbase-native-client/.buckconfig +++ b/hbase-native-client/.buckconfig @@ -1,2 +1,2 @@ [cxx] - gtest_dep = //third-party/googletest/googletest:google-test + gtest_dep = //third-party:google-test http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/Dockerfile ---------------------------------------------------------------------- diff --git a/hbase-native-client/Dockerfile b/hbase-native-client/Dockerfile index 70e823b..5f17f04 100644 --- a/hbase-native-client/Dockerfile +++ b/hbase-native-client/Dockerfile @@ -17,6 +17,6 @@ FROM pjameson/buck-folly-watchman -RUN apt-get install -y libprotobuf-dev protobuf-compiler clang-format-3.7 vim +RUN apt-get install -y libprotobuf-dev protobuf-compiler clang-format-3.7 vim maven inetutils-ping WORKDIR /usr/local/src/hbase/hbase-native-client http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/bin/start-docker.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/start-docker.sh b/hbase-native-client/bin/start-docker.sh index 1c9b02e..bf38912 100755 --- a/hbase-native-client/bin/start-docker.sh +++ b/hbase-native-client/bin/start-docker.sh @@ -28,5 +28,13 @@ if [[ ! -d third-party/googletest ]]; then git clone https://github.com/google/googletest.git third-party/googletest fi +if [[ ! -d ~/.m2 ]]; then + echo "~/.m2 directory doesn't exist. Check Apache Maven is installed." + exit 1 +fi; -docker run -v ${PWD}/..:/usr/local/src/hbase -it hbase_native /bin/bash +docker run -p 16010:16010/tcp \ + -e "JAVA_HOME=/usr/lib/jvm/java-8-oracle" \ + -v ${PWD}/..:/usr/local/src/hbase \ + -v ~/.m2:/root/.m2 \ + -it hbase_native /bin/bash http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/bin/start_local_hbase_and_wait.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/start_local_hbase_and_wait.sh b/hbase-native-client/bin/start_local_hbase_and_wait.sh new file mode 100755 index 0000000..64d0b68 --- /dev/null +++ b/hbase-native-client/bin/start_local_hbase_and_wait.sh @@ -0,0 +1,26 @@ +#!/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. + +$PWD/../bin/start-hbase.sh + +until [ $(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:16010) == "200" ] +do + printf "Waiting for local HBase cluster to start\n" + sleep 1 +done http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/bin/stop_local_hbase_and_wait.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/stop_local_hbase_and_wait.sh b/hbase-native-client/bin/stop_local_hbase_and_wait.sh new file mode 100755 index 0000000..4e89334 --- /dev/null +++ b/hbase-native-client/bin/stop_local_hbase_and_wait.sh @@ -0,0 +1,26 @@ +#!/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. + +$PWD/../bin/stop-hbase.sh + +while [ $(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:16010) == "200" ] +do + printf "Waiting for local HBase cluster to stop\n" + sleep 1 +done http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/core/BUCK ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/BUCK b/hbase-native-client/core/BUCK index a7eaa9e..2e4e755 100644 --- a/hbase-native-client/core/BUCK +++ b/hbase-native-client/core/BUCK @@ -48,3 +48,18 @@ cxx_binary( 'PUBLIC', ], ) + +cxx_test( + name = "core_test", + headers = [ + "test_env.h", + ], + srcs = [ + "HBaseNativeClientTestEnv.cc", + "SampleNativeClientTest.cc", + ], + deps = [ + ":core", + ], + run_test_separately = True, +) http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/core/HBaseNativeClientTestEnv.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/HBaseNativeClientTestEnv.cc b/hbase-native-client/core/HBaseNativeClientTestEnv.cc new file mode 100644 index 0000000..b8cb8db --- /dev/null +++ b/hbase-native-client/core/HBaseNativeClientTestEnv.cc @@ -0,0 +1,42 @@ +/* + * 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. + * + */ + +#include <gtest/gtest.h> +#include <core/test_env.h> + +namespace { + +class HBaseNativeClientTestEnv : public ::testing::Environment { + public: + void SetUp() override { + init_test_env(); + } + + void TearDown() override { + clean_test_env(); + } +}; + +} // anonymous + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + ::testing::AddGlobalTestEnvironment(new HBaseNativeClientTestEnv()); + return RUN_ALL_TESTS(); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/core/SampleNativeClientTest.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/SampleNativeClientTest.cc b/hbase-native-client/core/SampleNativeClientTest.cc new file mode 100644 index 0000000..ef564f7 --- /dev/null +++ b/hbase-native-client/core/SampleNativeClientTest.cc @@ -0,0 +1,28 @@ +/* + * 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. + * + */ + +#include "gtest/gtest.h" + +/** + * Sample test. + */ +TEST(SampleTest, sample) { + EXPECT_TRUE(true); +} + http://git-wip-us.apache.org/repos/asf/hbase/blob/33cabe45/hbase-native-client/core/test_env.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/core/test_env.h b/hbase-native-client/core/test_env.h new file mode 100644 index 0000000..5796ae1 --- /dev/null +++ b/hbase-native-client/core/test_env.h @@ -0,0 +1,30 @@ +/* + * 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. + * + */ + +#include <cstdlib> + +inline void init_test_env() { + // start local HBase cluster to be reused by all tests + system("scripts/start_local_hbase_and_wait.sh"); +} + +inline void clean_test_env() { + // shutdown local HBase cluster + system("scripts/stop_local_hbase_and_wait.sh"); +}