1
0
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:
Teemu Ollakka
2018-04-18 15:03:12 +03:00
parent e8f4b2d183
commit cd21425e07
11 changed files with 253 additions and 62 deletions

View 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);
}