Skip to content

Commit

Permalink
Fix queries/endpoint proto. Add QueryService test
Browse files Browse the repository at this point in the history
  • Loading branch information
motxx committed Jul 20, 2017
1 parent de2b054 commit c0c6389
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 35 deletions.
23 changes: 2 additions & 21 deletions schema/endpoint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package iroha.protocol;

import "block.proto";
import "queries.proto";

enum ResponseCode {
FAIL = 0; // default value
Expand All @@ -14,30 +15,10 @@ message ToriiResponse {
string message = 2;
}

message VerifyResponse {
ResponseCode code = 1;
string message = 2;
}

message QueryResponse {}

message QueueTransactionResponse {
ResponseCode code = 1;
string message = 2;
}

service CommandService {
rpc Torii (Transaction) returns (ToriiResponse);
}

service QueryService {
// rpc Find (QueryRequest) returns (QueryResponse);
}

service SumeragiService {
rpc Verify (Block) returns (VerifyResponse);
}

service OrderingService {
rpc QueueTransaction (Transaction) returns (QueueTransactionResponse);
rpc Find (Query) returns (QueryResponse);
}
4 changes: 4 additions & 0 deletions schema/queries.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ message Query {
GetAccountAssets get_account_assets = 4;
}
}

message QueryResponse {

}
29 changes: 15 additions & 14 deletions test/module/irohad/torii/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Torii Test
add_executable(torii_async_test
torii_async_test.cpp
)
target_link_libraries(torii_async_test
command_service
command_client
server_runner
gtest
)
add_test(
NAME torii_async_test
COMMAND $<TARGET_FILE:torii_async_test>
)
add_subdirectory(processor)

# command service test
addtest(torii_async_test torii_async_test.cpp)
target_link_libraries(torii_async_test
command_service
command_client
server_runner
gtest
)

# query service test
addtest(query_service_test query_service_test.cpp)
target_link_libraries(query_service_test
query_service
server_runner
)
75 changes: 75 additions & 0 deletions test/module/irohad/torii/query_service_test.cpp
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));
}

0 comments on commit c0c6389

Please sign in to comment.