mirror of https://github.com/sysown/proxysql
Merge pull request #3499 from sysown/v2.x-codecov1
[WIP] code cleanup and improved code coveragev2.x-cluster_large_mysql_users
commit
5ede60ec9f
@ -0,0 +1,94 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
/* this test:
|
||||
* enables mysql-have_ssl
|
||||
* retrieves all tables in the most important schemas
|
||||
* for each table, it connects with SSL *and* compression, then retrieves all rows
|
||||
*/
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
|
||||
|
||||
std::vector<std::string> tables;
|
||||
std::vector<std::string> schemas = { "main", "stats", "disk", "monitor" };
|
||||
for (std::vector<std::string>::iterator s = schemas.begin(); s != schemas.end(); s++) {
|
||||
std::string q = "SHOW TABLES FROM " + *s;
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
std::string table1(row[0]);
|
||||
table1 = *s + "." + table1;
|
||||
tables.push_back(table1);
|
||||
std::string table2(row[0]);
|
||||
table2 = "`" + *s + "`.`" + table2 + "`";
|
||||
tables.push_back(table2);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
mysql_close(proxysql_admin);
|
||||
plan(tables.size() + 1);
|
||||
ok(tables.size() > 40 , "Number of tables to check: %ld" , tables.size());
|
||||
|
||||
|
||||
proxysql_admin = mysql_init(NULL); // redefined locally
|
||||
mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
const char * c = mysql_get_ssl_cipher(proxysql_admin);
|
||||
for (std::vector<std::string>::iterator it = tables.begin(); it != tables.end(); it++) {
|
||||
std::string q = "SHOW CREATE TABLE " + *it;
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
unsigned long rows = proxy_res->row_count;
|
||||
ok(c != NULL && proxysql_admin->net.compress == 1 && rows==1, "cipher %s and compression (%d) used while reading %lu row(s) from %s", c, proxysql_admin->net.compress, rows, it->c_str());
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
diag(row[1]);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
mysql_close(proxysql_admin);
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
/* this test:
|
||||
* enables mysql-have_ssl
|
||||
* retrieves all tables in the most important schemas
|
||||
*/
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
|
||||
|
||||
std::vector<std::string> tables;
|
||||
std::string q = "SHOW TABLES";
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
std::string table(row[0]);
|
||||
tables.push_back(table);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
mysql_close(proxysql_admin);
|
||||
std::vector<const char *> queries = {
|
||||
"show fields from `%s`",
|
||||
"ShOw fields FrOm `%s`",
|
||||
"show fields from %s",
|
||||
"ShOw fields FrOm %s",
|
||||
};
|
||||
plan(tables.size()*queries.size());
|
||||
|
||||
|
||||
for (std::vector<std::string>::iterator it = tables.begin(); it != tables.end(); it++) {
|
||||
MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally
|
||||
mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
char *query = (char *) malloc(strlen(queries[0]) + it->length() + 8);
|
||||
for (std::vector<const char *>::iterator it2 = queries.begin(); it2 != queries.end(); it2++) {
|
||||
sprintf(query,*it2, it->c_str());
|
||||
MYSQL_QUERY(proxysql_admin, query);
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
unsigned long rows = proxy_res->row_count;
|
||||
ok(rows > 0 , "Number of rows in %s = %d", it->c_str(), rows);
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
free(query);
|
||||
mysql_close(proxysql_admin);
|
||||
}
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
/* this test:
|
||||
* enables mysql-have_ssl
|
||||
* retrieves all tables in the most important schemas
|
||||
*/
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
|
||||
|
||||
std::vector<std::string> tables;
|
||||
std::string q = "SHOW TABLES";
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
std::string table(row[0]);
|
||||
tables.push_back(table);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
mysql_close(proxysql_admin);
|
||||
std::vector<const char *> queries = {
|
||||
"show table status like '%s'",
|
||||
"show TABLE status like '%s'",
|
||||
"SHOW table status like '%s'",
|
||||
"show TABLE status LIKE '%s'",
|
||||
};
|
||||
plan(tables.size()*queries.size());
|
||||
|
||||
|
||||
for (std::vector<std::string>::iterator it = tables.begin(); it != tables.end(); it++) {
|
||||
MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally
|
||||
mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
char *query = (char *) malloc(strlen(queries[0]) + it->length() + 8);
|
||||
for (std::vector<const char *>::iterator it2 = queries.begin(); it2 != queries.end(); it2++) {
|
||||
sprintf(query,*it2, it->c_str());
|
||||
MYSQL_QUERY(proxysql_admin, query);
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
unsigned long rows = proxy_res->row_count;
|
||||
ok(rows = 1 , "SHOW TABLE STATUS %s generated %lu row(s)", it->c_str(), rows);
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
free(query);
|
||||
mysql_close(proxysql_admin);
|
||||
}
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
/* this test:
|
||||
* enables mysql-have_ssl
|
||||
* retrieves all tables in the most important schemas
|
||||
*/
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
|
||||
|
||||
std::vector<std::string> tables;
|
||||
std::string q = "SHOW TABLES";
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
std::string table(row[0]);
|
||||
tables.push_back(table);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
mysql_close(proxysql_admin);
|
||||
std::vector<std::pair<int, const char *>> queries = { // number of rows + query
|
||||
{ 1 , "SELECT version()" },
|
||||
{ 1 , "select VERSION()" },
|
||||
{ 4 , "SHOW VARIABLES WHERE Variable_name in ('max_allowed_packet','system_time_zone','time_zone','sql_mode')" },
|
||||
{ 4 , "SHOW VARIABLES WHERE Variable_name in ('max_allowed_packet','system_time_zone','time_zone','auto_increment_increment')" },
|
||||
{ 1 , "select @@version_comment limit 1" },
|
||||
{ 1 , "select DATABASE(), USER() limit 1" },
|
||||
{ 1 , "SELECT DATABASE(), USER() LIMIT 1" },
|
||||
{ 1 , "select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1" },
|
||||
{ 1 , "select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database LIMIT 1" },
|
||||
{ 1 , "SHOW GLOBAL VARIABLES LIKE 'version'" },
|
||||
{ 40 , "SHOW CHARSET" },
|
||||
{ 200 , "SHOW COLLATION" },
|
||||
{ 1 , "show GLOBAL VARIABLES LIKE 'version'" },
|
||||
{ 40 , "show CHARSET" },
|
||||
{ 200 , "show COLLATION" },
|
||||
{ 1 , "SHOW mysql USERS" },
|
||||
{ 1 , "show MYSQL servers" },
|
||||
{ 1 , "SHOW global VARIABLES" },
|
||||
{ 1 , "show VARIABLES" },
|
||||
{ 1 , "show ALL variables" },
|
||||
{ 1 , "show MYSQL variables" },
|
||||
{ 1 , "SHOW admin VARIABLES" },
|
||||
{ 3 , "sHoW DATABASES" },
|
||||
{ 3 , "sHoW SCHEMAS" },
|
||||
/*
|
||||
{ , "" },
|
||||
{ , "" },
|
||||
{ , "" },
|
||||
*/
|
||||
};
|
||||
plan(1+queries.size());
|
||||
|
||||
|
||||
proxysql_admin = mysql_init(NULL);
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
const char * c = mysql_get_ssl_cipher(proxysql_admin);
|
||||
ok(c != NULL && proxysql_admin->net.compress == 1, "cipher %s and compression (%d) used", c, proxysql_admin->net.compress);
|
||||
for (std::vector<std::pair<int, const char *>>::iterator it2 = queries.begin(); it2 != queries.end(); it2++) {
|
||||
MYSQL_QUERY(proxysql_admin, it2->second);
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
unsigned long rows = proxy_res->row_count;
|
||||
ok(rows >= it2->first , "Number of rows: %lu . Minimum expected %d for command: %s", rows, it2->first, it2->second);
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
mysql_close(proxysql_admin);
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
struct memory {
|
||||
char *response;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static size_t cb(void *data, size_t size, size_t nmemb, void *userp) {
|
||||
size_t realsize = size * nmemb;
|
||||
struct memory *mem = (struct memory *)userp;
|
||||
|
||||
char *ptr = (char *)realloc((void *)mem->response, mem->size + realsize + 1);
|
||||
if(ptr == NULL)
|
||||
return 0; /* out of memory! */
|
||||
|
||||
mem->response = ptr;
|
||||
memcpy(&(mem->response[mem->size]), data, realsize);
|
||||
mem->size += realsize;
|
||||
mem->response[mem->size] = 0;
|
||||
|
||||
return realsize;
|
||||
}
|
||||
|
||||
|
||||
void run_request(const char *url) {
|
||||
struct memory chunk;
|
||||
chunk.response = NULL;
|
||||
chunk.size = 0;
|
||||
|
||||
CURL *curl_handle;
|
||||
char errbuf[CURL_ERROR_SIZE];
|
||||
unsigned int ret = 0;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, cb);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, "stats:stats");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errbuf);
|
||||
|
||||
CURLcode res1;
|
||||
res1 = curl_easy_perform(curl_handle);
|
||||
if(res1 == CURLE_OK) {
|
||||
long response_code;
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &response_code);
|
||||
ok(response_code==200,"Response code: %ld for %s", response_code, url);
|
||||
} else {
|
||||
size_t len = strlen(errbuf);
|
||||
diag("libcurl: (%d) ", res1);
|
||||
if(len)
|
||||
diag("%s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
|
||||
else
|
||||
diag("%s", curl_easy_strerror(res1));
|
||||
ok(0,"Failure for %s", url);
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
}
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
plan(4);
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET admin-web_enabled='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET admin-web_port=6080");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD ADMIN VARIABLES TO RUNTIME");
|
||||
|
||||
run_request("https://127.0.0.1:6080");
|
||||
run_request("https://127.0.0.1:6080/stats?metric=system");
|
||||
run_request("https://127.0.0.1:6080/stats?metric=mysql");
|
||||
run_request("https://127.0.0.1:6080/stats?metric=cache");
|
||||
return exit_status();
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <mysql.h>
|
||||
#include <mysql/mysqld_error.h>
|
||||
|
||||
#include "tap.h"
|
||||
#include "command_line.h"
|
||||
#include "utils.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
/* this test:
|
||||
* enables mysql-have_ssl
|
||||
* retrieves all tables in the most important schemas
|
||||
* for each table, it connects with SSL *and* compression, then retrieves all rows
|
||||
*/
|
||||
|
||||
int main() {
|
||||
CommandLine cl;
|
||||
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get the required environmental variables.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
MYSQL* proxysql_admin = mysql_init(NULL);
|
||||
// Initialize connections
|
||||
if (!proxysql_admin) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "SET mysql-have_compress='true'");
|
||||
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
|
||||
|
||||
std::vector<std::string> tables;
|
||||
std::vector<std::string> schemas = { "main", "stats", "disk", "monitor" };
|
||||
for (std::vector<std::string>::iterator s = schemas.begin(); s != schemas.end(); s++) {
|
||||
std::string q = "SHOW TABLES FROM " + *s;
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
MYSQL_ROW row;
|
||||
while ((row = mysql_fetch_row(proxy_res))) {
|
||||
std::string table(row[0]);
|
||||
table = *s + "." + table;
|
||||
tables.push_back(table);
|
||||
}
|
||||
mysql_free_result(proxy_res);
|
||||
}
|
||||
mysql_close(proxysql_admin);
|
||||
plan(tables.size());
|
||||
|
||||
|
||||
for (std::vector<std::string>::iterator it = tables.begin(); it != tables.end(); it++) {
|
||||
MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally
|
||||
mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) {
|
||||
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
|
||||
return -1;
|
||||
}
|
||||
const char * c = mysql_get_ssl_cipher(proxysql_admin);
|
||||
std::string q = "SELECT * FROM " + *it;
|
||||
MYSQL_QUERY(proxysql_admin, q.c_str());
|
||||
MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin);
|
||||
unsigned long rows = proxy_res->row_count;
|
||||
mysql_free_result(proxy_res);
|
||||
ok(c != NULL && proxysql_admin->net.compress == 1, "cipher %s and compression (%d) used while reading %lu from table %s", c, proxysql_admin->net.compress, rows, it->c_str());
|
||||
mysql_close(proxysql_admin);
|
||||
}
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
Loading…
Reference in new issue