forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix queries/endpoint proto. Add QueryService test
- Loading branch information
Showing
4 changed files
with
96 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,7 @@ message Query { | |
GetAccountAssets get_account_assets = 4; | ||
} | ||
} | ||
|
||
message QueryResponse { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright Soramitsu Co., Ltd. 2016 All Rights Reserved. | ||
Licensed 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 <gtest/gtest.h> | ||
#include <main/server_runner.hpp> | ||
#include <torii/command_service_handler.hpp> | ||
#include <torii/command_service.hpp> | ||
#include <torii/command_client.hpp> | ||
#include <endpoint.pb.h> | ||
#include <endpoint.grpc.pb.h> | ||
#include <thread> | ||
#include <memory> | ||
#include <chrono> | ||
#include <atomic> | ||
|
||
constexpr const char* Ip = "0.0.0.0"; | ||
constexpr int Port = 50051; | ||
|
||
class QueryServiceTest : public testing::Test { | ||
public: | ||
virtual void SetUp() { | ||
runner = new ServerRunner(Ip, Port); | ||
th = std::thread([runner = runner]{ | ||
runner->run(); | ||
}); | ||
|
||
runner->waitForServersReady(); | ||
} | ||
|
||
virtual void TearDown() { | ||
runner->shutdown(); | ||
delete runner; | ||
th.join(); | ||
} | ||
|
||
ServerRunner* runner; | ||
std::thread th; | ||
}; | ||
|
||
class QueryClient { | ||
public: | ||
QueryClient(const std::string& ip, int port) { | ||
auto channel = grpc::CreateChannel(ip + ":" + std::to_string(port), grpc::InsecureChannelCredentials()); | ||
stub_ = iroha::protocol::QueryService::NewStub(channel); | ||
} | ||
|
||
bool Find(iroha::protocol::Query const& request) { | ||
iroha::protocol::QueryResponse response; | ||
auto status = stub_->Find(&context_, request, &response); | ||
return status.ok(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<iroha::protocol::QueryService::Stub> stub_; | ||
grpc::ClientContext context_; | ||
}; | ||
|
||
TEST_F(QueryServiceTest, FindWhereQueryServiceSync) { | ||
QueryClient client(Ip, Port); | ||
iroha::protocol::Query request; | ||
ASSERT_TRUE(client.Find(request)); | ||
} |