mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-27 09:01:50 +03:00
Added unit tests for server_context applying codepath.
This commit is contained in:
84
src/server_context_test.cpp
Normal file
84
src/server_context_test.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
#include "mock_server_context.hpp"
|
||||
#include "mock_utils.hpp"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
// Test on_apply() method for 1pc
|
||||
BOOST_AUTO_TEST_CASE(server_context_applying_1pc)
|
||||
{
|
||||
trrep::mock_server_context sc("s1", "s1",
|
||||
trrep::server_context::rm_sync);
|
||||
trrep::mock_client_context cc(sc,
|
||||
trrep::client_id(1),
|
||||
trrep::client_context::m_applier,
|
||||
false);
|
||||
trrep::transaction_context tc(
|
||||
trrep_mock::applying_transaction(
|
||||
cc, 1, 1,
|
||||
WSREP_FLAG_TRX_START | WSREP_FLAG_TRX_END));
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, tc, trrep::data(buf, 1)) == 0);
|
||||
BOOST_REQUIRE(tc.state() == trrep::transaction_context::s_committed);
|
||||
}
|
||||
|
||||
// Test on_apply() method for 2pc
|
||||
BOOST_AUTO_TEST_CASE(server_context_applying_2pc)
|
||||
{
|
||||
trrep::mock_server_context sc("s1", "s1",
|
||||
trrep::server_context::rm_sync);
|
||||
trrep::mock_client_context cc(sc,
|
||||
trrep::client_id(1),
|
||||
trrep::client_context::m_applier,
|
||||
true);
|
||||
trrep::transaction_context tc(
|
||||
trrep_mock::applying_transaction(
|
||||
cc, 1, 1,
|
||||
WSREP_FLAG_TRX_START | WSREP_FLAG_TRX_END));
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, tc, trrep::data(buf, 1)) == 0);
|
||||
BOOST_REQUIRE(tc.state() == trrep::transaction_context::s_committed);
|
||||
}
|
||||
|
||||
// Test on_apply() method for 1pc transaction which
|
||||
// fails applying and rolls back
|
||||
BOOST_AUTO_TEST_CASE(server_context_applying_1pc_rollback)
|
||||
{
|
||||
trrep::mock_server_context sc("s1", "s1",
|
||||
trrep::server_context::rm_sync);
|
||||
trrep::mock_client_context cc(sc,
|
||||
trrep::client_id(1),
|
||||
trrep::client_context::m_applier,
|
||||
false);
|
||||
cc.fail_next_applying(true);
|
||||
trrep::transaction_context tc(
|
||||
trrep_mock::applying_transaction(
|
||||
cc, 1, 1,
|
||||
WSREP_FLAG_TRX_START | WSREP_FLAG_TRX_END));
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, tc, trrep::data(buf, 1)) == 1);
|
||||
BOOST_REQUIRE(tc.state() == trrep::transaction_context::s_aborted);
|
||||
}
|
||||
|
||||
// Test on_apply() method for 2pc transaction which
|
||||
// fails applying and rolls back
|
||||
BOOST_AUTO_TEST_CASE(server_context_applying_2pc_rollback)
|
||||
{
|
||||
trrep::mock_server_context sc("s1", "s1",
|
||||
trrep::server_context::rm_sync);
|
||||
trrep::mock_client_context cc(sc,
|
||||
trrep::client_id(1),
|
||||
trrep::client_context::m_applier,
|
||||
true);
|
||||
cc.fail_next_applying(true);
|
||||
trrep::transaction_context tc(
|
||||
trrep_mock::applying_transaction(
|
||||
cc, 1, 1,
|
||||
WSREP_FLAG_TRX_START | WSREP_FLAG_TRX_END));
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, tc, trrep::data(buf, 1)) == 1);
|
||||
BOOST_REQUIRE(tc.state() == trrep::transaction_context::s_aborted);
|
||||
}
|
Reference in New Issue
Block a user