Repository: hbase Updated Branches: refs/heads/HBASE-14850 ba68b9992 -> 65aa54885
HBASE-18536. [C++] Add fault injection infra Signed-off-by: Enis Soztutar <e...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/65aa5488 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/65aa5488 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/65aa5488 Branch: refs/heads/HBASE-14850 Commit: 65aa548859d03fbe84c5dd2243e6f5a226db90ac Parents: ba68b99 Author: Xiaobing Zhou <xz...@hortonworks.com> Authored: Mon Aug 7 17:51:34 2017 -0700 Committer: Enis Soztutar <e...@apache.org> Committed: Mon Aug 7 19:20:18 2017 -0700 ---------------------------------------------------------------------- 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(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/65aa5488/hbase-native-client/connection/BUCK ---------------------------------------------------------------------- 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", http://git-wip-us.apache.org/repos/asf/hbase/blob/65aa5488/hbase-native-client/connection/rpc-fault-injector-inl.h ---------------------------------------------------------------------- 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 */ http://git-wip-us.apache.org/repos/asf/hbase/blob/65aa5488/hbase-native-client/connection/rpc-fault-injector.cc ---------------------------------------------------------------------- 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 */ http://git-wip-us.apache.org/repos/asf/hbase/blob/65aa5488/hbase-native-client/connection/rpc-fault-injector.h ---------------------------------------------------------------------- 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"