You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2019/03/12 12:44:50 UTC
[hbase] 02/133: HBASE-15078 Added ability to start/stop hbase local
cluster for tests, global test_env for gtest,
small changes to dockerfile and docker run.
This is an automated email from the ASF dual-hosted git repository.
zghao pushed a commit to branch HBASE-14850
in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 0286c72c07acedcf39296ed07a2276890982bdc0
Author: Mikhail Antonov <an...@apache.org>
AuthorDate: Wed Jan 6 15:08:21 2016 -0800
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
---
hbase-native-client/.buckconfig | 2 +-
hbase-native-client/Dockerfile | 2 +-
hbase-native-client/bin/start-docker.sh | 10 +++++-
.../start_local_hbase_and_wait.sh} | 12 ++++---
.../stop_local_hbase_and_wait.sh} | 12 ++++---
hbase-native-client/core/BUCK | 15 ++++++++
.../core/HBaseNativeClientTestEnv.cc | 42 ++++++++++++++++++++++
hbase-native-client/core/SampleNativeClientTest.cc | 28 +++++++++++++++
hbase-native-client/core/test_env.h | 30 ++++++++++++++++
9 files changed, 142 insertions(+), 11 deletions(-)
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
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
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
diff --git a/hbase-native-client/Dockerfile b/hbase-native-client/bin/start_local_hbase_and_wait.sh
old mode 100644
new mode 100755
similarity index 78%
copy from hbase-native-client/Dockerfile
copy to hbase-native-client/bin/start_local_hbase_and_wait.sh
index 70e823b..64d0b68
--- a/hbase-native-client/Dockerfile
+++ b/hbase-native-client/bin/start_local_hbase_and_wait.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
##
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -15,8 +17,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM pjameson/buck-folly-watchman
-
-RUN apt-get install -y libprotobuf-dev protobuf-compiler clang-format-3.7 vim
+$PWD/../bin/start-hbase.sh
-WORKDIR /usr/local/src/hbase/hbase-native-client
+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
diff --git a/hbase-native-client/Dockerfile b/hbase-native-client/bin/stop_local_hbase_and_wait.sh
old mode 100644
new mode 100755
similarity index 79%
copy from hbase-native-client/Dockerfile
copy to hbase-native-client/bin/stop_local_hbase_and_wait.sh
index 70e823b..4e89334
--- a/hbase-native-client/Dockerfile
+++ b/hbase-native-client/bin/stop_local_hbase_and_wait.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
##
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -15,8 +17,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM pjameson/buck-folly-watchman
-
-RUN apt-get install -y libprotobuf-dev protobuf-compiler clang-format-3.7 vim
+$PWD/../bin/stop-hbase.sh
-WORKDIR /usr/local/src/hbase/hbase-native-client
+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
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,
+)
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();
+}
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);
+}
+
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");
+}