1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-10-18 00:31:19 +03:00
Files
wsrep-lib/test/client_state_fixture.hpp
Teemu Ollakka bf7dad6815 Added open(), close(), cleanup() methods to client_state.
Depending on the DBMS client session allocation strategy the
client id may or may not be available when the client_session
is constructed, therefore there should be a method to assign
an id after construction. Close/cleanup methods were added to
clean up open transactions appropriately.
2018-06-20 10:07:55 +03:00

225 lines
7.9 KiB
C++

//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#ifndef WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP
#define WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP
#include "mock_server_state.hpp"
#include "mock_client_state.hpp"
#include <boost/test/unit_test.hpp>
namespace
{
struct replicating_client_fixture_sync_rm
{
replicating_client_fixture_sync_rm()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct replicating_client_fixture_async_rm
{
replicating_client_fixture_async_rm()
: sc("s1", "s1", wsrep::server_state::rm_async)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct replicating_client_fixture_2pc
{
replicating_client_fixture_2pc()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
cc.do_2pc_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct replicating_client_fixture_autocommit
{
replicating_client_fixture_autocommit()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
cc.is_autocommit_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct applying_client_fixture
{
applying_client_fixture()
: sc("s1", "s1",
wsrep::server_state::rm_async)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_high_priority)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
wsrep::ws_handle ws_handle(1, (void*)1);
wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("1"), wsrep::seqno(1)),
wsrep::stid(sc.id(), 1, cc.id()),
wsrep::seqno(0),
wsrep::provider::flag::start_transaction |
wsrep::provider::flag::commit);
BOOST_REQUIRE(cc.start_transaction(ws_handle, ws_meta) == 0);
BOOST_REQUIRE(tc.active() == true);
BOOST_REQUIRE(tc.certified() == true);
BOOST_REQUIRE(tc.ordered() == true);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct applying_client_fixture_2pc
{
applying_client_fixture_2pc()
: sc("s1", "s1",
wsrep::server_state::rm_async)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_high_priority)
, tc(cc.transaction())
{
cc.open(cc.id());
cc.do_2pc_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
wsrep::ws_handle ws_handle(1, (void*)1);
wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("1"), wsrep::seqno(1)),
wsrep::stid(sc.id(), 1, cc.id()),
wsrep::seqno(0),
wsrep::provider::flag::start_transaction |
wsrep::provider::flag::commit);
BOOST_REQUIRE(cc.start_transaction(ws_handle, ws_meta) == 0);
BOOST_REQUIRE(tc.active() == true);
BOOST_REQUIRE(tc.certified() == true);
BOOST_REQUIRE(tc.ordered() == true);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct streaming_client_fixture_row
{
streaming_client_fixture_row()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
cc.enable_streaming(wsrep::streaming_context::row, 1);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct streaming_client_fixture_byte
{
streaming_client_fixture_byte()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
cc.enable_streaming(wsrep::streaming_context::bytes, 1);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
struct streaming_client_fixture_statement
{
streaming_client_fixture_statement()
: sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_replicating)
, tc(cc.transaction())
{
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
// Verify initial state
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
cc.enable_streaming(wsrep::streaming_context::row, 1);
}
wsrep::mock_server_state sc;
wsrep::mock_client cc;
const wsrep::transaction& tc;
};
}
#endif // WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP