-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Executor Fixture: parametric backend
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
- Loading branch information
Showing
5 changed files
with
212 additions
and
0 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
117 changes: 117 additions & 0 deletions
117
test/integration/executor/executor_fixture_param_postgres.cpp
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,117 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "integration/executor/executor_fixture_param_postgres.hpp" | ||
|
||
#include <soci/soci.h> | ||
#include "ametsuchi/impl/postgres_command_executor.hpp" | ||
#include "ametsuchi/impl/postgres_query_executor.hpp" | ||
#include "ametsuchi/impl/postgres_specific_query_executor.hpp" | ||
#include "backend/protobuf/proto_permission_to_string.hpp" | ||
#include "backend/protobuf/proto_query_response_factory.hpp" | ||
#include "common/result.hpp" | ||
#include "framework/result_gtest_checkers.hpp" | ||
#include "framework/test_db_manager.hpp" | ||
#include "framework/test_logger.hpp" | ||
#include "logger/logger_manager.hpp" | ||
#include "main/impl/pg_connection_init.hpp" | ||
#include "module/irohad/ametsuchi/mock_block_storage.hpp" | ||
#include "module/irohad/pending_txs_storage/pending_txs_storage_mock.hpp" | ||
#include "module/shared_model/interface_mocks.hpp" | ||
|
||
using namespace executor_testing; | ||
using namespace iroha; | ||
using namespace iroha::ametsuchi; | ||
using namespace iroha::expected; | ||
using namespace iroha::integration_framework; | ||
|
||
namespace { | ||
constexpr size_t kDataBaseSessionPoolSize = 3; // sessions for: | ||
// - command executor | ||
// - query executor | ||
// - resetWsv | ||
|
||
ExecutorItfTarget createPostgresExecutorItfTarget(TestDbManager &db_manager); | ||
} // namespace | ||
|
||
PostgresExecutorTestParam::PostgresExecutorTestParam() { | ||
auto db_manager_result = TestDbManager::createWithRandomDbName( | ||
kDataBaseSessionPoolSize, | ||
getTestLoggerManager()->getChild("TestDbManager")); | ||
if (auto e = resultToOptionalError(db_manager_result)) { | ||
throw std::runtime_error(e.value()); | ||
} | ||
db_manager_ = resultToOptionalValue(std::move(db_manager_result)).value(); | ||
|
||
executor_itf_target_ = createPostgresExecutorItfTarget(*db_manager_); | ||
} | ||
|
||
PostgresExecutorTestParam::~PostgresExecutorTestParam() = default; | ||
|
||
void PostgresExecutorTestParam::clearBackendState() { | ||
auto session = db_manager_->getSession(); | ||
framework::expected::assertResultValue(PgConnectionInit::resetWsv(*session)); | ||
} | ||
|
||
ExecutorItfTarget PostgresExecutorTestParam::getExecutorItfParam() const { | ||
return executor_itf_target_; | ||
} | ||
|
||
std::string PostgresExecutorTestParam::toString() const { | ||
return "PostgreSQL"; | ||
} | ||
|
||
namespace { | ||
struct SessionHolder { | ||
SessionHolder(std::unique_ptr<soci::session> session) | ||
: session(std::move(session)) {} | ||
std::unique_ptr<soci::session> session; | ||
}; | ||
|
||
class PostgresSpecificQueryExecutorWrapper | ||
: private SessionHolder, | ||
public PostgresSpecificQueryExecutor { | ||
public: | ||
PostgresSpecificQueryExecutorWrapper( | ||
std::unique_ptr<soci::session> &&session, | ||
std::unique_ptr<BlockStorage> block_storage, | ||
std::shared_ptr<PendingTransactionStorage> pending_txs_storage, | ||
std::shared_ptr<shared_model::interface::QueryResponseFactory> | ||
response_factory, | ||
std::shared_ptr<shared_model::interface::PermissionToString> | ||
perm_converter, | ||
logger::LoggerPtr log) | ||
: SessionHolder(std::move(session)), | ||
PostgresSpecificQueryExecutor(*SessionHolder::session, | ||
*block_storage, | ||
std::move(pending_txs_storage), | ||
std::move(response_factory), | ||
std::move(perm_converter), | ||
std::move(log)), | ||
block_storage_(std::move(block_storage)) {} | ||
|
||
private: | ||
std::unique_ptr<BlockStorage> block_storage_; | ||
}; | ||
|
||
ExecutorItfTarget createPostgresExecutorItfTarget(TestDbManager &db_manager) { | ||
ExecutorItfTarget target; | ||
target.command_executor = std::make_shared<PostgresCommandExecutor>( | ||
db_manager.getSession(), | ||
std::make_shared<shared_model::proto::ProtoPermissionToString>()); | ||
target.query_executor = | ||
std::make_unique<PostgresSpecificQueryExecutorWrapper>( | ||
db_manager.getSession(), | ||
std::make_unique<MockBlockStorage>(), | ||
std::make_shared<MockPendingTransactionStorage>(), | ||
std::make_shared<shared_model::proto::ProtoQueryResponseFactory>(), | ||
std::make_shared<shared_model::proto::ProtoPermissionToString>(), | ||
getTestLoggerManager() | ||
->getChild("SpecificQueryExecutor") | ||
->getLogger()); | ||
return target; | ||
} | ||
|
||
} // namespace |
45 changes: 45 additions & 0 deletions
45
test/integration/executor/executor_fixture_param_postgres.hpp
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,45 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_POSTGRES_HPP | ||
#define TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_POSTGRES_HPP | ||
|
||
#include "integration/executor/executor_fixture_param.hpp" | ||
|
||
namespace iroha { | ||
namespace integration_framework { | ||
class TestDbManager; | ||
} | ||
} // namespace iroha | ||
|
||
namespace executor_testing { | ||
|
||
/** | ||
* PostgreSQL backend parameter for ExecutorTest. | ||
* Creates and holds a test database manager object that: | ||
* - gets PostgreSQL connection options | ||
* - creates a new working database with a random name | ||
* - drops the working database when the test suite is complete | ||
*/ | ||
class PostgresExecutorTestParam : public ExecutorTestParam { | ||
public: | ||
PostgresExecutorTestParam(); | ||
|
||
virtual ~PostgresExecutorTestParam(); | ||
|
||
void clearBackendState() override; | ||
|
||
iroha::integration_framework::ExecutorItfTarget getExecutorItfParam() | ||
const override; | ||
|
||
std::string toString() const override; | ||
|
||
private: | ||
std::unique_ptr<iroha::integration_framework::TestDbManager> db_manager_; | ||
iroha::integration_framework::ExecutorItfTarget executor_itf_target_; | ||
}; | ||
} // namespace executor_testing | ||
|
||
#endif /* TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_POSTGRES_HPP */ |
19 changes: 19 additions & 0 deletions
19
test/integration/executor/executor_fixture_param_provider.cpp
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,19 @@ | ||
#include "integration/executor/executor_fixture_param_provider.hpp" | ||
|
||
#include "integration/executor/executor_fixture_param.hpp" | ||
#include "integration/executor/executor_fixture_param_postgres.hpp" | ||
|
||
namespace executor_testing { | ||
|
||
std::vector<std::shared_ptr<ExecutorTestParam>> | ||
getExecutorTestParamsVector() { | ||
return std::vector<std::shared_ptr<ExecutorTestParam>>{ | ||
{std::make_shared<PostgresExecutorTestParam>()}}; | ||
} | ||
|
||
auto getExecutorTestParams() | ||
-> decltype(::testing::ValuesIn(getExecutorTestParamsVector())) { | ||
static auto params = ::testing::ValuesIn(getExecutorTestParamsVector()); | ||
return params; | ||
} | ||
} // namespace executor_testing |
16 changes: 16 additions & 0 deletions
16
test/integration/executor/executor_fixture_param_provider.hpp
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,16 @@ | ||
#ifndef TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_PROVIDER_HPP | ||
#define TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_PROVIDER_HPP | ||
|
||
#include <gtest/gtest-param-test.h> | ||
|
||
namespace executor_testing { | ||
struct ExecutorTestParam; | ||
|
||
std::vector<std::shared_ptr<ExecutorTestParam>> getExecutorTestParamsVector(); | ||
|
||
auto getExecutorTestParams() | ||
-> decltype(::testing::ValuesIn(getExecutorTestParamsVector())); | ||
|
||
} // namespace executor_testing | ||
|
||
#endif /* TEST_INTEGRATION_EXECUTOR_FIXTURE_PARAM_PROVIDER_HPP */ |