Skip to content

Commit

Permalink
Update peer service test. We need a way to run N peers simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
Warchant authored and lebdron committed Jul 19, 2017
1 parent 65a165c commit 4cd7a2f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 38 deletions.
32 changes: 16 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ jobs:
steps:
- checkout

- run:
- run_grpc:
name: ensure, required folders created
command: |
mkdir -p $IROHA_HOME
mkdir -p $IROHA_BUILD
- run:
- run_grpc:
name: cmake
command: cmake -H$IROHA_HOME -B$IROHA_BUILD
- run:
- run_grpc:
name: make
command: cmake --build $IROHA_BUILD -- -j4
- run:
name: run tests
- run_grpc:
name: run_grpc tests
command: cmake --build $IROHA_BUILD --target test

# - run:
# - run_grpc:
# name: analyze source code with cppcheck and sonarqube
# command: |
# export TEST_FOLDER=$IROHA_BUILD/test_bin
#
# cd $IROHA_HOME
# cppcheck --enable=all --inconclusive --xml --xml-version=2 core/ peer/ smart_contract/ test/ tools/ 2>/tmp/cppcheck.xml || true
#
# # run valgrind for tests
# # run_grpc valgrind for tests
# VALGRIND_XML=
# mkdir -p valgrind_report
# for test in $(ls $TEST_FOLDER); do
Expand Down Expand Up @@ -68,22 +68,22 @@ jobs:
# - setup_docker_engine
#
# ## At this step we have compiled and tested iroha.
# - run:
# - run_grpc:
# name: setup docker
# command: |
# set -ex
# curl -L -o /tmp/docker.tgz https://get.docker.com/builds/Linux/x86_64/docker-17.03.0-ce.tgz
# tar -xz -C /tmp -f /tmp/docker.tgz
# mv /tmp/docker/* /usr/bin
#
# - run:
# - run_grpc:
# name: setup docker-compose
# command: |
# set -ex
# curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
#
# - run:
# - run_grpc:
# name: build and push hyperledger/iroha-docker:$CIRCLE_BRANCH image
# command: |
# # replace all invalid characters to dots
Expand Down Expand Up @@ -134,26 +134,26 @@ jobs:
#
# ## you can use it by tag:
# ## hyperledger/iroha-docker:$TAG
# ## don't forget, that call docker run hyperledger/iroha-docker:$TAG is blocking.
# ## to make in unblocking, run with -d
# ## don't forget, that call docker run_grpc hyperledger/iroha-docker:$TAG is blocking.
# ## to make in unblocking, run_grpc with -d
# ##
# ## put your tests here as separate run command, here is the template:
# #- run:
# ## put your tests here as separate run_grpc command, here is the template:
# #- run_grpc:
# # name: test name
# # command: |
# # test body (bash)
# # test body (bash)
# # don't forget to clean up after tests (if needed)
#
# - run:
# - run_grpc:
# name: template test using docker compose
# command: |
# docker-compose up -d
# docker-compose scale iroha=4
# IP=$(docker inspect --format "{{ .NetworkSettings.Networks.iroha_private.IPAddress }}" $(docker ps -lq))
# TAG=$(echo $CIRCLE_BRANCH | sed "s/[^a-zA-Z0-9_\-\.]/./g")
#
# #docker run --rm -it hyperledger/iroha-docker:$TAG sh -c "/iroha/bin/add_peer key $(IP) ledger"
# #docker run_grpc --rm -it hyperledger/iroha-docker:$TAG sh -c "/iroha/bin/add_peer key $(IP) ledger"
#
# docker stop $(docker ps -qln 4)
# docker rm $(docker ps -qln 4)
Expand Down
12 changes: 6 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ ${IROHA_HOME}/docker/build_in_docker.sh

Docker image with tag `hyperledger/iroha-docker:latest` will be built.

# How to run
# How to run_grpc

