MXS-2008 Move Worker and MessageQueue to maxbase

This commit is contained in:
Johan Wikman
2018-08-20 13:03:39 +03:00
parent 02ed338afa
commit 88f1795412
29 changed files with 196 additions and 199 deletions

View File

@ -26,7 +26,6 @@ add_executable(test_trxtracking test_trxtracking.cc)
add_executable(test_users test_users.cc)
add_executable(test_utils test_utils.cc)
add_executable(test_session_track test_session_track.cc)
add_executable(test_worker test_worker.cc)
target_link_libraries(profile_trxboundaryparser maxscale-common)
target_link_libraries(test_adminusers maxscale-common)
@ -56,7 +55,6 @@ target_link_libraries(test_trxtracking maxscale-common)
target_link_libraries(test_users maxscale-common)
target_link_libraries(test_utils maxscale-common)
target_link_libraries(test_session_track mysqlcommon)
target_link_libraries(test_worker maxscale-common)
add_test(test_adminusers test_adminusers)
add_test(test_atomic test_atomic)
@ -92,7 +90,6 @@ add_test(test_trxtracking test_trxtracking)
add_test(test_users test_users)
add_test(test_utils test_utils)
add_test(test_session_track test_session_track)
add_test(test_worker test_worker)
add_subdirectory(rest-api)
add_subdirectory(canonical_tests)

View File

@ -36,7 +36,6 @@
#include <maxscale/config.h>
#include <maxscale/listener.h>
#include <maxscale/messagequeue.hh>
#include "../internal/routingworker.hh"
#include "../dcb.cc"

View File

@ -15,9 +15,9 @@
* Test modulecmd.h functionality
*/
#include <maxbase/messagequeue.hh>
#include <maxscale/alloc.h>
#include <maxscale/dcb.h>
#include <maxscale/messagequeue.hh>
#include <maxscale/paths.h>
#include <maxscale/modulecmd.h>
#include <maxscale/session.h>
@ -466,7 +466,7 @@ int main(int argc, char **argv)
int rc = 0;
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT);
mxs::MessageQueue::init();
mxb::MessageQueue::init();
rc += test_arguments();
rc += test_optional_arguments();

View File

@ -15,6 +15,8 @@
*/
#include <maxscale/cdefs.h>
#include <maxbase/messagequeue.hh>
#include <maxbase/worker.hh>
#include <maxscale/dcb.h>
#include <maxscale/housekeeper.h>
#include <maxscale/maxscale_test.h>
@ -46,8 +48,8 @@ void init_test_env(char *path)
qc_setup(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL);
qc_process_init(QC_INIT_BOTH);
poll_init();
maxscale::MessageQueue::init();
maxscale::Worker::init();
mxb::MessageQueue::init();
mxb::Worker::init();
maxscale::RoutingWorker::init();
hkinit();
}

View File

@ -1,139 +0,0 @@
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2022-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include <iostream>
#include <maxscale/worker.hh>
#include "../internal/poll.hh"
using namespace maxscale;
using namespace std;
namespace
{
// TODO: Put this in some common place.
int64_t get_monotonic_time_ms()
{
struct timespec ts;
ss_debug(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts);
ss_dassert(rv == 0);
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
class TimerTest
{
public:
static int s_ticks;
TimerTest(Worker* pWorker, int* pRv, int32_t delay)
: m_id(s_id++)
, m_worker(*pWorker)
, m_delay(delay)
, m_at(get_monotonic_time_ms() + delay)
, m_rv(*pRv)
{
}
int32_t delay() const
{
return m_delay;
}
bool tick(mxs::Worker::Call::action_t action)
{
bool rv = false;
if (action == mxs::Worker::Call::EXECUTE)
{
int64_t now = get_monotonic_time_ms();
int64_t diff = abs(now - m_at);
cout << m_id << ": " << diff << endl;
if (diff > 50)
{
cout << "Error: Difference between expected and happened > 50: " << diff << endl;
m_rv = EXIT_FAILURE;
}
m_at += m_delay;
if (--s_ticks < 0)
{
m_worker.shutdown();
}
rv = true;
}
return rv;
}
private:
static int s_id;
int m_id;
Worker& m_worker;
int32_t m_delay;
int64_t m_at;
int& m_rv;
};
int TimerTest::s_id = 1;
int TimerTest::s_ticks;
int run()
{
int rv = EXIT_SUCCESS;
TimerTest::s_ticks = 100;
Worker w;
TimerTest t1(&w, &rv, 200);
TimerTest t2(&w, &rv, 300);
TimerTest t3(&w, &rv, 400);
TimerTest t4(&w, &rv, 500);
TimerTest t5(&w, &rv, 600);
w.delayed_call(t1.delay(), &TimerTest::tick, &t1);
w.delayed_call(t2.delay(), &TimerTest::tick, &t2);
w.delayed_call(t3.delay(), &TimerTest::tick, &t3);
w.delayed_call(t4.delay(), &TimerTest::tick, &t4);
w.delayed_call(t5.delay(), &TimerTest::tick, &t5);
w.run();
return EXIT_SUCCESS;
}
}
int main()
{
int rv = EXIT_FAILURE;
if (mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT))
{
poll_init();
maxscale::MessageQueue::init();
maxscale::Worker::init();
rv = run();
mxs_log_finish();
}
return rv;
}