Skip to content

Commit

Permalink
Implementation of query processor, client removed from transaction an…
Browse files Browse the repository at this point in the history
…d query responses
  • Loading branch information
kamilsa committed Jul 24, 2017
1 parent 7394ebf commit 39f1a71
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 100 deletions.
2 changes: 1 addition & 1 deletion irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <main/context.hpp>
#include <network/network_api.h>
#include <consensus/consensus_service_stub.hpp>
#include <torii/processor/query_processor_stub.hpp>
#include <torii/processor/query_processor_impl.hpp>
#include <torii/processor/transaction_processor_impl.hpp>
#include <validation/chain/validator_stub.hpp>
#include <validation/impl/stateless_validator_impl.hpp>
Expand Down
38 changes: 38 additions & 0 deletions irohad/model/query_responses/stateless_response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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_STATELESS_RESPONSE_HPP
#define IROHA_STATELESS_RESPONSE_HPP

namespace iroha {
namespace model {

/**
* Query response that contains
*/
struct QueryStatelessResponse : QueryResponse {

/**
* Is stateless validation passed
*/
bool passed;
};
} // namespace model
} // namespace iroha


#endif //IROHA_STATELESS_RESPONSE_HPP
5 changes: 0 additions & 5 deletions irohad/model/transaction_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ namespace iroha {
*/
Transaction transaction;

/**
* Transaction emitter
*/
Client client;

virtual ~TransactionResponse() = default;
};
} //namespace model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace iroha {
/**
* Transaction response that contains
*/
struct StatelessResponse : TransactionResponse {
struct TransactionStatelessResponse : TransactionResponse {

/**
* Is stateless validation passed
Expand Down
3 changes: 2 additions & 1 deletion irohad/torii/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
add_library(processors
impl/transaction_processor_impl.cpp
impl/query_processor_stub.cpp
impl/query_processor_impl.cpp
)

target_link_libraries(processors PUBLIC
model
rxcpp
stateless_validator
)
48 changes: 48 additions & 0 deletions irohad/torii/processor/impl/query_processor_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.
*/

#include "torii/processor/query_processor_impl.hpp"
#include "model/query_responses/stateless_response.hpp"

namespace iroha {
namespace torii {

QueryProcessorImpl::QueryProcessorImpl(
model::QueryProcessingFactory &qpf,
validation::StatelessValidator &stateless_validator)
: qpf_(qpf), validator_(stateless_validator) {}

void QueryProcessorImpl::query_handle(const model::Query &query) {
model::QueryStatelessResponse response;
response.query = query;
response.passed = false;

if (validator_.validate(query)) {
response.passed = true;
qpf_.execute(query);
}

subject_.get_subscriber().on_next(
std::make_shared<model::QueryStatelessResponse>(response));
}

rxcpp::observable<std::shared_ptr<model::QueryResponse>>
QueryProcessorImpl::query_notifier() {
return subject_.get_observable();
}
}
}
55 changes: 0 additions & 55 deletions irohad/torii/processor/impl/query_processor_stub.cpp

This file was deleted.

8 changes: 3 additions & 5 deletions irohad/torii/processor/impl/transaction_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ namespace iroha {
validator_(validator) {
}

void TransactionProcessorImpl::transaction_handle(model::Client client,
model::Transaction &transaction) {
model::StatelessResponse response;
response.client = client;
void TransactionProcessorImpl::transaction_handle(model::Transaction &transaction) {
model::TransactionStatelessResponse response;
response.transaction = transaction;
response.passed = false;

Expand All @@ -49,7 +47,7 @@ namespace iroha {
}

notifier_.get_subscriber().on_next(
std::make_shared<model::StatelessResponse>(response));
std::make_shared<model::TransactionStatelessResponse>(response));
}

rxcpp::observable<std::shared_ptr<model::TransactionResponse>>
Expand Down
3 changes: 1 addition & 2 deletions irohad/torii/processor/query_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ namespace iroha {
* @param client - query emitter
* @param query - client intent
*/
virtual void query_handle(model::Client client,
const model::Query &query) = 0;
virtual void query_handle(const model::Query &query) = 0;

/**
* Subscribe for query responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,44 @@
* limitations under the License.
*/

#ifndef IROHA_STUB_QUERY_PROCESSOR_HPP
#define IROHA_STUB_QUERY_PROCESSOR_HPP
#ifndef IROHA_QUERY_PROCESSOR_IMPL_HPP
#define IROHA_QUERY_PROCESSOR_IMPL_HPP

#include <torii/processor/query_processor.hpp>
#include <handler_map/handler_map.hpp>
#include <ametsuchi/block_query.hpp>
#include <ametsuchi/wsv_query.hpp>
#include "model/query_execution.hpp"
#include "validation/stateless_validator.hpp"
#include "torii/processor/query_processor.hpp"

namespace iroha {
namespace torii {

/**
* QueryProcessor provides start point for queries in the whole system
*/
class QueryProcessorStub : public QueryProcessor {
class QueryProcessorImpl : public QueryProcessor {
public:

explicit QueryProcessorStub(ametsuchi::WsvQuery &wsv,
ametsuchi::BlockQuery &block);
explicit QueryProcessorImpl(
model::QueryProcessingFactory &qpf,
validation::StatelessValidator &stateless_validator);

/**
* Register client query
* @param client - query emitter
* @param query - client intent
*/
void query_handle(model::Client client, const model::Query &query) override;
void query_handle(const model::Query &query) override;

/**
* Subscribe for query responses
* @return observable with query responses
*/
rxcpp::observable<std::shared_ptr<model::QueryResponse>> query_notifier() override;
rxcpp::observable<std::shared_ptr<model::QueryResponse>> query_notifier()
override;

private:
HandlerMap<model::Query, void> handler_;
rxcpp::subjects::subject<std::shared_ptr<model::QueryResponse>> subject_;
ametsuchi::WsvQuery &wsv_;
ametsuchi::BlockQuery &block_;


model::QueryProcessingFactory &qpf_;
validation::StatelessValidator &validator_;
};
} //namespace torii
} //namespace iroha
#endif //IROHA_STUB_QUERY_PROCESSOR_HPP
}
}

#endif // IROHA_QUERY_PROCESSOR_IMPL_HPP
4 changes: 1 addition & 3 deletions irohad/torii/processor/transaction_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ namespace iroha {

/**
* Add transaction to the system for processing
* @param client - transaction owner
* @param transaction - transaction for processing
*/
virtual void transaction_handle(model::Client client,
model::Transaction &transaction) = 0;
virtual void transaction_handle(model::Transaction &transaction) = 0;

/**
* Subscribers will be notified with transaction status
Expand Down
3 changes: 1 addition & 2 deletions irohad/torii/processor/transaction_processor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ namespace iroha {
ordering::OrderingService &os,
const validation::StatelessValidator &validator);

void transaction_handle(model::Client client,
model::Transaction &transaction) override;
void transaction_handle(model::Transaction &transaction) override;

rxcpp::observable<std::shared_ptr<model::TransactionResponse>>
transaction_notifier() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ TEST(TransactionProcessorTest,
model::Transaction tx;
// TODO subscribe with testable subscriber
tp.transaction_notifier().subscribe([](auto response) {
auto resp = static_cast<model::StatelessResponse &>(*response);
auto resp = static_cast<model::TransactionStatelessResponse &>(*response);
ASSERT_EQ(resp.passed, true);
});
tp.transaction_handle(model::Client(), tx);
tp.transaction_handle(tx);
}

/**
Expand All @@ -96,8 +96,8 @@ TEST(TransactionProcessorTest,
model::Transaction tx;
// TODO subscribe with testable subscriber
tp.transaction_notifier().subscribe([](auto response) {
auto resp = static_cast<model::StatelessResponse &>(*response);
auto resp = static_cast<model::TransactionStatelessResponse &>(*response);
ASSERT_EQ(resp.passed, false);
});
tp.transaction_handle(model::Client(), tx);
tp.transaction_handle(tx);
}

0 comments on commit 39f1a71

Please sign in to comment.