1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CONTRIB_BIGTABLE_KERNELS_TEST_KERNELS_BIGTABLE_TEST_CLIENT_H_ 17 #define TENSORFLOW_CONTRIB_BIGTABLE_KERNELS_TEST_KERNELS_BIGTABLE_TEST_CLIENT_H_ 18 19 #include "google/cloud/bigtable/data_client.h" 20 #include "tensorflow/core/platform/logging.h" 21 #include "tensorflow/core/platform/mutex.h" 22 23 namespace tensorflow { 24 25 class BigtableTestClient : public ::google::cloud::bigtable::DataClient { 26 public: project_id()27 std::string const& project_id() const override { return project_id_; } instance_id()28 std::string const& instance_id() const override { return instance_id_; } reset()29 void reset() override { 30 mutex_lock l(mu_); 31 table_ = Table(); 32 } 33 34 grpc::Status MutateRow( 35 grpc::ClientContext* context, 36 google::bigtable::v2::MutateRowRequest const& request, 37 google::bigtable::v2::MutateRowResponse* response) override; 38 39 grpc::Status CheckAndMutateRow( 40 grpc::ClientContext* context, 41 google::bigtable::v2::CheckAndMutateRowRequest const& request, 42 google::bigtable::v2::CheckAndMutateRowResponse* response) override; 43 44 grpc::Status ReadModifyWriteRow( 45 grpc::ClientContext* context, 46 google::bigtable::v2::ReadModifyWriteRowRequest const& request, 47 google::bigtable::v2::ReadModifyWriteRowResponse* response) override; 48 49 std::unique_ptr<grpc::ClientAsyncResponseReaderInterface< 50 google::bigtable::v2::ReadModifyWriteRowResponse>> 51 AsyncReadModifyWriteRow( 52 grpc::ClientContext* context, 53 google::bigtable::v2::ReadModifyWriteRowRequest const& request, 54 grpc::CompletionQueue* cq) override; 55 56 std::unique_ptr< 57 grpc::ClientReaderInterface<google::bigtable::v2::ReadRowsResponse>> 58 ReadRows(grpc::ClientContext* context, 59 google::bigtable::v2::ReadRowsRequest const& request) override; 60 std::unique_ptr< 61 grpc::ClientReaderInterface<google::bigtable::v2::SampleRowKeysResponse>> 62 SampleRowKeys( 63 grpc::ClientContext* context, 64 google::bigtable::v2::SampleRowKeysRequest const& request) override; 65 66 std::unique_ptr< 67 grpc::ClientReaderInterface<google::bigtable::v2::MutateRowsResponse>> 68 MutateRows(grpc::ClientContext* context, 69 google::bigtable::v2::MutateRowsRequest const& request) override; 70 71 std::unique_ptr<grpc::ClientAsyncResponseReaderInterface< 72 google::bigtable::v2::MutateRowResponse>> 73 AsyncMutateRow(grpc::ClientContext* context, 74 google::bigtable::v2::MutateRowRequest const& request, 75 grpc::CompletionQueue* cq) override; 76 77 std::unique_ptr<::grpc::ClientAsyncReaderInterface< 78 ::google::bigtable::v2::SampleRowKeysResponse>> 79 AsyncSampleRowKeys( 80 ::grpc::ClientContext* context, 81 const ::google::bigtable::v2::SampleRowKeysRequest& request, 82 ::grpc::CompletionQueue* cq, void* tag) override; 83 84 std::unique_ptr<::grpc::ClientAsyncReaderInterface< 85 ::google::bigtable::v2::MutateRowsResponse>> 86 AsyncMutateRows(::grpc::ClientContext* context, 87 const ::google::bigtable::v2::MutateRowsRequest& request, 88 ::grpc::CompletionQueue* cq, void* tag) override; 89 90 std::unique_ptr<grpc::ClientAsyncResponseReaderInterface< 91 google::bigtable::v2::CheckAndMutateRowResponse>> 92 AsyncCheckAndMutateRow( 93 grpc::ClientContext* context, 94 const google::bigtable::v2::CheckAndMutateRowRequest& request, 95 grpc::CompletionQueue* cq) override; 96 97 std::unique_ptr< 98 grpc::ClientAsyncReaderInterface<google::bigtable::v2::ReadRowsResponse>> 99 AsyncReadRows(grpc::ClientContext* context, 100 const google::bigtable::v2::ReadRowsRequest& request, 101 grpc::CompletionQueue* cq, void* tag) override; 102 103 std::shared_ptr<grpc::Channel> Channel() override; 104 105 private: 106 friend class SampleRowKeysResponse; 107 friend class ReadRowsResponse; 108 friend class MutateRowsResponse; 109 110 struct Row { 111 string row_key; 112 std::map<string, string> columns; 113 }; 114 struct Table { 115 std::map<string, Row> rows; 116 }; 117 118 mutex mu_; 119 const std::string project_id_ = "testproject"; 120 const std::string instance_id_ = "testinstance"; 121 Table table_ GUARDED_BY(mu_); 122 }; 123 124 } // namespace tensorflow 125 126 #endif // TENSORFLOW_CONTRIB_BIGTABLE_KERNELS_TEST_KERNELS_BIGTABLE_TEST_CLIENT_H_ 127