Skip to content

Commit 9070f2a

Browse files
committed
Change unit tests to mimic application behavior on replaying
Allocate separate client state in mock_client_service::replay() for replaying step. Added two new test cases for streaming replication replay after BF abort.
1 parent e238c0d commit 9070f2a

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

test/mock_client_state.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,42 @@ int wsrep::mock_client_service::bf_rollback()
3535
return ret;
3636
}
3737

38+
struct replayer_context
39+
{
40+
wsrep::mock_client_state state;
41+
wsrep::mock_client_service service;
42+
replayer_context(wsrep::server_state& server_state,
43+
const wsrep::transaction& transaction,
44+
const wsrep::client_id& id)
45+
: state{server_state, service, id, wsrep::client_state::m_high_priority}
46+
, service{&state}
47+
{
48+
state.open(id);
49+
state.before_command();
50+
state.clone_transaction_for_replay(transaction);
51+
}
52+
53+
~replayer_context() {
54+
state.after_applying();
55+
state.after_command_before_result();
56+
state.after_command_after_result();
57+
state.close();
58+
}
59+
};
60+
3861
enum wsrep::provider::status
3962
wsrep::mock_client_service::replay()
4063
{
41-
wsrep::mock_high_priority_service hps(client_state_->server_state(),
42-
client_state_, true);
64+
/* Mimic application and allocate separate client state for replaying. */
65+
wsrep::client_id replayer_id{ 1001 };
66+
replayer_context replayer(client_state_->server_state(),
67+
client_state_->transaction(), replayer_id);
68+
wsrep::mock_high_priority_service hps{ client_state_->server_state(),
69+
&replayer.state, true };
70+
4371
enum wsrep::provider::status ret(
4472
client_state_->provider().replay(
45-
client_state_->transaction().ws_handle(),
73+
replayer.state.transaction().ws_handle(),
4674
&hps));
4775
++replays_;
4876
return ret;

test/mock_provider.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ namespace wsrep
201201
wsrep::mock_client_state& cc(
202202
static_cast<wsrep::mock_client_state&>(
203203
high_priority_service.client_state()));
204-
wsrep::high_priority_context high_priority_context(cc);
205204
const wsrep::transaction& tc(cc.transaction());
206205
wsrep::ws_meta ws_meta;
207206
if (replay_result_ == wsrep::provider::success)

test/transaction_test.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,55 @@ BOOST_FIXTURE_TEST_CASE(
15391539
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
15401540
}
15411541

1542+
//
1543+
// Test a streaming transaction which gets BF aborted inside provider before
1544+
// certification result is known. Replaying will be successful
1545+
//
1546+
BOOST_FIXTURE_TEST_CASE(
1547+
transaction_row_streaming_bf_before_cert_result_replay_success,
1548+
streaming_client_fixture_row)
1549+
{
1550+
BOOST_REQUIRE(cc.start_transaction(wsrep::transaction_id(1)) == 0);
1551+
BOOST_REQUIRE(cc.after_row() == 0);
1552+
BOOST_REQUIRE(tc.streaming_context().fragments_certified() == 1);
1553+
1554+
sc.provider().certify_result_ = wsrep::provider::error_bf_abort;
1555+
sc.provider().replay_result_ = wsrep::provider::success;
1556+
1557+
BOOST_REQUIRE(cc.before_commit());
1558+
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
1559+
BOOST_REQUIRE(cc.will_replay_called() == true);
1560+
BOOST_REQUIRE(cc.after_statement() == 0);
1561+
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_committed);
1562+
BOOST_REQUIRE(cc.current_error() == wsrep::e_success);
1563+
}
1564+
1565+
//
1566+
// Test a streaming transaction which gets BF aborted inside provider before
1567+
// certification result is known. Replaying will fail because of
1568+
// certification failure.
1569+
//
1570+
BOOST_FIXTURE_TEST_CASE(
1571+
transaction_row_streaming_bf_before_cert_result_replay_cert_fail,
1572+
streaming_client_fixture_row)
1573+
{
1574+
BOOST_REQUIRE(cc.start_transaction(wsrep::transaction_id(1)) == 0);
1575+
BOOST_REQUIRE(cc.after_row() == 0);
1576+
BOOST_REQUIRE(tc.streaming_context().fragments_certified() == 1);
1577+
1578+
sc.provider().certify_result_ = wsrep::provider::error_bf_abort;
1579+
sc.provider().replay_result_ = wsrep::provider::error_certification_failed;
1580+
1581+
BOOST_REQUIRE(cc.before_commit());
1582+
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
1583+
BOOST_REQUIRE(cc.will_replay_called() == true);
1584+
BOOST_REQUIRE(cc.after_statement() );
1585+
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted);
1586+
BOOST_REQUIRE(cc.current_error() == wsrep::e_deadlock_error);
1587+
BOOST_REQUIRE(tc.active() == false);
1588+
}
1589+
1590+
15421591
BOOST_FIXTURE_TEST_CASE(transaction_byte_streaming_1pc_commit,
15431592
streaming_client_fixture_byte)
15441593
{

0 commit comments

Comments
 (0)