From ec1d54043ab3f4c31af1043c4a07f5db92e5a5ec Mon Sep 17 00:00:00 2001 From: Xiaobing Zhou Date: Mon, 7 Aug 2017 17:51:34 -0700 Subject: [PATCH] HBASE-18536. [C++] Add fault injection infra --- 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(+) create mode 100644 hbase-native-client/connection/rpc-fault-injector-inl.h create mode 100644 hbase-native-client/connection/rpc-fault-injector.cc create mode 100644 hbase-native-client/connection/rpc-fault-injector.h diff --git a/hbase-native-client/connection/BUCK b/hbase-native-client/connection/BUCK index aaf8fdbe35..a87d27ae1c 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 0000000000..8bbaddf7df --- /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 +std::shared_ptr RpcFaultInjector::instance = std::make_shared(); + +template +RpcFaultInjector::RpcFaultInjector() {} + +template +RpcFaultInjector::~RpcFaultInjector() {} + +template +std::shared_ptr RpcFaultInjector::Get() { + return instance; +} + +template +void RpcFaultInjector::Set(std::shared_ptr 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 0000000000..16e2034d6f --- /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 0000000000..2733b7d415 --- /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 +#include "connection/pipeline.h" + +namespace hbase { + +template +class RpcFaultInjector { + public: + RpcFaultInjector(); + virtual ~RpcFaultInjector(); + + static std::shared_ptr Get(); + static void Set(std::shared_ptr instance); + + private: + static std::shared_ptr instance; +}; + +class RpcClientFaultInjector : public RpcFaultInjector { + 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" -- 2.11.0 (Apple Git-81)