Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
x3medima17 committed Oct 11, 2017
1 parent 47c0fc4 commit 7ce0995
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 60 deletions.
14 changes: 7 additions & 7 deletions irohad/network/ordering_gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef IROHA_ORDERING_SERVICE_HPP
#define IROHA_ORDERING_SERVICE_HPP

#include <model/transaction.hpp>
#include <model/proposal.hpp>
#include "model/proposal.hpp"
#include "model/transaction.hpp"
#include <rxcpp/rx-observable.hpp>

namespace iroha {
Expand All @@ -30,12 +30,12 @@ namespace iroha {
*/
class OrderingGate {
public:

/**
* Propagate a signed transaction for further processing
* @param transaction
*/
virtual void propagate_transaction(std::shared_ptr<const model::Transaction> transaction) = 0;
virtual void propagate_transaction(
std::shared_ptr<const model::Transaction> transaction) = 0;

/**
* Return observable of all proposals in the consensus
Expand All @@ -45,7 +45,7 @@ namespace iroha {

virtual ~OrderingGate() = default;
};
}//namespace network
}// namespace iroha
} // namespace network
} // namespace iroha

#endif //IROHA_ORDERING_SERVICE_HPP
#endif // IROHA_ORDERING_SERVICE_HPP
6 changes: 3 additions & 3 deletions irohad/network/ordering_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ namespace iroha {
*/
virtual void publishProposal(model::Proposal &&proposal) = 0;
};
}
}
#endif //IROHA_ORDERINGSERVICE_H
} // namespace network
} // namespace iroha
#endif // IROHA_ORDERINGSERVICE_H
4 changes: 2 additions & 2 deletions irohad/network/ordering_service_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace iroha {
* Publishes proposal over network
* @param proposal : proposal to be published
*/
virtual void publishProposal(model::Proposal&& proposal,
const std::vector<std::string>& peers) = 0;
virtual void publishProposal(model::Proposal &&proposal,
const std::vector<std::string> &peers) = 0;

virtual ~OrderingServiceTransport() = default;
};
Expand Down
18 changes: 9 additions & 9 deletions irohad/network/peer_communication_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#ifndef IROHA_PEER_COMMUNICATION_SERVICE_HPP
#define IROHA_PEER_COMMUNICATION_SERVICE_HPP

#include <model/block.hpp>
#include <model/proposal.hpp>
#include "model/block.hpp"
#include "model/proposal.hpp"

#include <rxcpp/rx.hpp>

