LCOV - code coverage report
Current view: top level - irohad/torii/impl - query_client.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 23 27 85.2 %
Date: 2019-03-07 14:46:43 Functions: 8 11 72.7 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "torii/query_client.hpp"
       7             : 
       8             : #include "network/impl/grpc_channel_builder.hpp"
       9             : 
      10             : namespace torii_utils {
      11             : 
      12             :   using iroha::protocol::Query;
      13             :   using iroha::protocol::QueryResponse;
      14             : 
      15             :   QuerySyncClient::QuerySyncClient(const std::string &ip, size_t port)
      16         264 :       : ip_(ip),
      17         264 :         port_(port),
      18         264 :         stub_(iroha::network::createClient<iroha::protocol::QueryService_v1>(
      19         264 :             ip + ":" + std::to_string(port))) {}
      20             : 
      21             :   QuerySyncClient::QuerySyncClient(const QuerySyncClient &rhs)
      22           2 :       : QuerySyncClient(rhs.ip_, rhs.port_) {}
      23             : 
      24             :   QuerySyncClient &QuerySyncClient::operator=(QuerySyncClient rhs) {
      25           0 :     swap(*this, rhs);
      26           0 :     return *this;
      27             :   }
      28             : 
      29             :   QuerySyncClient::QuerySyncClient(QuerySyncClient &&rhs) noexcept {
      30           2 :     swap(*this, rhs);
      31           2 :   }
      32             : 
      33             :   QuerySyncClient &QuerySyncClient::operator=(QuerySyncClient &&rhs) noexcept {
      34           0 :     swap(*this, rhs);
      35           0 :     return *this;
      36             :   }
      37             : 
      38             :   /**
      39             :    * requests query to a torii server and returns response (blocking, sync)
      40             :    * @param query
      41             :    * @param response
      42             :    * @return grpc::Status
      43             :    */
      44             :   grpc::Status QuerySyncClient::Find(const iroha::protocol::Query &query,
      45             :                                      QueryResponse &response) const {
      46         164 :     grpc::ClientContext context;
      47         164 :     return stub_->Find(&context, query, &response);
      48         164 :   }
      49             : 
      50             :   std::vector<iroha::protocol::BlockQueryResponse>
      51             :   QuerySyncClient::FetchCommits(
      52             :       const iroha::protocol::BlocksQuery &blocks_query) const {
      53           2 :     grpc::ClientContext context;
      54           2 :     auto reader = stub_->FetchCommits(&context, blocks_query);
      55           2 :     std::vector<iroha::protocol::BlockQueryResponse> responses;
      56           2 :     iroha::protocol::BlockQueryResponse resp;
      57           4 :     while (reader->Read(&resp)) {
      58           2 :       responses.push_back(resp);
      59             :     }
      60           2 :     reader->Finish();
      61           2 :     return responses;
      62           2 :   }
      63             : 
      64             :   void QuerySyncClient::swap(QuerySyncClient &lhs, QuerySyncClient &rhs) {
      65             :     using std::swap;
      66           2 :     swap(lhs.ip_, rhs.ip_);
      67           2 :     swap(lhs.port_, rhs.port_);
      68           2 :     swap(lhs.stub_, rhs.stub_);
      69           2 :   }
      70             : 
      71             : }  // namespace torii_utils

Generated by: LCOV version 1.13