1 /*
2  * Copyright (C) 2019 Codership Oy <info@codership.com>
3  *
4  * This file is part of wsrep-lib.
5  *
6  * Wsrep-lib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Wsrep-lib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "wsrep/client_state.hpp"
21 
22 #include "client_state_fixture.hpp"
23 
24 #include <boost/test/unit_test.hpp>
25 
BOOST_FIXTURE_TEST_CASE(test_toi_mode,replicating_client_fixture_sync_rm)26 BOOST_FIXTURE_TEST_CASE(test_toi_mode,
27                         replicating_client_fixture_sync_rm)
28 {
29     BOOST_REQUIRE(cc.mode() == wsrep::client_state::m_local);
30     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_undefined);
31     wsrep::key key(wsrep::key::exclusive);
32     key.append_key_part("k1", 2);
33     key.append_key_part("k2", 2);
34     wsrep::key_array keys{key};
35     wsrep::const_buffer buf("toi", 3);
36     BOOST_REQUIRE(cc.enter_toi_local(keys, buf) == 0);
37     BOOST_REQUIRE(cc.mode() == wsrep::client_state::m_toi);
38     BOOST_REQUIRE(cc.in_toi());
39     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_local);
40     wsrep::mutable_buffer err;
41     BOOST_REQUIRE(cc.leave_toi_local(err) == 0);
42     BOOST_REQUIRE(cc.mode() == wsrep::client_state::m_local);
43     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_undefined);
44     BOOST_REQUIRE(sc.provider().toi_write_sets() == 1);
45     BOOST_REQUIRE(sc.provider().toi_start_transaction() == 1);
46     BOOST_REQUIRE(sc.provider().toi_commit() == 1);
47 }
48 
BOOST_FIXTURE_TEST_CASE(test_toi_applying,applying_client_fixture)49 BOOST_FIXTURE_TEST_CASE(test_toi_applying,
50                         applying_client_fixture)
51 {
52     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_undefined);
53     wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("1"), wsrep::seqno(2)),
54                            wsrep::stid(sc.id(),
55                                        wsrep::transaction_id::undefined(),
56                                        cc.id()),
57                            wsrep::seqno(1),
58                            wsrep::provider::flag::start_transaction |
59                            wsrep::provider::flag::commit);
60     cc.enter_toi_mode(ws_meta);
61     BOOST_REQUIRE(cc.in_toi());
62     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_high_priority);
63     cc.leave_toi_mode();
64     BOOST_REQUIRE(cc.toi_mode() == wsrep::client_state::m_undefined);
65     cc.after_applying();
66 }
67