int main(int argc, char *argv[])
{
    int OldMaster;
    int NewMaster;

    if (argc != 3)
    {
        printf("Usage: change_master NewMasterNode OldMasterNode\n");
        exit(1);
    }
    TestConnections * Test = new TestConnections(argc, argv);

    sscanf(argv[1], "%d", &NewMaster);
    sscanf(argv[2], "%d", &OldMaster);

    Test->tprintf("Changing master from node %d (%s) to node %d (%s)\n", OldMaster, Test->repl->IP[OldMaster],
                  NewMaster, Test->repl->IP[NewMaster]);

    Test->repl->connect();
    Test->repl->change_master(NewMaster, OldMaster);
    Test->repl->close_connections();

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();


    Test->binlog_cmd_option = 2;
    Test->start_binlog();

    Test->repl->connect();

    create_t1(Test->repl->nodes[0]);
    global_result += insert_into_t1(Test->repl->nodes[0], 4);
    printf("Sleeping to let replication happen\n"); fflush(stdout);
    sleep(30);

    for (int i = 0; i < Test->repl->N; i++) {
        printf("Checking data from node %d (%s)\n", i, Test->repl->IP[i]); fflush(stdout);
        global_result += select_from_t1(Test->repl->nodes[i], 4);
    }

    Test->repl->close_connections();


    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    int global_result = 0;
    int OldMaster;
    int NewMaster;

    if (argc !=3) {
        printf("Usage: change_master NewMasterNode OldMasterNode\n");
        exit(1);
    }
    TestConnections * Test = new TestConnections(argc, argv);
    Test->read_env();
    Test->print_env();

    sscanf(argv[1], "%d", &NewMaster);
    sscanf(argv[2], "%d", &OldMaster);

    printf("Changing master from node %d (%s) to node %d (%s)\n", OldMaster, Test->repl->IP[OldMaster], NewMaster, Test->repl->IP[NewMaster]);

    Test->repl->connect();
    Test->repl->change_master(NewMaster, OldMaster);
    Test->repl->close_connections();

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->print_env();
    global_result += execute_maxadmin_command_print(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, (char *) "show servers");

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(30);
    Test->check_log_err((char *) "Unexpected parameter 'укпоукц'", true);
    Test->check_log_err((char *) "Unexpected parameter 'hren'", true);

    Test->check_maxscale_processes(0);
    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();

    printf("Connecting to RWSplit %s\n", Test->maxscale_IP);
    Test->connect_rwsplit();

    printf("Setup firewall to block mysql on master\n"); fflush(stdout);
    Test->repl->block_node(0);

    printf("Trying query to RWSplit, expecting failure, but not a crash\n"); fflush(stdout);
    execute_query(Test->conn_rwsplit, (char *) "show processlist;");

    printf("Setup firewall back to allow mysql\n"); fflush(stdout);
    Test->repl->unblock_node(0);

    sleep(10);

    global_result += check_maxscale_alive();

    Test->close_rwsplit();


    printf("Reconnecting and trying query to RWSplit\n"); fflush(stdout);
    Test->connect_rwsplit();
    global_result += execute_query(Test->conn_rwsplit, (char *) "show processlist;");
    Test->close_rwsplit();

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->connect_maxscale();
    Test->set_timeout(10);
    Test->tprintf("Trying SHOW GLOBAL STATUS against RWSplit\n");
    Test->try_query(Test->conn_rwsplit, (char *) "SHOW GLOBAL STATUS;");
    Test->tprintf("Trying SHOW GLOBAL STATUS against ReadConn master\n");
    Test->try_query(Test->conn_master,  (char *) "SHOW GLOBAL STATUS;");
    Test->tprintf("Trying SHOW GLOBAL STATUS against ReadConn slave\n");
    Test->try_query(Test->conn_slave,   (char *) "SHOW GLOBAL STATUS;");
    Test->check_maxscale_alive();
    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(30);

    Test->ssh_maxscale(true, "maxkeys");
    Test->ssh_maxscale(true, "sudo chown maxscale:maxscale /var/lib/maxscale/.secrets");

    try_password(Test, (char *) "aaa$aaa");
    try_password(Test, (char *) "#¤&");
    try_password(Test, (char *) "пароль");

    Test->check_maxscale_alive();
    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(30);

    Test->galera->connect();

    tolerance = 0;

    // connect to the MaxScale server (rwsplit)
    Test->connect_rwsplit();

    Test->execute_maxadmin_command((char *) "shutdown monitor \"Galera Monitor\"");

    if (Test->conn_rwsplit == NULL )
    {
        Test->add_result(1, "Can't connect to MaxScale\n");
        int rval = Test->global_result;
        delete Test;
        exit(1);
    }
    else
    {

        Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1;");
        Test->try_query(Test->conn_rwsplit, "create table t1 (x1 int);");

        get_global_status_allnodes(&selects[0], &inserts[0], Test->galera, silent);
        Test->try_query(Test->conn_rwsplit, "select * from t1;");
        get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->galera, silent);
        print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->galera->N);

        Test->try_query(Test->conn_rwsplit, "insert into t1 values(1);");
        get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->galera, silent);
        print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->galera->N);

        // close connections
        Test->close_rwsplit();
    }
    Test->galera->close_connections();

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);

    Test->tprintf("Trying 11 connections with RWSplit\n");
    check_max_conn(0, 10, Test);
    Test->tprintf("Trying 21 connections with Readconn master\n");
    check_max_conn(1, 20, Test);
    Test->tprintf("Trying 26 connections with Readconnn slave\n");
    check_max_conn(2, 25, Test);

    sleep(10);

    Test->check_maxscale_alive();
    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections *test = new TestConnections(argc, argv);
    Config config(test);

    config.create_all_listeners();
    config.create_all_listeners();
    test->check_maxscale_processes(1);

    config.create_monitor("mysql-monitor", "mysqlmon", 500);
    config.reset();

    sleep(1);

    test->check_maxscale_alive();
    int rval = test->global_result;
    delete test;
    return rval;
}
int main(int argc, char *argv[])
{

    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(3000);
    int options_set = 3;
    if (Test->smoke)
    {
        options_set = 1;
    }

    Test->repl->connect();
    execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;");
    Test->repl->close_connections();
    sleep(5);

    for (int option = 0; option < options_set; option++)
    {
        Test->binlog_cmd_option = option;
        Test->start_binlog();
        test_binlog(Test);
    }

    Test->check_log_err("SET NAMES utf8mb4", false);
    Test->check_log_err("set autocommit=1", false);
    Test->check_log_err("select USER()", false);

    int rval = Test->global_result;
    delete Test;
    return rval;
}
Пример #13
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();

    Test->connect_maxscale();

    printf("Trying SELECT @a:=@a+1 as a, test.b FROM test\n"); fflush(stdout);
    global_result += execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test; CREATE TABLE test (b integer);");
    for (int i=0; i<10000;i++) {execute_query(Test->conn_rwsplit, "insert into test value(2);");}
    if (execute_query(Test->conn_rwsplit, "SELECT @a:=@a+1 as a, test.b FROM test;") == 0) {
        printf("Query succeded, but expected to fail. Test FAILED!\n"); fflush(stdout);
        global_result++;
    }
    printf("Trying USE test\n"); fflush(stdout);
    global_result += execute_query(Test->conn_rwsplit, "USE test");

    global_result += execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test;");

    printf("Checking if MaxScale alive\n"); fflush(stdout);
    Test->close_maxscale_connections();

    printf("Checking logs\n"); fflush(stdout);
    global_result    += check_log_err((char *) "Warning : The query can't be routed to all backend servers because it includes SELECT and SQL variable modifications which is not supported", TRUE);
    global_result    += check_log_err((char *) "SELECT with session data modification is not supported if configuration parameter use_sql_variables_in=all", TRUE);

    global_result += check_maxscale_alive();

    Test->copy_all_logs(); return(global_result);
}
Пример #14
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;
    int i;

    Test->read_env();
    Test->print_env();

    printf("Connecting to all MaxScale services\n");
    fflush(stdout);
    global_result += Test->connect_maxscale();

    printf("executing show status 1000 times\n");
    fflush(stdout);


    for (i = 0; i < 1000; i++)  {
        global_result += execute_query(Test->conn_rwsplit, (char *) "show status");
    }
    for (i = 0; i < 1000; i++)  {
        global_result += execute_query(Test->conn_slave, (char *) "show status");
    }
    for (i = 0; i < 1000; i++)  {
        global_result += execute_query(Test->conn_master, (char *) "show status");
    }

    Test->close_maxscale_connections();

    check_maxscale_alive();

    Test->copy_all_logs();
    return(global_result);
}
Пример #15
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->print_env();

    Test->connect_maxscale();

    printf("RWSplit: \n"); fflush(stdout);
    global_result = execute_query(Test->conn_rwsplit, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;");
    printf("ReadConn master: \n"); fflush(stdout);
    global_result = execute_query(Test->conn_master, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;");
    printf("readConn slave: \n"); fflush(stdout);
    global_result = execute_query(Test->conn_slave, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;");

    Test->close_maxscale_connections();

    global_result += check_maxscale_alive();

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{

    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(20);

    Test->connect_maxscale();

    Test->tprintf("Trying query to ReadConn master\n");
    fflush(stdout);
    Test->try_query(Test->conn_master, "show processlist;");
    Test->tprintf("Trying query to ReadConn slave\n");
    Test->try_query(Test->conn_slave, "show processlist;");

    Test->close_maxscale_connections();

    Test->check_log_err((char *) "Creating client session for Tee filter failed. Terminating session.", true);
    Test->check_log_err((char *) "Failed to create filter 'DuplicaFilter' for service 'RW_Router'", true);

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;
    int i;
    int N=4;

    Test->read_env();
    Test->print_env();


    for (i = 0; i < 4; i++) {
        Test->repl->connect();
        if (Test->connect_maxscale() !=0 ) {
            printf("Error connecting to MaxScale\n");
            exit(1);
        }

        global_result += insert_select(Test, N);

        printf("Creating database test1\n"); fflush(stdout);
        global_result += execute_query(Test->conn_rwsplit, "DROP TABLE t1");
        global_result += execute_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS test1;");
        global_result += execute_query(Test->conn_rwsplit, "CREATE DATABASE test1;");
        sleep(5);

        printf("Testing with database 'test1'\n");fflush(stdout);
        global_result += use_db(Test, (char *) "test1");
        global_result += insert_select(Test, N);

        global_result += check_t1_table(Test, FALSE, (char *) "test");
        global_result += check_t1_table(Test, TRUE, (char *) "test1");



        printf("Trying queries with syntax errors\n");fflush(stdout);
        execute_query(Test->conn_rwsplit, "DROP DATABASE I EXISTS test1;");
        execute_query(Test->conn_rwsplit, "CREATE TABLE ");

        execute_query(Test->conn_master, "DROP DATABASE I EXISTS test1;");
        execute_query(Test->conn_master, "CREATE TABLE ");

        execute_query(Test->conn_slave, "DROP DATABASE I EXISTS test1;");
        execute_query(Test->conn_slave, "CREATE TABLE ");

        // close connections
        Test->close_maxscale_connections();
        Test->repl->close_connections();

    }

    global_result += check_maxscale_alive();

    if (global_result == 0) {printf("PASSED!!\n");} else {printf("FAILED!!\n");}
    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(100);
    Test->execute_maxadmin_command((char *) "show monitors");
    sleep(5);
    Test->check_log_err((char *) "Failed to start monitor", true);
    Test->check_log_err((char *) "fatal signal 11", false);

    Test->check_maxscale_processes(1);

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(20);
    int i, j;
    MYSQL * conn;

    int N_cmd = 2;
    char * fail_cmd[N_cmd - 1];

    int N_ports = 3;
    int ports[N_ports];

    fail_cmd[0] = (char *) "fail backendfd";
    fail_cmd[1] = (char *) "fail clientfd";

    ports[0] = Test->rwsplit_port;
    ports[1] = Test->readconn_master_port;
    ports[2] = Test->readconn_slave_port;

    for (i = 0; i < N_cmd; i++)
    {
        for (j = 0; j < N_ports; j++)
        {
            Test->tprintf("Executing MaxAdmin command '%s'\n", fail_cmd[i]);
            if (execute_maxadmin_command(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, fail_cmd[i]) != 0)
            {
                Test->add_result(1, "MaxAdmin command failed\n");
            }
            else
            {
                printf("Trying query against %d\n", ports[j]);
                conn = open_conn(ports[j], Test->maxscale_IP, Test->maxscale_user, Test->maxscale_user, Test->ssl);
                Test->try_query(conn, (char *) "show processlist;");
            }
        }
    }

    Test->check_maxscale_alive();
    int rval = Test->global_result;
    delete Test;
    return rval;
}
Пример #20
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->ReadEnv();
    Test->PrintIP();

    Test->ConnectMaxscale();


    execute_query(Test->conn_rwsplit, (char *) "select @@server_id; -- max_slave_replication_lag=120");




    Test->CloseMaxscaleConn();


    global_result += CheckMaxscaleAlive();

    Test->Copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{

    TestConnections * Test = new TestConnections(argc, argv);
    int master;
    long int q;
    int threads_num = 25;

    long int selects[256];
    long int inserts[256];
    long int new_selects[256];
    long int new_inserts[256];
    long int i1, i2;

    Test->set_timeout(20);
    master = Test->find_master_maxadmin(Test->galera);

    if (master >= 0)
    {
        Test->tprintf("Master node is %d (server%d)\n", master, master + 1);
        Test->set_timeout(20);

        if (Test->smoke)
        {
            threads_num = 15;
        }
        Test->galera->connect();
        for (int i = 0; i < Test->galera->N; i++)
        {
            execute_query(Test->galera->nodes[i], (char *) "set global max_connections = 300;");
            execute_query(Test->galera->nodes[i], (char *) "set global max_connect_errors = 100000;");
        }
        Test->galera->close_connections();

        Test->set_timeout(1200);
        load(&new_inserts[0], &new_selects[0], &selects[0], &inserts[0], threads_num, Test, &i1, &i2, 1, true, true);

        long int avr = (i1 + i2 ) / (Test->galera->N);
        Test->tprintf("average number of quries per node %ld\n", avr);
        long int min_q = avr / 3;
        long int max_q = avr * 3;
        Test->tprintf("Acceplable value for every node from %ld until %ld\n", min_q, max_q);

        for (int i = 0; i < Test->galera->N; i++)
        {
            if ( i != master)
            {
                q = new_selects[i] - selects[i];
                if ((q > max_q) || (q < min_q))
                {
                    Test->add_result(1, "number of queries for node %d is %ld\n", i + 1, q);
                }
            }
        }

        if ((new_selects[master] - selects[master]) > avr / 3 )
        {
            Test->add_result(1,
                             "number of queries for master greater then 30%% of averange number of queries per node\n");
        }

        Test->tprintf("Restoring nodes\n");
        Test->galera->connect();
        for (int i = 0; i < Test->galera->N; i++)
        {
            execute_query(Test->galera->nodes[i], (char *) "flush hosts;");
            execute_query(Test->galera->nodes[i], (char *) "set global max_connections = 151;");
        }
        Test->galera->close_connections();

        Test->check_maxscale_alive();
    }
    else
    {
        Test->add_result(1, "Master is not found\n");
    }

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char **argv)
{
    TestConnections *test = new TestConnections(argc, argv);

    char server_id[test->repl->N][1024];

    test->repl->connect();
    /** Get server_id for each node */
    for (int i = 0; i < test->repl->N; i++)
    {
        sprintf(server_id[i], "%d", test->repl->get_server_id(i));
    }

    test->tprintf("Block the master and try a read query\n");
    test->repl->block_node(0);
    sleep(15);
    test->connect_readconn_slave();
    char first_slave[1024];
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", first_slave);

    int found = -1;

    for (int i = 0; i < test->repl->N; i++)
    {
        if (strcmp(server_id[i], first_slave) == 0)
        {
            found = i;
            break;
        }
    }

    test->add_result(found < 0, "No server with ID '%s' found.", first_slave);

    test->tprintf("Blocking node %d\n", found + 1);
    test->repl->block_node(found);
    sleep(15);

    test->tprintf("Blocked the slave that replied to us, expecting a different slave\n");
    test->connect_readconn_slave();
    char second_slave[1024];
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave);
    test->add_result(strcmp(first_slave, second_slave) == 0,
                     "Server IDs match when they shouldn't: %s - %s",
                     first_slave, second_slave);

    test->tprintf("Unblocking the slave that replied\n");
    test->repl->unblock_node(found);
    sleep(15);

    test->tprintf("Unblocked the slave, still expecting a different slave\n");
    test->connect_readconn_slave();
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave);
    test->add_result(strcmp(first_slave, second_slave) == 0,
                     "Server IDs match when they shouldn't: %s - %s",
                     first_slave, second_slave);

    test->tprintf("Unblocking all nodes\n");
    test->repl->unblock_all_nodes();
    sleep(15);

    test->tprintf("Unblocked all nodes, expecting the server ID of the first slave server\n");
    test->connect_readconn_slave();
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave);
    test->add_result(strcmp(first_slave, second_slave) != 0,
                     "Server IDs don't match when they should: %s - %s",
                     first_slave, second_slave);

    test->tprintf("Stopping replication on node %d\n", found + 1);
    execute_query(test->repl->nodes[found], "stop slave");
    sleep(15);

    test->tprintf("Stopped replication, expecting a different slave\n");
    test->connect_readconn_slave();
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave);
    test->add_result(strcmp(first_slave, second_slave) == 0,
                     "Server IDs match when they shouldn't: %s - %s",
                     first_slave, second_slave);

    test->tprintf("Starting replication on node %d\n", found + 1);
    execute_query(test->repl->nodes[found], "start slave");
    sleep(15);

    test->tprintf("Started replication, expecting the server ID of the first slave server\n");
    test->connect_readconn_slave();
    find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave);
    test->add_result(strcmp(first_slave, second_slave) != 0,
                     "Server IDs don't match when they should: %s - %s",
                     first_slave, second_slave);

    int rval = test->global_result;
    delete test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(20);
    Test->repl->connect();

    Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_ip());
    Test->connect_rwsplit();

    unsigned int conn_num;
    unsigned int all_conn = 0;
    Test->tprintf("Sleeping 5 seconds\n");
    sleep(5);
    Test->tprintf("Checking number of connections ot backend servers\n");
    for (int i = 0; i < Test->repl->N; i++)
    {
        conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test");
        Test->tprintf("connections: %u\n", conn_num);
        if ((i == 0) && (conn_num != 1))
        {
            Test->add_result(1, " Master should have only 1 connection, but it has %d connection(s)\n", conn_num);
        }
        all_conn += conn_num;
    }
    if (all_conn != 2)
    {
        Test->add_result(1,
                         "there should be two connections in total: one to master and one to one of slaves, but number of connections is %d\n",
                         all_conn);
    }

    Test->close_rwsplit();
    Test->repl->close_connections();

    int rval = Test->global_result;
    delete Test;
    return rval;
}
bool run_test(TestConnections& test)
{
    bool rval = true;

    for (int x = 0; test_set[x].types; x++)
    {
        for (int i = 0; test_set[x].types[i]; i++)
        {
            std::string name = type_to_table_name(test_set[x].types[i]);
            insert_data(test, name.c_str(), test_set[x].types[i], test_set[x].values);
        }
    }

    test.repl->connect();
    execute_query(test.repl->nodes[0], "FLUSH LOGS");
    test.repl->close_connections();
    sleep(10);

    for (int x = 0; test_set[x].types; x++)
    {
        for (int i = 0; test_set[x].types[i]; i++)
        {
            test.set_timeout(60);
            test.tprintf("Testing type: %s", test_set[x].types[i]);
            std::string name = type_to_table_name(test_set[x].types[i]);
            CDC::Connection conn(test.maxscale_IP, 4001, "skysql", "skysql");

            if (conn.createConnection() && conn.requestData(name))
            {
                for (int j = 0; test_set[x].values[j]; j++)
                {
                    std::string row;

                    if (conn.readRow(row))
                    {
                        TestInput input(test_set[x].values[j], test_set[x].types[i]);
                        TestOutput output(row, field_name);

                        if (input != output)
                        {
                            test.tprintf("Result mismatch: %s(%s) => %s",
                                         test_set[x].types[i], test_set[x].values[j], output.getValue().c_str());
                            rval = false;
                        }
                    }
                    else
                    {
                        std::string err = conn.getError();
                        test.tprintf("Failed to read data: %s", err.c_str());
                    }
                }
            }
            else
            {
                std::string err = conn.getError();
                test.tprintf("Failed to request data: %s", err.c_str());
                rval = false;
            }
            test.stop_timeout();
        }
    }
    return rval;
}
Пример #25
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;
    int N=4;
    char str[1024];

    Test->read_env();
    Test->print_env();

    Test->connect_maxscale();
    Test->repl->connect();

    printf("Create t1\n"); fflush(stdout);
    create_t1(Test->conn_rwsplit);
    printf("Insert data into t1\n"); fflush(stdout);
    insert_into_t1(Test->conn_rwsplit, N);
    printf("Sleeping to let replication happen\n");fflush(stdout);
    sleep(30);

    printf("Copying data from t1 to file\n");fflush(stdout);
    sprintf(str, "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s@%s '%s rm /tmp/t*.csv; %s chmod 777 -R /tmp'", Test->repl->sshkey[0], Test->repl->access_user, Test->repl->IP[0], Test->repl->access_sudo, Test->repl->access_sudo);
    printf("%s\n", str);
    system(str);

    printf("RWSplit:\n");fflush(stdout);
    global_result += execute_query(Test->conn_rwsplit, (char *) "SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;");
    printf("ReadsConn master:\n");fflush(stdout);
    global_result += execute_query(Test->conn_master, (char *) "SELECT * INTO OUTFILE '/tmp/t2.csv' FROM t1;");
    printf("ReadsConn slave:\n");fflush(stdout);
    global_result += execute_query(Test->conn_slave, (char *) "SELECT * INTO OUTFILE '/tmp/t3.csv' FROM t1;");

    printf("Copying t1.cvs from Maxscale machine:\n");fflush(stdout);
    sprintf(str, "scp -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s@%s:/tmp/t1.csv ./", Test->repl->sshkey[0], Test->repl->access_user, Test->repl->IP[0]);
    printf("%s\n", str);
    system(str);

    MYSQL *srv[2];

    srv[0] = Test->conn_rwsplit;
    srv[1] = Test->conn_master;
    for (int i=0; i<2; i++) {
        printf("Dropping t1 \n");fflush(stdout);
        global_result += execute_query(Test->conn_rwsplit, (char *) "DROP TABLE t1;");
        printf("Sleeping to let replication happen\n");fflush(stdout);
        sleep(100);
        printf("Create t1\n"); fflush(stdout);
        create_t1(Test->conn_rwsplit);
        printf("Loading data to t1 from file\n");fflush(stdout);
        global_result += execute_query(srv[i], (char *) "LOAD DATA LOCAL INFILE 't1.csv' INTO TABLE t1;");

        printf("Sleeping to let replication happen\n");fflush(stdout);
        sleep(100);
        printf("SELECT: rwsplitter\n");fflush(stdout);
        global_result += select_from_t1(Test->conn_rwsplit, N);
        printf("SELECT: master\n");fflush(stdout);
        global_result += select_from_t1(Test->conn_master, N);
        printf("SELECT: slave\n");fflush(stdout);
        global_result += select_from_t1(Test->conn_slave, N);
        printf("Sleeping to let replication happen\n");fflush(stdout);
        /*sleep(100);
        for (int i=0; i<Test->repl->N; i++) {
            printf("SELECT: directly from node %d\n", i);fflush(stdout);
            global_result += select_from_t1(Test->repl->nodes[i], N);
        }*/
    }



    Test->repl->close_connections();
    global_result += check_maxscale_alive();

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(30);
    MYSQL * conn_found_rows;
    my_ulonglong rows;


    Test->repl->connect();
    Test->connect_maxscale();

    conn_found_rows = open_conn_db_flags(Test->rwsplit_port, Test->maxscale_IP, (char *) "test",
                                         Test->maxscale_user, Test->maxscale_password, CLIENT_FOUND_ROWS, Test->ssl);

    Test->set_timeout(30);
    execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1");
    execute_query(Test->conn_rwsplit, "CREATE TABLE t1(id INT PRIMARY KEY, val INT, msg VARCHAR(100))");
    execute_query(Test->conn_rwsplit,
                  "INSERT INTO t1 VALUES (1, 1, 'foo'), (2, 1, 'bar'), (3, 2, 'baz'), (4, 2, 'abc')");

    Test->set_timeout(30);
    execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #1: %ld (expeced value is 2)\n", (long) rows);
    if (rows != 2)
    {
        Test->add_result(1, "Affected rows is not 2\n");
    }

    Test->set_timeout(30);
    execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #2: %ld  (expeced value is 0)\n", (long) rows);
    if (rows != 0)
    {
        Test->add_result(1, "Affected rows is not 0\n");
    }

    Test->set_timeout(30);
    execute_query_affected_rows(conn_found_rows, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #3: %ld  (expeced value is 2)\n", (long) rows);
    if (rows != 2)
    {
        Test->add_result(1, "Affected rows is not 2\n");
    }

    Test->close_maxscale_connections();

    int rval = Test->global_result;
    delete Test;
    return rval;

}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(10);
    int i;

    Test->repl->connect();
    Test->connect_maxscale();

    Test->tprintf("Trying SHOW VARIABLES to different Maxscale services\n");
    fflush(stdout);
    Test->tprintf("RWSplit\n");
    for (i = 0; i < 100; i++)
    {
        Test->set_timeout(5);
        Test->try_query(Test->conn_rwsplit, (char *) "SHOW VARIABLES;");
    }
    Test->tprintf("ReadConn master\n");
    for (i = 0; i < 100; i++)
    {
        Test->set_timeout(5);
        Test->try_query(Test->conn_master, (char *) "SHOW VARIABLES;");
    }
    Test->tprintf("ReadConn slave\n");
    for (i = 0; i < 100; i++)
    {
        Test->set_timeout(5);
        Test->try_query(Test->conn_slave, (char *) "SHOW VARIABLES;");
    }

    Test->tprintf("All in one loop\n");
    for (i = 0; i < 100; i++)
    {
        Test->set_timeout(5);
        Test->try_query(Test->conn_rwsplit, (char *) "SHOW VARIABLES;");
        Test->try_query(Test->conn_master, (char *) "SHOW VARIABLES;");
        Test->try_query(Test->conn_slave, (char *) "SHOW VARIABLES;");
    }

    Test->set_timeout(10);
    Test->close_maxscale_connections();
    Test->repl->close_connections();

    Test->check_maxscale_alive();

    int rval = Test->global_result;
    delete Test;
    return rval;
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(100);
    Test->repl->connect();

    const int TestConnNum = 100;
    MYSQL *conn[TestConnNum];
    int i;
    int conn_num;

    Test->tprintf("Creating %d connections to ReadConnRouter in 'slave' mode\n", TestConnNum);
    for (i = 0; i < TestConnNum; i++)
    {
        conn[i] = Test->open_readconn_slave_connection();
    }
    Test->tprintf("Waiting 5 seconds\n");
    sleep(5);

    int ConnFloor = floor((float)TestConnNum / (Test->repl->N - 1));
    int ConnCell = ceil((float)TestConnNum / (Test->repl->N - 1));
    int TotalConn = 0;

    Test->tprintf("Checking connections to Master: should be 0\n");
    conn_num = get_conn_num(Test->repl->nodes[0], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test");
    Test->add_result(conn_num, "number of connections to Master is %d\n", conn_num);

    Test->tprintf("Number of connections to each slave should be between %d and %d\n", ConnFloor, ConnCell);
    Test->tprintf("Checking connections to each node\n");
    for (int i = 1; i < Test->repl->N; i++)
    {
        conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test");
        TotalConn += conn_num;
        printf("Connections to node %d (%s):\t%d\n", i, Test->repl->IP[i], conn_num);
        if ((conn_num > ConnCell) || (conn_num < ConnFloor))
        {
            Test->add_result(1, "wrong number of connectiosn to mode %d\n", i);
        }
    }

    Test->tprintf("Total number of connections %d\n", TotalConn);
    if (TotalConn != TestConnNum)
    {
        Test->add_result(1, "total number of connections is wrong\n");
    }

    for (i = 0; i < TestConnNum; i++)
    {
        mysql_close(conn[i]);
    }

    int rval = Test->global_result;
    delete Test;
    return rval;
}
Пример #29
0
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;
    int i;

    Test->read_env();
    Test->print_env();

    Test->connect_maxscale();

    printf("Trying \n");  fflush(stdout);

    char serverid1[1024];
    char serverid2[1024];

    if ( (
             find_field(
                 Test->conn_rwsplit, sel3,
                 "@@server_id", &serverid1[0])
             != 0 ) || (
             find_field(
                 Test->conn_rwsplit, sel4,
                 "@@server_id", &serverid2[0])
             != 0 )) {
        printf("@@server_id field not found!!\n");
        exit(1);
    } else {
        printf("'%s' to RWSplit gave @@server_id %s\n", sel3, serverid1);
        printf("'%s' directly to master gave @@server_id %s\n", sel4, serverid2);
        if (strcmp(serverid1, serverid2) !=0 ) {
            global_result++;
            printf("server_id are different depending in which order terms are in SELECT\n");
        }
    }

    if ( (
             find_field(
                 Test->conn_rwsplit, sel1,
                 "@@hostname", &serverid1[0])
             != 0 ) || (
             find_field(
                 Test->conn_rwsplit, sel2,
                 "@@hostname", &serverid2[0])
             != 0 )) {
        printf("@@hostname field not found!!\n");
        exit(1);
    } else {
        printf("'%s' to RWSplit gave @@hostname %s\n", sel1, serverid1);
        printf("'%s' to RWSplit gave @@hostname %s\n", sel2, serverid2);
        if (strcmp(serverid1, serverid2) !=0 ) {
            global_result++;
            printf("hostname are different depending in which order terms are in SELECT\n");
        }
    }

    Test->close_maxscale_connections();

    global_result += check_maxscale_alive();

    Test->copy_all_logs(); return(global_result);
}
int main(int argc, char *argv[])
{
    TestConnections::skip_maxscale_start(true);
    TestConnections * Test = new TestConnections(argc, argv);
    int local_result;
    char str[4096];
    char sql[4096];
    char pass_file[4096];
    char deny_file[4096];
    char rules_dir[4096];
    FILE* file;

    sprintf(rules_dir, "%s/fw/", test_dir);
    int N = 10;
    int i;

    for (i = 1; i < N + 1; i++)
    {
        Test->set_timeout(180);
        local_result = 0;

        Test->stop_maxscale();

        sprintf(str, "rules%d", i);
        copy_rules(Test, str, rules_dir);

        Test->start_maxscale();
        Test->connect_rwsplit();

        sprintf(pass_file, "%s/fw/pass%d", test_dir, i);
        sprintf(deny_file, "%s/fw/deny%d", test_dir, i);
        Test->tprintf("Pass file: %s\n", pass_file);
        Test->tprintf("Deny file: %s\n", deny_file);

        file = fopen(pass_file, "r");
        if (file != NULL)
        {
            Test->tprintf("********** Trying queries that should be OK ********** \n");
            while (fgets(sql, sizeof(sql), file))
            {
                if (strlen(sql) > 1)
                {
                    Test->tprintf("%s", sql);
                    local_result += execute_query(Test->conn_rwsplit, sql);
                }
            }
            fclose(file);
        }
        else
        {
            Test->add_result(1, "Error opening query file\n");
        }

        file = fopen(deny_file, "r");
        if (file != NULL)
        {
            Test->tprintf("********** Trying queries that should FAIL ********** \n");
            while (fgets(sql, sizeof(sql), file))
            {
                Test->set_timeout(180);
                if (strlen(sql) > 1)
                {
                    Test->tprintf("%s", sql);
                    execute_query(Test->conn_rwsplit, sql);
                    if (mysql_errno(Test->conn_rwsplit) != 1141)
                    {
                        Test->tprintf("Query succeded, but fail expected, errono is %d\n", mysql_errno(Test->conn_rwsplit));
                        local_result++;
                    }
                }
            }
            fclose(file);
        }
        else
        {
            Test->add_result(1, "Error opening query file\n");
        }
        if (local_result != 0)
        {
            Test->add_result(1, "********** rules%d test FAILED\n", i);
        }
        else
        {
            Test->tprintf("********** rules%d test PASSED\n", i);
        }

        mysql_close(Test->conn_rwsplit);
    }

    Test->set_timeout(180);
    Test->stop_maxscale();

    // Test for at_times clause
    Test->tprintf("Trying at_times clause\n");
    copy_rules(Test, (char *) "rules_at_time", rules_dir);

    Test->tprintf("DELETE quries without WHERE clause will be blocked during next 2 minutes\n");
    Test->tprintf("Put time to rules.txt: %s\n", str);
    Test->ssh_maxscale(false, "start_time=`date +%%T`; stop_time=` date --date "
                       "\"now +2 mins\" +%%T`; %s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt",
                       Test->maxscale_access_sudo, Test->maxscale_access_homedir);

    Test->start_maxscale();
    Test->connect_rwsplit();

    Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE\n");
    execute_query(Test->conn_rwsplit, "DELETE FROM t1");
    if (mysql_errno(Test->conn_rwsplit) != 1141)
    {
        Test->add_result(1, "Query succeded, but fail expected, errono is %d\n", mysql_errno(Test->conn_rwsplit));
    }
    Test->tprintf("Waiting 3 minutes and trying 'DELETE FROM t1', expecting OK\n");
    Test->stop_timeout();
    sleep(180);
    Test->set_timeout(180);
    Test->try_query(Test->conn_rwsplit, "DELETE FROM t1");

    mysql_close(Test->conn_rwsplit);
    Test->stop_maxscale();

    Test->tprintf("Trying limit_queries clause\n");
    Test->tprintf("Copying rules to Maxscale machine: %s\n", str);
    copy_rules(Test, (char *) "rules_limit_queries", rules_dir);

    Test->start_maxscale();
    Test->connect_rwsplit();

    printf("Trying 10 quries as fast as possible\n");
    for (i = 0; i < 10; i++)
    {
        Test->add_result(execute_query(Test->conn_rwsplit, "SELECT * FROM t1"), "%d -query failed\n", i);
    }

    Test->tprintf("Expecting failures during next 5 seconds\n");

    time_t start_time_clock = time(NULL);
    timeval t1, t2;
    double elapsedTime;
    gettimeofday(&t1, NULL);


    do
    {
        gettimeofday(&t2, NULL);
        elapsedTime = (t2.tv_sec - t1.tv_sec);
        elapsedTime += (double) (t2.tv_usec - t1.tv_usec) / 1000000.0;
    }
    while ((execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1") != 0) && (elapsedTime < 10));

    Test->tprintf("Quries were blocked during %f (using clock_gettime())\n", elapsedTime);
    Test->tprintf("Quries were blocked during %lu (using time())\n", time(NULL) - start_time_clock);
    if ((elapsedTime > 6) or (elapsedTime < 4))
    {
        Test->add_result(1, "Queries were blocked during wrong time\n");
    }

    Test->set_timeout(180);
    printf("Trying 20 quries, 1 query / second\n");
    for (i = 0; i < 20; i++)
    {
        sleep(1);
        Test->add_result(execute_query(Test->conn_rwsplit, "SELECT * FROM t1"), "query failed\n");
        Test->tprintf("%d ", i);
    }
    Test->tprintf("\n");
    Test->set_timeout(180);
    Test->tprintf("Stopping Maxscale\n");
    Test->stop_maxscale();

    Test->tprintf("Trying rules with syntax error\n");
    Test->tprintf("Copying rules to Maxscale machine: %s\n", str);
    copy_rules(Test, (char *) "rules_syntax_error", rules_dir);

    Test->tprintf("Starting Maxscale\n");
    Test->start_maxscale();
    Test->connect_rwsplit();

    Test->tprintf("Trying to connectt to Maxscale when 'rules' has syntax error, expecting failures\n");
    if (execute_query(Test->conn_rwsplit, "SELECT * FROM t1") == 0)
    {
        Test->add_result(1, "Rule has syntax error, but query OK\n");
    }

    Test->check_maxscale_processes(0);

    int rval = Test->global_result;
    delete Test;
    return rval;
}