diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ff06517..6122b1f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,7 +3,7 @@ # add_executable(wsrep-lib_test - fake_client_context.cpp + mock_client_context.cpp test_utils.cpp id_test.cpp server_context_test.cpp diff --git a/test/client_context_fixture.hpp b/test/client_context_fixture.hpp index d78b70a..e9a2336 100644 --- a/test/client_context_fixture.hpp +++ b/test/client_context_fixture.hpp @@ -5,8 +5,8 @@ #ifndef WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP #define WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP -#include "fake_server_context.hpp" -#include "fake_client_context.hpp" +#include "mock_server_context.hpp" +#include "mock_client_context.hpp" #include @@ -27,8 +27,8 @@ namespace BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -46,8 +46,8 @@ namespace BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -65,8 +65,8 @@ namespace BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -84,8 +84,8 @@ namespace BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -112,8 +112,8 @@ namespace BOOST_REQUIRE(tc.certified() == true); BOOST_REQUIRE(tc.ordered() == true); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -140,8 +140,8 @@ namespace BOOST_REQUIRE(tc.certified() == true); BOOST_REQUIRE(tc.ordered() == true); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -160,8 +160,8 @@ namespace BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); cc.enable_streaming(wsrep::streaming_context::row, 1); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -180,8 +180,8 @@ namespace BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); cc.enable_streaming(wsrep::streaming_context::bytes, 1); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; @@ -201,8 +201,8 @@ namespace cc.enable_streaming(wsrep::streaming_context::row, 1); } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; const wsrep::transaction_context& tc; }; } diff --git a/test/fake_client_context.cpp b/test/mock_client_context.cpp similarity index 85% rename from test/fake_client_context.cpp rename to test/mock_client_context.cpp index 797a004..dfa2116 100644 --- a/test/fake_client_context.cpp +++ b/test/mock_client_context.cpp @@ -3,10 +3,10 @@ // #include "wsrep/transaction_context.hpp" -#include "fake_client_context.hpp" +#include "mock_client_context.hpp" -int wsrep::fake_client_context::apply( +int wsrep::mock_client_context::apply( const wsrep::const_buffer& data __attribute__((unused))) { @@ -15,7 +15,7 @@ int wsrep::fake_client_context::apply( return (fail_next_applying_ ? 1 : 0); } -int wsrep::fake_client_context::commit() +int wsrep::mock_client_context::commit() { int ret(0); if (do_2pc()) @@ -39,7 +39,7 @@ int wsrep::fake_client_context::commit() return ret; } -int wsrep::fake_client_context::rollback() +int wsrep::mock_client_context::rollback() { int ret(0); if (transaction_.before_rollback()) diff --git a/test/fake_client_context.hpp b/test/mock_client_context.hpp similarity index 92% rename from test/fake_client_context.hpp rename to test/mock_client_context.hpp index dfffaf4..4ea534a 100644 --- a/test/fake_client_context.hpp +++ b/test/mock_client_context.hpp @@ -13,10 +13,10 @@ namespace wsrep { - class fake_client_context : public wsrep::client_context + class mock_client_context : public wsrep::client_context { public: - fake_client_context(wsrep::server_context& server_context, + mock_client_context(wsrep::server_context& server_context, const wsrep::client_id& id, enum wsrep::client_context::mode mode, bool is_autocommit = false, @@ -37,7 +37,7 @@ namespace wsrep , replays_() , aborts_() { } - ~fake_client_context() + ~mock_client_context() { if (transaction().active()) { @@ -57,14 +57,9 @@ namespace wsrep void will_replay(wsrep::transaction_context&) WSREP_OVERRIDE { } int replay(wsrep::transaction_context& tc) WSREP_OVERRIDE { - wsrep::client_applier_mode am(*this); - if (server_context().on_apply( - *this, tc.ws_handle(), tc.ws_meta(), wsrep::const_buffer())) - { - return 1; - } + int ret(provider().replay(tc.ws_handle(), this)); ++replays_; - return 0; + return ret; } void wait_for_replayers(wsrep::unique_lock& lock) WSREP_OVERRIDE diff --git a/test/fake_provider.hpp b/test/mock_provider.hpp similarity index 91% rename from test/fake_provider.hpp rename to test/mock_provider.hpp index 39d09a6..991a591 100644 --- a/test/fake_provider.hpp +++ b/test/mock_provider.hpp @@ -15,12 +15,12 @@ namespace wsrep { - class fake_provider : public wsrep::provider + class mock_provider : public wsrep::provider { public: typedef std::map bf_abort_map; - fake_provider(wsrep::server_context& server_context) + mock_provider(wsrep::server_context& server_context) : provider(server_context) , certify_result_() , commit_order_enter_result_() @@ -138,7 +138,15 @@ namespace wsrep int release(wsrep::ws_handle&) { return release_result_; } - int replay(wsrep::ws_handle&, void*) { ::abort(); /* not impl */} + int replay(wsrep::ws_handle&, void* ctx) + { + wsrep::mock_client_context& cc( + *static_cast(ctx)); + wsrep::client_applier_mode applier_mode(cc); + const wsrep::transaction_context& tc(cc.transaction()); + return server_context_.on_apply(cc, tc.ws_handle(), tc.ws_meta(), + wsrep::const_buffer()); + } int sst_sent(const wsrep::gtid&, int) { return 0; } int sst_received(const wsrep::gtid&, int) { return 0; } @@ -148,7 +156,7 @@ namespace wsrep return std::vector(); } - // Methods to modify fake state + // Methods to modify mock state /*! Inject BF abort event into the provider. * * \param bf_seqno Aborter sequence number diff --git a/test/fake_server_context.hpp b/test/mock_server_context.hpp similarity index 85% rename from test/fake_server_context.hpp rename to test/mock_server_context.hpp index bfcdb09..3cd5073 100644 --- a/test/fake_server_context.hpp +++ b/test/mock_server_context.hpp @@ -6,17 +6,17 @@ #define WSREP_FAKE_SERVER_CONTEXT_HPP #include "wsrep/server_context.hpp" -#include "fake_client_context.hpp" -#include "fake_provider.hpp" +#include "mock_client_context.hpp" +#include "mock_provider.hpp" #include "wsrep/compiler.hpp" namespace wsrep { - class fake_server_context : public wsrep::server_context + class mock_server_context : public wsrep::server_context { public: - fake_server_context(const std::string& name, + mock_server_context(const std::string& name, const std::string& id, enum wsrep::server_context::rollback_mode rollback_mode) : wsrep::server_context(mutex_, cond_, @@ -26,16 +26,16 @@ namespace wsrep , provider_(*this) , last_client_id_(0) { } - wsrep::fake_provider& provider() const + wsrep::mock_provider& provider() const { return provider_; } wsrep::client_context* local_client_context() { - return new wsrep::fake_client_context(*this, ++last_client_id_, + return new wsrep::mock_client_context(*this, ++last_client_id_, wsrep::client_context::m_local); } wsrep::client_context* streaming_applier_client_context() { - return new wsrep::fake_client_context( + return new wsrep::mock_client_context( *this, ++last_client_id_, wsrep::client_context::m_applier); } void log_dummy_write_set(wsrep::client_context&, const wsrep::ws_meta&) @@ -65,7 +65,7 @@ namespace wsrep private: wsrep::default_mutex mutex_; wsrep::default_condition_variable cond_; - mutable wsrep::fake_provider provider_; + mutable wsrep::mock_provider provider_; unsigned long long last_client_id_; }; } diff --git a/test/server_context_test.cpp b/test/server_context_test.cpp index ed9f4a5..399e078 100644 --- a/test/server_context_test.cpp +++ b/test/server_context_test.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2018 Codership Oy // -#include "fake_server_context.hpp" +#include "mock_server_context.hpp" #include @@ -25,8 +25,8 @@ namespace wsrep::provider::flag::commit) { } - wsrep::fake_server_context sc; - wsrep::fake_client_context cc; + wsrep::mock_server_context sc; + wsrep::mock_client_context cc; wsrep::ws_handle ws_handle; wsrep::ws_meta ws_meta; }; @@ -85,9 +85,9 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback, BOOST_AUTO_TEST_CASE(server_context_streaming) { - wsrep::fake_server_context sc("s1", "s1", + wsrep::mock_server_context sc("s1", "s1", wsrep::server_context::rm_sync); - wsrep::fake_client_context cc(sc, + wsrep::mock_client_context cc(sc, wsrep::client_id(1), wsrep::client_context::m_applier, false); diff --git a/test/test_utils.cpp b/test/test_utils.cpp index ae9b0bb..9abb0f7 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -4,7 +4,7 @@ #include "test_utils.hpp" #include "wsrep/client_context.hpp" -#include "fake_server_context.hpp" +#include "mock_server_context.hpp" // Simple BF abort method to BF abort unordered transasctions @@ -22,7 +22,7 @@ void wsrep_test::bf_abort_ordered(wsrep::client_context& cc) cc.bf_abort(lock, wsrep::seqno(0)); } // BF abort method to abort transactions via provider -void wsrep_test::bf_abort_provider(wsrep::fake_server_context& sc, +void wsrep_test::bf_abort_provider(wsrep::mock_server_context& sc, const wsrep::transaction_context& tc, wsrep::seqno bf_seqno) { diff --git a/test/test_utils.hpp b/test/test_utils.hpp index c288fa2..4466990 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -6,7 +6,7 @@ namespace wsrep { class client_context; - class fake_server_context; + class mock_server_context; } #include "wsrep/transaction_context.hpp" @@ -25,7 +25,7 @@ namespace wsrep_test void bf_abort_ordered(wsrep::client_context& cc); // BF abort method to abort transactions via provider - void bf_abort_provider(wsrep::fake_server_context& sc, + void bf_abort_provider(wsrep::mock_server_context& sc, const wsrep::transaction_context& tc, wsrep::seqno bf_seqno); diff --git a/test/transaction_context_test.cpp b/test/transaction_context_test.cpp index 5794564..bfcc3c1 100644 --- a/test/transaction_context_test.cpp +++ b/test/transaction_context_test.cpp @@ -158,7 +158,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_bf_during_before_commit_uncertified, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -198,7 +198,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_bf_during_commit_wait_for_replayers, T, replicating_fixtures, T) { - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -236,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_error_during_prepare_data, T, replicating_fixtures, T) { - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -275,7 +275,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_killed_before_certify, T, replicating_fixtures, T) { - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -317,8 +317,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_bf_during_before_commit_certified, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_server_context& sc(T::sc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -360,8 +360,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_bf_before_unordered_cert_failure, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_server_context& sc(T::sc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); cc.start_transaction(1); @@ -369,7 +369,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( BOOST_REQUIRE(tc.id() == wsrep::transaction_id(1)); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); cc.sync_point_enabled_ = "wsrep_before_certification"; - cc.sync_point_action_ = wsrep::fake_client_context::spa_bf_abort_unordered; + cc.sync_point_action_ = wsrep::mock_client_context::spa_bf_abort_unordered; sc.provider().certify_result_ = wsrep::provider::error_certification_failed; BOOST_REQUIRE(cc.before_commit()); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_cert_failed); @@ -393,7 +393,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_warning_error_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -434,7 +434,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_transaction_missing_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -475,7 +475,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_size_exceeded_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -516,7 +516,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_connection_failed_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -557,7 +557,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_no_allowed_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); + wsrep::mock_server_context& sc(T::sc); wsrep::client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); @@ -598,8 +598,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_fatal_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_server_context& sc(T::sc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -640,8 +640,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_unknown_from_certify, T, replicating_fixtures, T) { - wsrep::fake_server_context& sc(T::sc); - wsrep::fake_client_context& cc(T::cc); + wsrep::mock_server_context& sc(T::sc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -682,8 +682,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( transaction_context_1pc_bf_abort_before_certify_regain_lock, T, replicating_fixtures, T) { - // wsrep::fake_server_context& sc(T::sc); - wsrep::fake_client_context& cc(T::cc); + // wsrep::mock_server_context& sc(T::sc); + wsrep::mock_client_context& cc(T::cc); const wsrep::transaction_context& tc(T::tc); // Start a new transaction with ID 1 @@ -693,7 +693,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE( BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_executing); cc.sync_point_enabled_ = "wsrep_after_certification"; - cc.sync_point_action_ = wsrep::fake_client_context::spa_bf_abort_ordered; + cc.sync_point_action_ = wsrep::mock_client_context::spa_bf_abort_ordered; // Run before commit BOOST_REQUIRE(cc.before_commit()); BOOST_REQUIRE(tc.state() == wsrep::transaction_context::s_must_replay);