You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Initial aurora implementation
This commit is contained in:
@@ -21,7 +21,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/unittest/mytap)
|
||||
ADD_DEFINITIONS(-DLIBMARIADB)
|
||||
|
||||
SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs"
|
||||
SET(API_TESTS "aurora" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs"
|
||||
"sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol")
|
||||
|
||||
# Get finger print from server certificate
|
||||
@@ -61,7 +61,7 @@ ENDIF()
|
||||
|
||||
FOREACH(API_TEST ${API_TESTS})
|
||||
ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c)
|
||||
TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient )
|
||||
TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb)
|
||||
ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST})
|
||||
SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120)
|
||||
ENDFOREACH(API_TEST)
|
||||
|
67
unittest/libmariadb/aurora.c
Normal file
67
unittest/libmariadb/aurora.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
*/
|
||||
|
||||
#include "my_test.h"
|
||||
|
||||
static int aurora1(MYSQL *mysql)
|
||||
{
|
||||
int rc;
|
||||
my_bool read_only= 1;
|
||||
char *primary, *replica;
|
||||
MYSQL_RES *res;
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1, 'foo'), (2, 'bar')");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
primary= mysql->host;
|
||||
diag("primary: %s", primary);
|
||||
|
||||
mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only);
|
||||
|
||||
/* ensure, that this is a replica, so INSERT should fail */
|
||||
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (3, 'error')");
|
||||
if (rc)
|
||||
diag("Expected error: %s", mysql_error(mysql));
|
||||
|
||||
rc= mysql_query(mysql, "SELECT a, b FROM t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
res= mysql_store_result(mysql);
|
||||
|
||||
diag("Num_rows: %d", mysql_num_rows(res));
|
||||
mysql_free_result(res);
|
||||
|
||||
replica= mysql->host;
|
||||
diag("replica: %s", replica);
|
||||
diag("db: %s", mysql->db);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"aurora1", aurora1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
mysql_library_init(0,0,NULL);
|
||||
|
||||
if (argc > 1)
|
||||
get_options(argc, argv);
|
||||
|
||||
get_envvars();
|
||||
|
||||
run_tests(my_tests);
|
||||
|
||||
mysql_server_end();
|
||||
return(exit_status());
|
||||
}
|
@@ -55,13 +55,17 @@ static int test_conc75(MYSQL *my)
|
||||
{
|
||||
ulong thread_id= mysql_thread_id(mysql);
|
||||
/* force reconnect */
|
||||
mysql->reconnect= 1;
|
||||
diag("killing connection");
|
||||
mysql_kill(my, thread_id);
|
||||
sleep(1);
|
||||
sleep(2);
|
||||
mysql_ping(mysql);
|
||||
rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)");
|
||||
FAIL_IF(!test(mysql->options.client_flag | CLIENT_LOCAL_FILES), "client_flags not correct");
|
||||
diag("thread1: %d %d", thread_id, mysql_thread_id(mysql));
|
||||
FAIL_IF(thread_id == mysql_thread_id(mysql), "new thread id expected");
|
||||
diag("cs: %s", mysql->charset->csname);
|
||||
FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set");
|
||||
//diag("cs: %s", mysql->charset->csname);
|
||||
//FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set");
|
||||
}
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
@@ -76,7 +80,12 @@ static int test_conc74(MYSQL *my)
|
||||
mysql= mysql_init(NULL);
|
||||
|
||||
|
||||
mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS);
|
||||
if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS))
|
||||
{
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE IF EXISTS a");
|
||||
check_mysql_rc(rc, mysql);
|
||||
@@ -128,7 +137,11 @@ static int test_conc70(MYSQL *my)
|
||||
int rc;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
MYSQL *mysql;
|
||||
|
||||
SKIP_CONNECTION_HANDLER;
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
|
||||
rc= mysql_query(my, "SET @a:=@@max_allowed_packet");
|
||||
check_mysql_rc(rc, my);
|
||||
@@ -148,6 +161,14 @@ static int test_conc70(MYSQL *my)
|
||||
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
if (mysql_warning_count(mysql))
|
||||
{
|
||||
diag("server doesn't accept package size");
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
sleep(20);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT a FROM t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
@@ -175,7 +196,11 @@ static int test_conc68(MYSQL *my)
|
||||
int rc;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
MYSQL *mysql;
|
||||
|
||||
SKIP_CONNECTION_HANDLER;
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
|
||||
rc= mysql_query(my, "SET @a:=@@max_allowed_packet");
|
||||
check_mysql_rc(rc, my);
|
||||
@@ -193,6 +218,11 @@ static int test_conc68(MYSQL *my)
|
||||
|
||||
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))");
|
||||
check_mysql_rc(rc, mysql);
|
||||
if (mysql_warning_count(mysql))
|
||||
{
|
||||
diag("server doesn't accept package size");
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
rc= mysql_query(mysql, "SELECT a FROM t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
@@ -504,6 +534,7 @@ static int test_mysql_insert_id(MYSQL *mysql)
|
||||
according to the manual, this might be 20 or 300, but it looks like
|
||||
auto_increment column takes priority over last_insert_id().
|
||||
*/
|
||||
diag("res: %d", res);
|
||||
FAIL_UNLESS(res == 20, "");
|
||||
/* If first autogenerated number fails and 2nd works: */
|
||||
rc= mysql_query(mysql, "drop table t2");
|
||||
@@ -618,12 +649,9 @@ static int bug_conc1(MYSQL *mysql)
|
||||
{
|
||||
mysql_real_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname, 0);
|
||||
diag("errno: %d", mysql_errno(mysql));
|
||||
FAIL_IF(mysql_errno(mysql) != CR_ALREADY_CONNECTED,
|
||||
"Expected errno=CR_ALREADY_CONNECTED");
|
||||
FAIL_IF(strcmp(mysql_error(mysql), ER(CR_ALREADY_CONNECTED)) != 0,
|
||||
"Wrong error message");
|
||||
FAIL_IF(strcmp(ER(CR_ALREADY_CONNECTED), "Can't connect twice. Already connected") != 0,
|
||||
"wrong error message");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -668,11 +696,14 @@ static int test_reconnect_maxpackage(MYSQL *my)
|
||||
{
|
||||
int rc;
|
||||
ulong max_packet= 0;
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
MYSQL *mysql;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
char *query;
|
||||
|
||||
SKIP_CONNECTION_HANDLER;
|
||||
mysql= mysql_init(NULL);
|
||||
|
||||
FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname,
|
||||
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql));
|
||||
@@ -770,6 +801,8 @@ int main(int argc, char **argv)
|
||||
|
||||
get_envvars();
|
||||
|
||||
diag("user: %s", username);
|
||||
|
||||
run_tests(my_tests);
|
||||
|
||||
return(exit_status());
|
||||
|
@@ -679,7 +679,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql)
|
||||
|
||||
for (i= 0; i < sizeof(csname)/sizeof(char*); ++i)
|
||||
{
|
||||
csinfo[i]= mysql_find_charset_name(csname[i]);
|
||||
csinfo[i]= mariadb_get_charset_by_name(csname[i]);
|
||||
|
||||
if (csinfo[i] == NULL)
|
||||
{
|
||||
|
@@ -32,6 +32,7 @@ static int test_conc66(MYSQL *my)
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
int rc;
|
||||
FILE *fp;
|
||||
char query[1024];
|
||||
|
||||
if (!(fp= fopen("./my.cnf", "w")))
|
||||
return FAIL;
|
||||
@@ -47,7 +48,8 @@ static int test_conc66(MYSQL *my)
|
||||
rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(my, "GRANT ALL ON test.* TO 'conc66'@'localhost' IDENTIFIED BY 'test\";#test'");
|
||||
sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname);
|
||||
rc= mysql_query(my, query);
|
||||
check_mysql_rc(rc, my);
|
||||
rc= mysql_query(my, "FLUSH PRIVILEGES");
|
||||
check_mysql_rc(rc, my);
|
||||
@@ -57,7 +59,8 @@ static int test_conc66(MYSQL *my)
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
return FAIL;
|
||||
}
|
||||
rc= mysql_query(my, "DROP USER conc66@localhost");
|
||||
sprintf(query, "DROP user conc66@%s", hostname);
|
||||
rc= mysql_query(my, query);
|
||||
|
||||
check_mysql_rc(rc, my);
|
||||
mysql_close(mysql);
|
||||
@@ -561,6 +564,8 @@ static int test_reconnect(MYSQL *mysql)
|
||||
mysql_kill(mysql, mysql_thread_id(mysql1));
|
||||
sleep(4);
|
||||
|
||||
mysql_ping(mysql1);
|
||||
|
||||
rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0");
|
||||
check_mysql_rc(rc, mysql1);
|
||||
diag("Thread_id after kill: %lu", mysql_thread_id(mysql1));
|
||||
@@ -649,6 +654,8 @@ static int test_conc118(MYSQL *mysql)
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
sleep(2);
|
||||
|
||||
mysql_ping(mysql);
|
||||
|
||||
rc= mysql_query(mysql, "SET @a:=1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
@@ -657,12 +664,9 @@ static int test_conc118(MYSQL *mysql)
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
sleep(2);
|
||||
|
||||
mysql->host= "foo";
|
||||
|
||||
rc= mysql_query(mysql, "SET @a:=1");
|
||||
FAIL_IF(!rc, "error expected");
|
||||
|
||||
mysql->host= hostname;
|
||||
rc= mysql_query(mysql, "SET @a:=1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
|
@@ -82,6 +82,13 @@ if (!(expr))\
|
||||
return FAIL;\
|
||||
}
|
||||
|
||||
#define SKIP_CONNECTION_HANDLER \
|
||||
if (hostname && strstr(hostname, "://"))\
|
||||
{\
|
||||
diag("Test skipped (connection handler)");\
|
||||
return SKIP;\
|
||||
}
|
||||
|
||||
/* connection options */
|
||||
#define TEST_CONNECTION_DEFAULT 1 /* default connection */
|
||||
#define TEST_CONNECTION_NONE 2 /* tests creates own connection */
|
||||
@@ -104,7 +111,7 @@ struct my_tests_st
|
||||
char *skipmsg;
|
||||
};
|
||||
|
||||
static char *schema = "test_c";
|
||||
static char *schema = 0;
|
||||
static char *hostname = 0;
|
||||
static char *password = 0;
|
||||
static unsigned int port = 0;
|
||||
@@ -368,18 +375,19 @@ int check_variable(MYSQL *mysql, char *variable, char *value)
|
||||
MYSQL *test_connect(struct my_tests_st *test) {
|
||||
MYSQL *mysql;
|
||||
char query[255];
|
||||
int i= 1;
|
||||
int i= 0;
|
||||
int timeout= 10;
|
||||
int truncation_report= 1;
|
||||
if (!(mysql = mysql_init(NULL))) {
|
||||
diag("%s", "mysql_init failed - exiting");
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &i);
|
||||
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&i);
|
||||
mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &truncation_report);
|
||||
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);
|
||||
|
||||
/* option handling */
|
||||
if (test && test->options) {
|
||||
int i=0;
|
||||
|
||||
while (test->options[i].option)
|
||||
{
|
||||
@@ -403,6 +411,8 @@ MYSQL *test_connect(struct my_tests_st *test) {
|
||||
|
||||
/* change database or create if it doesn't exist */
|
||||
if (mysql_select_db(mysql, schema)) {
|
||||
diag("Error number: %d", mysql_errno(mysql));
|
||||
|
||||
if(mysql_errno(mysql) == 1049) {
|
||||
sprintf(query, "CREATE DATABASE %s", schema);
|
||||
if (mysql_query(mysql, query)) {
|
||||
@@ -425,11 +435,6 @@ static int reset_connection(MYSQL *mysql) {
|
||||
|
||||
rc= mysql_change_user(mysql, username, password, schema);
|
||||
check_mysql_rc(rc, mysql);
|
||||
if (mysql_get_server_version(mysql) < 50400)
|
||||
rc= mysql_query(mysql, "SET table_type='MyISAM'");
|
||||
else
|
||||
rc= mysql_query(mysql, "SET storage_engine='MyISAM'");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_query(mysql, "SET sql_mode=''");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
@@ -452,6 +457,8 @@ void get_envvars() {
|
||||
password= envvar;
|
||||
if (!schema && (envvar= getenv("MYSQL_TEST_DB")))
|
||||
schema= envvar;
|
||||
if (!schema)
|
||||
schema= "testc";
|
||||
if (!port && (envvar= getenv("MYSQL_TEST_PORT")))
|
||||
port= atoi(envvar);
|
||||
if (!socketname && (envvar= getenv("MYSQL_TEST_SOCKET")))
|
||||
@@ -470,7 +477,8 @@ void run_tests(struct my_tests_st *test) {
|
||||
if ((mysql_default= test_connect(NULL)))
|
||||
{
|
||||
diag("Testing against MySQL Server %s", mysql_get_server_info(mysql_default));
|
||||
diag("Host %s", mysql_get_host_info(mysql_default));
|
||||
diag("Host: %s", mysql_get_host_info(mysql_default));
|
||||
diag("Client library: %s", mysql_get_client_info());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -64,7 +64,10 @@ static int test_conc83(MYSQL *my)
|
||||
/* 1. Status is inited, so prepare should work */
|
||||
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
sleep(2);
|
||||
sleep(5);
|
||||
|
||||
rc= mysql_ping(mysql);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_stmt_prepare(stmt, query, strlen(query));
|
||||
check_stmt_rc(rc, stmt);
|
||||
|
@@ -528,9 +528,8 @@ static int test_bug12744(MYSQL *mysql)
|
||||
rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_kill(mysql, mysql_thread_id(mysql));
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
sleep(2);
|
||||
sleep(4);
|
||||
rc= mysql_ping(mysql);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
|
Reference in New Issue
Block a user