Skip to content

Commit

Permalink
Refactoring:
Browse files Browse the repository at this point in the history
- Remove unnecessary links to ametsuchi in CMakeLists
- Simplify genesis_proc_test
- Move AmetsuchiTest fixture to separate header with interface library
  • Loading branch information
lebdron committed Aug 22, 2017
1 parent 4933699 commit ce1938e
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 163 deletions.
3 changes: 0 additions & 3 deletions iroha-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ target_link_libraries(bootstrap_network
genesis_block_client
rapidjson
model
ametsuchi
ip_tools
)

Expand Down Expand Up @@ -42,7 +41,6 @@ target_link_libraries(client
rapidjson
command_client
query_client
ametsuchi
model_generators
)

Expand All @@ -60,7 +58,6 @@ target_link_libraries(iroha-cli
cli-flags_validators
bootstrap_network
rapidjson
ametsuchi
model
keys_manager
)
2 changes: 0 additions & 2 deletions irohad/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_library(genesis_block_server
impl/raw_block_insertion.cpp
)
target_link_libraries(genesis_block_server
ametsuchi
model
timer
endpoint
Expand Down Expand Up @@ -64,7 +63,6 @@ add_executable(irohad irohad.cpp)
target_link_libraries(irohad
application
genesis_block_server
ametsuchi
gflags
rapidjson
config
Expand Down
3 changes: 1 addition & 2 deletions irohad/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ add_library(networking
impl/peer_communication_service_impl.cpp
)

target_link_libraries(networking PUBLIC
target_link_libraries(networking
rxcpp
model
ametsuchi
ordering_service
synchronizer
logger
Expand Down
1 change: 0 additions & 1 deletion irohad/simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ target_link_libraries(simulator
model
rxcpp
optional
ametsuchi
logger
)
2 changes: 1 addition & 1 deletion irohad/synchronizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_library(synchronizer
impl/synchronizer_impl.cpp
)

target_link_libraries(synchronizer PUBLIC
target_link_libraries(synchronizer
model
rxcpp
logger
Expand Down
2 changes: 2 additions & 0 deletions libs/common/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef IROHA_FILES_HPP
#define IROHA_FILES_HPP

#include <string>

/**
* This source file contains common methods related to files
*/
Expand Down
1 change: 0 additions & 1 deletion test/module/iroha-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ addtest(bootstrap_network_test bootstrap_network_test.cpp)
target_link_libraries(bootstrap_network_test
bootstrap_network
crypto
ametsuchi
)
target_include_directories(bootstrap_network_test PUBLIC
${PROJECT_SOURCE_DIR}/iroha-cli
Expand Down
6 changes: 6 additions & 0 deletions test/module/irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ target_link_libraries(testing_storage_test
test_block_generator
libs_common
)

add_library(ametsuchi_fixture INTERFACE)
target_link_libraries(ametsuchi_fixture INTERFACE
pqxx
cpp_redis
)
94 changes: 94 additions & 0 deletions test/module/irohad/ametsuchi/ametsuchi_fixture.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
* http://soramitsu.co.jp
*
* 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.
*/

#ifndef IROHA_AMETSUCHI_FIXTURE_HPP
#define IROHA_AMETSUCHI_FIXTURE_HPP

#include "common/files.hpp"
#include "logger/logger.hpp"

#include <gtest/gtest.h>
#include <cpp_redis/cpp_redis>
#include <pqxx/pqxx>

namespace iroha {
namespace ametsuchi {
/**
* Class with ametsuchi initialization
*/
class AmetsuchiTest : public ::testing::Test {
protected:
virtual void SetUp() {
auto log = logger::testLog("AmetsuchiTest");

mkdir(block_store_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
auto pg_host = std::getenv("IROHA_POSTGRES_HOST");
auto pg_port = std::getenv("IROHA_POSTGRES_PORT");
auto pg_user = std::getenv("IROHA_POSTGRES_USER");
auto pg_pass = std::getenv("IROHA_POSTGRES_PASSWORD");
auto rd_host = std::getenv("IROHA_REDIS_HOST");
auto rd_port = std::getenv("IROHA_REDIS_PORT");
if (not pg_host) {
return;
}
std::stringstream ss;
ss << "host=" << pg_host << " port=" << pg_port << " user=" << pg_user
<< " password=" << pg_pass;
pgopt_ = ss.str();
redishost_ = rd_host;
redisport_ = std::stoull(rd_port);
log->info("host={}, port={}, user={}, password={}", pg_host, pg_port,
pg_user, pg_pass);
}
virtual void TearDown() {
const auto drop =
"DROP TABLE IF EXISTS account_has_asset;\n"
"DROP TABLE IF EXISTS account_has_signatory;\n"
"DROP TABLE IF EXISTS peer;\n"
"DROP TABLE IF EXISTS account;\n"
"DROP TABLE IF EXISTS exchange;\n"
"DROP TABLE IF EXISTS asset;\n"
"DROP TABLE IF EXISTS domain;\n"
"DROP TABLE IF EXISTS signatory;";

pqxx::connection connection(pgopt_);
pqxx::work txn(connection);
txn.exec(drop);
txn.commit();
connection.disconnect();

cpp_redis::redis_client client;
client.connect(redishost_, redisport_);
client.flushall();
client.sync_commit();
client.disconnect();

iroha::remove_all(block_store_path);
}

std::string pgopt_ =
"host=localhost port=5432 user=postgres password=mysecretpassword";

std::string redishost_ = "localhost";
size_t redisport_ = 6379;

std::string block_store_path = "/tmp/block_store";
};
} // namespace ametsuchi
} // namespace iroha

#endif // IROHA_AMETSUCHI_FIXTURE_HPP
66 changes: 0 additions & 66 deletions test/module/irohad/ametsuchi/ametsuchi_mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@
#define IROHA_AMETSUCHI_MOCKS_HPP

#include <gmock/gmock.h>
#include <cpp_redis/cpp_redis>
#include <pqxx/pqxx>
#include "ametsuchi/block_query.hpp"
#include "ametsuchi/mutable_factory.hpp"
#include "ametsuchi/mutable_storage.hpp"
#include "ametsuchi/temporary_factory.hpp"
#include "ametsuchi/temporary_wsv.hpp"
#include "ametsuchi/wsv_query.hpp"
#include "ametsuchi/peer_query.hpp"
#include "logger/logger.hpp"
#include "common/files.hpp"

namespace iroha {
namespace ametsuchi {
Expand Down Expand Up @@ -135,68 +131,6 @@ namespace iroha {
nonstd::optional<std::vector<model::Peer>>());
};

/**
* Class with ametsuchi initialization
*/
class AmetsuchiTest : public ::testing::Test {
protected:
virtual void SetUp() {
auto log = logger::testLog("AmetsuchiTest");

mkdir(block_store_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
auto pg_host = std::getenv("IROHA_POSTGRES_HOST");
auto pg_port = std::getenv("IROHA_POSTGRES_PORT");
auto pg_user = std::getenv("IROHA_POSTGRES_USER");
auto pg_pass = std::getenv("IROHA_POSTGRES_PASSWORD");
auto rd_host = std::getenv("IROHA_REDIS_HOST");
auto rd_port = std::getenv("IROHA_REDIS_PORT");
if (not pg_host) {
return;
}
std::stringstream ss;
ss << "host=" << pg_host << " port=" << pg_port << " user=" << pg_user
<< " password=" << pg_pass;
pgopt_ = ss.str();
redishost_ = rd_host;
redisport_ = std::stoull(rd_port);
log->info("host={}, port={}, user={}, password={}",
pg_host, pg_port, pg_user, pg_pass);
}
virtual void TearDown() {
const auto drop =
"DROP TABLE IF EXISTS account_has_asset;\n"
"DROP TABLE IF EXISTS account_has_signatory;\n"
"DROP TABLE IF EXISTS peer;\n"
"DROP TABLE IF EXISTS account;\n"
"DROP TABLE IF EXISTS exchange;\n"
"DROP TABLE IF EXISTS asset;\n"
"DROP TABLE IF EXISTS domain;\n"
"DROP TABLE IF EXISTS signatory;";

pqxx::connection connection(pgopt_);
pqxx::work txn(connection);
txn.exec(drop);
txn.commit();
connection.disconnect();

cpp_redis::redis_client client;
client.connect(redishost_, redisport_);
client.flushall();
client.sync_commit();
client.disconnect();

iroha::remove_all(block_store_path);
}

std::string pgopt_ =
"host=localhost port=5432 user=postgres password=mysecretpassword";

std::string redishost_ = "localhost";
size_t redisport_ = 6379;

std::string block_store_path = "/tmp/block_store";
};

} // namespace ametsuchi
} // namespace iroha

Expand Down
4 changes: 2 additions & 2 deletions test/module/irohad/ametsuchi/ametsuchi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "model/commands/create_domain.hpp"
#include "model/commands/transfer_asset.hpp"
#include "model/model_hash_provider_impl.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"

using namespace iroha::ametsuchi;
using namespace iroha::model;
Expand Down Expand Up @@ -57,7 +57,7 @@ TEST_F(AmetsuchiTest, SampleTest) {
auto storage =
StorageImpl::create(block_store_path, redishost_, redisport_, pgopt_);
ASSERT_TRUE(storage);

Transaction txn;
txn.creator_account_id = "admin1";
CreateDomain createDomain;
Expand Down
2 changes: 1 addition & 1 deletion test/module/irohad/ametsuchi/testing_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gtest/gtest.h"
#include "logger/logger.hpp"
#include "ametsuchi/impl/test_storage_impl.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/ametsuchi/ametsuchi_fixture.hpp"
#include "framework/test_block_generator.hpp"

#include "model/commands/add_asset_quantity.hpp"
Expand Down
1 change: 0 additions & 1 deletion test/module/irohad/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ AddTest(blob_converter_test blob_converter_test.cpp)

AddTest(block_insertion_test block_insertion_test.cpp)
target_link_libraries(block_insertion_test
ametsuchi
model
genesis_block_server
test_block_generator
Expand Down
1 change: 0 additions & 1 deletion test/module/irohad/consensus/yac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ target_link_libraries(yac_network_test
addtest(yac_peer_orderer_test peer_orderer_test.cpp)
target_link_libraries(yac_peer_orderer_test
yac
ametsuchi
)

addtest(yac_gate_test yac_gate_test.cpp)
Expand Down
13 changes: 7 additions & 6 deletions test/module/irohad/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

addtest(genesis_block_processor_test
genesis_block_server/genesis_proc_test.cpp)
addtest(genesis_block_processor_test genesis_block_server/genesis_proc_test.cpp)
target_link_libraries(genesis_block_processor_test
genesis_block_server
crypto
libs_common
)
genesis_block_server
crypto
libs_common
ametsuchi
ametsuchi_fixture
)
Loading

0 comments on commit ce1938e

Please sign in to comment.