namespace iroha {
Expand All @@ -32,7 +33,6 @@ namespace iroha {
*/
class PeerCommunicationService {
public:

/**
* Propagate transaction in network
* @param transaction - object for propagation
Expand All @@ -48,12 +48,12 @@ namespace iroha {
virtual rxcpp::observable<model::Proposal> on_proposal() = 0;

/**
* Event is triggered when commit block arrives.
* @return observable with sequence of committed blocks.
* In common case observable<Block> will contain one element.
* But there are scenarios when consensus provide many blocks, e.g.
* on peer startup - peer will get all actual blocks.
*/
* Event is triggered when commit block arrives.
* @return observable with sequence of committed blocks.
* In common case observable<Block> will contain one element.
* But there are scenarios when consensus provide many blocks, e.g.
* on peer startup - peer will get all actual blocks.
*/
virtual rxcpp::observable<Commit> on_commit() = 0;

virtual ~PeerCommunicationService() = default;
Expand Down
6 changes: 3 additions & 3 deletions irohad/ordering/impl/ordering_gate_transport_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
using namespace iroha::ordering;

grpc::Status OrderingGateTransportGrpc::onProposal(
::grpc::ServerContext *context, const proto::Proposal *request,
::grpc::ServerContext *context,
const proto::Proposal *request,
::google::protobuf::Empty *response) {
log_->info("receive proposal");

Expand All @@ -31,7 +32,7 @@ grpc::Status OrderingGateTransportGrpc::onProposal(

model::Proposal proposal(transactions);
proposal.height = request->height();
if(not subscriber_.expired())
if (not subscriber_.expired())
subscriber_.lock()->onProposal(std::move(proposal));
else
log_->error("(onProposal) No subscriber");
Expand All @@ -50,7 +51,6 @@ void OrderingGateTransportGrpc::propagate_transaction(
log_->info("Propagate tx (on transport)");
auto call = new AsyncClientCall;


call->response_reader = client_->AsynconTransaction(
&call->context, factory_.serialize(*transaction), &cq_);

Expand Down
1 change: 0 additions & 1 deletion irohad/ordering/impl/ordering_gate_transport_grpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define IROHA_ORDERING_GATE_TRANSPORT_GRPC_H

#include <google/protobuf/empty.pb.h>
#include "ordering.grpc.pb.h"
#include "logger/logger.hpp"
#include "model/converters/pb_transaction_factory.hpp"
#include "network/impl/async_grpc_client.hpp"
Expand Down
25 changes: 12 additions & 13 deletions irohad/ordering/impl/ordering_service_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include <memory>
#include <unordered_map>

#include "network/impl/async_grpc_client.hpp"
#include "network/ordering_service.hpp"
#include "network/ordering_service_transport.hpp"
#include "network/impl/async_grpc_client.hpp"

#include "ametsuchi/peer_query.hpp"
#include "ordering.grpc.pb.h"
Expand All @@ -49,7 +49,8 @@ namespace iroha {
class OrderingServiceImpl : public network::OrderingService {
public:
OrderingServiceImpl(
std::shared_ptr<ametsuchi::PeerQuery> wsv, size_t max_size,
std::shared_ptr<ametsuchi::PeerQuery> wsv,
size_t max_size,
size_t delay_milliseconds,
std::shared_ptr<network::OrderingServiceTransport> transport);

Expand All @@ -58,24 +59,23 @@ namespace iroha {
* Enqueues transaction and publishes corresponding event
* @param transaction
*/
void onTransaction(const model::Transaction& transaction) override;
void onTransaction(const model::Transaction &transaction) override;

~OrderingServiceImpl() override;

protected:
/**
* Transform model proposal to transport object and send to peers
* @param proposal - object for propagation
*/
void publishProposal(model::Proposal &&proposal) override;
protected:
/**
* Transform model proposal to transport object and send to peers
* @param proposal - object for propagation
*/
void publishProposal(model::Proposal &&proposal) override;

private:
private:
/**
* Collect transactions from queue
* Passes the generated proposal to publishProposal
*/
void generateProposal() override ;

void generateProposal() override;

/**
* Method update peers for sending proposal
Expand Down Expand Up @@ -103,7 +103,6 @@ namespace iroha {
const size_t delay_milliseconds_;
std::shared_ptr<network::OrderingServiceTransport> transport_;
size_t proposal_height;

};
} // namespace ordering
} // namespace iroha
Expand Down
5 changes: 3 additions & 2 deletions irohad/ordering/impl/ordering_service_transport_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ grpc::Status OrderingServiceTransportGrpc::onTransaction(
::grpc::ServerContext *context,
const protocol::Transaction *request,
::google::protobuf::Empty *response) {
if (subscriber_.expired())
if (subscriber_.expired()) {
log_->error("No subscriber");
else
} else {
subscriber_.lock()->onTransaction(*factory_.deserialize(*request));
}

return ::grpc::Status::OK;
}
Expand Down
2 changes: 1 addition & 1 deletion irohad/ordering/impl/ordering_service_transport_grpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace iroha {
const protocol::Transaction *request,
::google::protobuf::Empty *response) override;

~OrderingServiceTransportGrpc() = default;

~OrderingServiceTransportGrpc() = default;
private:
std::weak_ptr<iroha::network::OrderingServiceNotification> subscriber_;
model::converters::PbTransactionFactory factory_;
Expand Down
26 changes: 8 additions & 18 deletions test/module/irohad/ordering/ordering_gate_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "framework/test_subscriber.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"

#include "ordering/impl/ordering_service_transport_grpc.hpp"
#include "ordering/impl/ordering_gate_impl.hpp"
#include "ordering/impl/ordering_gate_transport_grpc.hpp"
#include "ordering/impl/ordering_service_impl.hpp"
#include "ordering/impl/ordering_service_transport_grpc.hpp"

using namespace iroha::ordering;
using namespace iroha::model;
Expand All @@ -43,23 +43,21 @@ class OrderingGateServiceTest : public ::testing::Test {
counter = 2;
}

void SetUp() override { }
void SetUp() override {}

void start() {
void start() {
std::mutex mtx;
std::condition_variable cv;
thread = std::thread([&cv, this] {
grpc::ServerBuilder builder;
int port = 0;
builder.AddListeningPort(address, grpc::InsecureServerCredentials(),
&port);
builder.AddListeningPort(
address, grpc::InsecureServerCredentials(), &port);

builder.RegisterService(gate_transport.get());

builder.RegisterService(service_transport.get());



server = builder.BuildAndStart();
ASSERT_NE(port, 0);
ASSERT_TRUE(server);
Expand All @@ -69,10 +67,9 @@ class OrderingGateServiceTest : public ::testing::Test {

std::unique_lock<std::mutex> lock(mtx);
cv.wait_for(lock, std::chrono::seconds(1));

}

void TearDown() override {
void TearDown() override {
proposals.clear();
server->Shutdown();
if (thread.joinable()) {
Expand All @@ -81,8 +78,7 @@ class OrderingGateServiceTest : public ::testing::Test {
}

TestSubscriber<iroha::model::Proposal> init(size_t times) {
auto wrapper =
make_test_subscriber<CallExact>(gate->on_proposal(), times);
auto wrapper = make_test_subscriber<CallExact>(gate->on_proposal(), times);
wrapper.subscribe([this](auto proposal) { proposals.push_back(proposal); });
gate->on_proposal().subscribe([this](auto) {
counter--;
Expand All @@ -99,7 +95,7 @@ class OrderingGateServiceTest : public ::testing::Test {
std::this_thread::sleep_for(20ms);
}

std::string address {"0.0.0.0:50051"};
std::string address{"0.0.0.0:50051"};
std::shared_ptr<OrderingGateImpl> gate;
std::shared_ptr<OrderingServiceImpl> service;

Expand All @@ -113,11 +109,8 @@ class OrderingGateServiceTest : public ::testing::Test {
Peer peer;
std::shared_ptr<OrderingGateTransportGrpc> gate_transport;
std::shared_ptr<OrderingServiceTransportGrpc> service_transport;

};



TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) {
// 8 transaction -> proposal -> 2 transaction -> proposal

Expand All @@ -127,12 +120,10 @@ TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) {
const size_t max_proposal = 100;
const size_t commit_delay = 400;


service = std::make_shared<OrderingServiceImpl>(
wsv, max_proposal, commit_delay, service_transport);
service_transport->subscribe(service);


start();
std::unique_lock<std::mutex> lk(m);
auto wrapper = init(2);
Expand All @@ -146,7 +137,6 @@ TEST_F(OrderingGateServiceTest, SplittingBunchTransactions) {
send_transaction(9);
cv.wait_for(lk, 10s);


std::this_thread::sleep_for(1s);
ASSERT_EQ(proposals.size(), 2);
ASSERT_EQ(proposals.at(0).transactions.size(), 8);
Expand Down
1 change: 0 additions & 1 deletion test/module/irohad/ordering/ordering_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <grpc++/grpc++.h>
#include <grpc++/impl/codegen/server_context.h>

#include "logger/logger.hpp"
#include "network/ordering_service.hpp"
Expand Down

0 comments on commit 7ce0995

Please sign in to comment.