```
docker run -d --name=iroha -p 50051:50051 hyperledger/iroha-docker:latest
docker run_grpc -d --name=iroha -p 50051:50051 hyperledger/iroha-docker:latest
```


Expand All @@ -47,15 +47,15 @@ Start different containers:
* postgre - container for WSW
* redis - container for indexes

For run use:
For run_grpc use:
```sh
sh run-ametsuchi-dev.sh
sh run_grpc-ametsuchi-dev.sh
```

## Consnesus
Currently starts only one container - node, but in future it should deploy also container with ordering service.

For run use:
For run_grpc use:
```sh
sh run-consensus-dev.sh
sh run_grpc-consensus-dev.sh
```
2 changes: 1 addition & 1 deletion docker/dev/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to build:

Navigate to this folder and run:
Navigate to this folder and run_grpc:
```
docker build -t warchantua/iroha-dev .
```
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-ametsuchi-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'

# How to run:
# How to run_grpc:
# docker-compose -f docker-compose-dev.yml up
#
# This file creates persistent redis and postgres containers.
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'

# How to run:
# How to run_grpc:
# docker-compose -f docker-compose-dev.yml up
#
# This file creates persistent redis and postgres containers.
Expand Down
24 changes: 23 additions & 1 deletion irohad/network/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@
* limitations under the License.
*/

#include "network.hpp"
#include "server.hpp"
#include <grpc++/grpc++.h>

namespace network {
Server::Server(std::shared_ptr<uvw::Loop> loop)
: loop_{loop} {

}

void Server::run_grpc(uvw::Addr addr, bool blocking) {
// bind grpc service
auto listen_on = addr.ip + ":" + std::to_string(addr.port);
builder.AddListeningPort(listen_on,
grpc::InsecureServerCredentials());
builder.RegisterService(&this->consensus_);

auto server = builder.BuildAndStart();

if(blocking) {
server->Wait();
}
}
}
35 changes: 26 additions & 9 deletions irohad/network/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@
#ifndef IROHA_NETWORK_HPP
#define IROHA_NETWORK_HPP



class network {

};



#endif //IROHA_NETWORK_HPP
#include <grpc++/server_builder.h>
#include <consensus/consensus_service.hpp>
#include <consensus/messages.hpp>
#include <uvw.hpp>

namespace network {

/**
* This is an entity, which is listens host:port and emits received messages
* It emits all types of messages defined in consensus/messages.hpp
* GRPC server builder is also here.
*/
class Server : public uvw::Emitter<Server> {
public:
Server(std::shared_ptr<uvw::Loop> loop = uvw::Loop::getDefault());

void run_grpc(uvw::Addr addr, bool blocking = true);

private:
std::shared_ptr<uvw::Loop> loop_;

grpc::ServerBuilder builder;
consensus::ConsensusService consensus_;
};
}
#endif // IROHA_NETWORK_HPP
6 changes: 3 additions & 3 deletions test/module/irohad/peerservice/peerservice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class Service : public testing::Test {
[]() { return create_keypair(create_seed()); });

std::vector<peerservice::Node> cluster;
for (int i = 0; i < NPEERS; i++) {
for (int i = 0; i < NPEERS; ++i) {
peerservice::Node node;
node.ip = "127.0.0.1";
node.port = (uint16_t)(65530 + i);
node.pubkey = kps[i].pubkey;
cluster.push_back(node);
}

for (int i = 0; i < NPEERS; i++) {
for (int i = 0; i < NPEERS; ++i) {
auto &&builder = std::make_unique<grpc::ServerBuilder>();
auto on = cluster[i].ip + ":" + std::to_string(cluster[i].port);

Expand Down Expand Up @@ -115,4 +115,4 @@ TEST_F(Service, AyoungerThanB) {
ASSERT_EQ(A->getLatestState().height(), HEIGHT)
<< "A(2) -> B(3) and A did not update its latest state";
}
*/
*/

0 comments on commit 4cd7a2f

Please sign in to comment.