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 12d11e3bdc8f9b2009504e5dd9b9dfac2df41217
Author: Xiaobing Zhou <[email protected]>
AuthorDate: Mon Aug 7 17:51:34 2017 -0700

    HBASE-18536. [C++] Add fault injection infra
    
    Signed-off-by: Enis Soztutar <[email protected]>
---
 hbase-native-client/connection/BUCK                |  3 ++
 .../connection/rpc-fault-injector-inl.h            | 41 ++++++++++++++++++
 .../connection/rpc-fault-injector.cc               | 21 +++++++++
 .../connection/rpc-fault-injector.h                | 50 ++++++++++++++++++++++
 4 files changed, 115 insertions(+)

diff --git a/hbase-native-client/connection/BUCK 
b/hbase-native-client/connection/BUCK
index aaf8fdb..a87d27a 100644
--- a/hbase-native-client/connection/BUCK
+++ b/hbase-native-client/connection/BUCK
@@ -35,6 +35,8 @@ cxx_library(
         "sasl-util.h",
         "rpc-test-server.h",
         "rpc-test-server-handler.h",
+        "rpc-fault-injector.h",
+        "rpc-fault-injector-inl.h",
     ],
     srcs=[
         "client-dispatcher.cc",
@@ -48,6 +50,7 @@ cxx_library(
         "sasl-util.cc",
         "rpc-test-server.cc",
         "rpc-test-server-handler.cc",
+        "rpc-fault-injector.cc",
     ],
     deps=[
         "//if:if",
diff --git a/hbase-native-client/connection/rpc-fault-injector-inl.h 
b/hbase-native-client/connection/rpc-fault-injector-inl.h
new file mode 100644
index 0000000..8bbaddf
--- /dev/null
+++ b/hbase-native-client/connection/rpc-fault-injector-inl.h
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ *
+ */
+#pragma once
+
+namespace hbase {
+
+template <typename T>
+std::shared_ptr<T> RpcFaultInjector<T>::instance = std::make_shared<T>();
+
+template <typename T>
+RpcFaultInjector<T>::RpcFaultInjector() {}
+
+template <typename T>
+RpcFaultInjector<T>::~RpcFaultInjector() {}
+
+template <typename T>
+std::shared_ptr<T> RpcFaultInjector<T>::Get() {
+  return instance;
+}
+
+template <typename T>
+void RpcFaultInjector<T>::Set(std::shared_ptr<T> injector) {
+  instance = injector;
+}
+} /* namespace hbase */
diff --git a/hbase-native-client/connection/rpc-fault-injector.cc 
b/hbase-native-client/connection/rpc-fault-injector.cc
new file mode 100644
index 0000000..16e2034
--- /dev/null
+++ b/hbase-native-client/connection/rpc-fault-injector.cc
@@ -0,0 +1,21 @@
+/*
+ * 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 "rpc-fault-injector.h"
+
+namespace hbase {} /* namespace hbase */
diff --git a/hbase-native-client/connection/rpc-fault-injector.h 
b/hbase-native-client/connection/rpc-fault-injector.h
new file mode 100644
index 0000000..2733b7d
--- /dev/null
+++ b/hbase-native-client/connection/rpc-fault-injector.h
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ *
+ */
+#pragma once
+
+#include <folly/io/async/AsyncTransport.h>
+#include "connection/pipeline.h"
+
+namespace hbase {
+
+template <typename T>
+class RpcFaultInjector {
+ public:
+  RpcFaultInjector();
+  virtual ~RpcFaultInjector();
+
+  static std::shared_ptr<T> Get();
+  static void Set(std::shared_ptr<T> instance);
+
+ private:
+  static std::shared_ptr<T> instance;
+};
+
+class RpcClientFaultInjector : public RpcFaultInjector<RpcClientFaultInjector> 
{
+ public:
+  RpcClientFaultInjector() {}
+  virtual ~RpcClientFaultInjector() {}
+  /**
+   * Here goes virtual functions for injecting various faults. They should be 
no-ops by default.
+   * Sub classes of RpcClientFaultInjector will override by providing concrete 
faults.
+   */
+};
+} /* namespace hbase */
+
+#include "connection/rpc-fault-injector-inl.h"

Reply via email to