MXS-1475 Add system test for @maxscale.cache.(soft_ttl|hard_ttl)

This commit is contained in:
Johan Wikman 2018-03-15 16:20:13 +02:00
parent 51251fd9f3
commit 749f43a70e
4 changed files with 249 additions and 0 deletions

View File

@ -66,6 +66,7 @@ bug729
bug730
bulk_insert
cache_runtime
cache_runtime_ttl
ccrfilter
cdc_client
cdc_connector-prefix/

View File

@ -542,6 +542,9 @@ add_test_script(cache_basic cache_basic.sh cache_basic LABELS cachefilter REPL_B
# Test of Cache filter - runtime configuration
add_test_executable(cache_runtime.cpp cache_runtime cache_runtime LABELS cachefilter REPL_BACKEND)
# Test of Cache filter - ttl runtime configuration
add_test_executable(cache_runtime_ttl.cpp cache_runtime_ttl cache_runtime_ttl LABELS cachefilter REPL_BACKEND)
# Set utf8mb4 in the backend and restart Maxscale
add_test_executable(mxs951_utfmb4.cpp mxs951_utfmb4 replication LABELS REPL_BACKEND)

View File

@ -0,0 +1,197 @@
/*
* 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: 2020-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 <string>
#include <vector>
#include "testconnections.h"
using namespace std;
namespace
{
enum class Column
{
A,
B,
};
void drop(TestConnections& test)
{
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("DROP TABLE IF EXISTS cache_test");
cout << stmt << endl;
test.try_query(pMysql, stmt.c_str());
}
void create(TestConnections& test)
{
drop(test);
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("CREATE TABLE cache_test (a INT, b INT)");
cout << stmt << endl;
test.try_query(pMysql, stmt.c_str());
}
void insert(TestConnections& test)
{
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("INSERT INTO cache_test VALUES (1, 1)");
cout << stmt << endl;
test.try_query(pMysql, stmt.c_str());
}
void update(TestConnections& test, Column column, int value)
{
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("UPDATE cache_test SET ");
stmt += (column == Column::A) ? "a=" : "b=";
stmt += std::to_string(value);
cout << stmt << endl;
test.try_query(pMysql, stmt.c_str());
}
void select(TestConnections& test, Column column, int* pValue)
{
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("SELECT ");
stmt += (column == Column::A) ? "a" : "b";
stmt += " FROM cache_test";
cout << stmt << endl;
if (mysql_query(pMysql, stmt.c_str()) == 0)
{
if (mysql_field_count(pMysql) != 0)
{
size_t nRows = 0;
do
{
MYSQL_RES* pRes = mysql_store_result(pMysql);
MYSQL_ROW row = mysql_fetch_row(pRes);
*pValue = atoi(row[0]);
mysql_free_result(pRes);
++nRows;
}
while (mysql_next_result(pMysql) == 0);
test.assert(nRows == 1, "Unexpected number of rows: %u", nRows);
}
}
else
{
test.assert(false, "SELECT failed.");
}
}
namespace Cache
{
enum What
{
SOFT_TTL,
HARD_TTL
};
}
void set(TestConnections& test, Cache::What what, uint32_t value)
{
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
string stmt("SET @maxscale.cache.");
stmt += ((what == Cache::SOFT_TTL) ? "soft_ttl" : "hard_ttl");
stmt += "=";
stmt += std::to_string(value);
cout << stmt << endl;
test.try_query(pMysql, stmt.c_str());
}
}
namespace
{
void init(TestConnections& test)
{
create(test);
insert(test);
}
void run(TestConnections& test)
{
init(test);
MYSQL* pMysql = test.maxscales->conn_rwsplit[0];
int value;
// Let's set a long hard_ttl so that it will not interfere
// with the soft_ttl testing.
set(test, Cache::HARD_TTL, 60);
// And update the cache.
select(test, Column::A, &value);
test.assert(value == 1, "Initial value was not 1.");
select(test, Column::B, &value);
test.assert(value == 1, "Initial value was not 1.");
// Update the real value.
update(test, Column::A, 2); // Now the cache contains 1 and the db 2.
update(test, Column::B, 2); // Now the cache contains 1 and the db 2.
sleep(5);
// With a soft_ttl less that the amount we slept should mean that
// the value in the cache is considered stale and that the value
// is fetched from the server.
set(test, Cache::SOFT_TTL, 4);
select(test, Column::A, &value);
test.assert(value == 2, "The value received was not the latest one.");
// With a soft_ttl larger that the amount we slept should mean that
// the value in the cache is *not* considered stale and that we
// get that value.
set(test, Cache::SOFT_TTL, 10);
select(test, Column::B, &value);
test.assert(value == 1, "The value received was not from the cache.");
}
}
int main(int argc, char* argv[])
{
std::ios::sync_with_stdio(true);
TestConnections test(argc, argv);
if (test.maxscales->connect_rwsplit() == 0)
{
run(test);
}
return test.global_result;
}

View File

@ -0,0 +1,48 @@
[maxscale]
threads=###threads###
log_warning=1
[server1]
type=server
address=###node_server_IP_1###
port=###node_server_port_1###
protocol=MySQLBackend
[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=server1
user=maxskysql
passwd=skysql
monitor_interval=1000
detect_stale_master=false
[Cache]
type=filter
module=cache
debug=31
[RWS]
type=service
router= readwritesplit
servers=server1
user=maxskysql
passwd=skysql
filters=Cache
[RWS-Listener]
type=listener
service=RWS
protocol=MySQLClient
port=4006
[CLI]
type=service
router=cli
[CLI-Listener]
type=listener
service=CLI
protocol=maxscaled
#address=localhost
socket=default