Merge branch 'testconnect' into develop
This commit is contained in:
@ -16,3 +16,6 @@ install(TARGETS cli DESTINATION modules)
|
||||
|
||||
add_subdirectory(readwritesplit)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
@ -1,2 +1,3 @@
|
||||
add_test(NAME ReadWriteSplitTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit.sh testrwsplit.log ${TEST_HOST} ${TEST_PORT_RW} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_test(NAME ReadWriteSplitLoginTest COMMAND $<TARGET_FILE:testconnect> 10000 ${TEST_HOST} ${MASTER_PORT} ${TEST_HOST} ${TEST_PORT_RW})
|
||||
add_subdirectory(test_hints)
|
3
server/modules/routing/test/CMakeLists.txt
Normal file
3
server/modules/routing/test/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_executable(testconnect testconnect.c)
|
||||
target_link_libraries(testconnect mysql)
|
||||
add_test(NAME ReadConnRouterLoginTest COMMAND $<TARGET_FILE:testconnect> 10000 ${TEST_HOST} ${MASTER_PORT} ${TEST_HOST} ${TEST_PORT})
|
79
server/modules/routing/test/testconnect.c
Normal file
79
server/modules/routing/test/testconnect.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <my_config.h>
|
||||
#include <mysql.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
MYSQL* server;
|
||||
char *host;
|
||||
unsigned int port;
|
||||
int rval, iterations,i;
|
||||
clock_t begin,end;
|
||||
double baseline,test;
|
||||
|
||||
if(argc < 6){
|
||||
fprintf(stderr,"Usage: %s <iterations> <baseline host> <baseline port> <test host> <test port>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
iterations = atoi(argv[1]);
|
||||
host = strdup(argv[2]);
|
||||
port = atoi(argv[3]);
|
||||
rval = 0;
|
||||
|
||||
/**Testing direct connection to master*/
|
||||
|
||||
printf("Connecting to MySQL server through %s:%d.\n",host,port);
|
||||
begin = clock();
|
||||
|
||||
for(i = 0;i<iterations;i++)
|
||||
{
|
||||
if((server = mysql_init(NULL)) == NULL){
|
||||
return 1;
|
||||
}
|
||||
if(mysql_real_connect(server,host,"maxuser","maxpwd",NULL,port,NULL,0) == NULL){
|
||||
fprintf(stderr, "Failed to connect to database: Error: %s\n",
|
||||
mysql_error(server));
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
mysql_close(server);
|
||||
}
|
||||
|
||||
end = clock();
|
||||
baseline = (double)(end - begin)/CLOCKS_PER_SEC;
|
||||
|
||||
free(host);
|
||||
host = strdup(argv[4]);
|
||||
port = atoi(argv[5]);
|
||||
|
||||
/**Testing connection to master through MaxScale*/
|
||||
|
||||
printf("Connecting to MySQL server through %s:%d.\n",host,port);
|
||||
begin = clock();
|
||||
|
||||
for(i = 0;i<iterations;i++)
|
||||
{
|
||||
if((server = mysql_init(NULL)) == NULL){
|
||||
return 1;
|
||||
}
|
||||
if(mysql_real_connect(server,host,"maxuser","maxpwd",NULL,port,NULL,0) == NULL){
|
||||
rval = 1;
|
||||
fprintf(stderr, "Failed to connect to database: Error: %s\n",
|
||||
mysql_error(server));
|
||||
break;
|
||||
}
|
||||
mysql_close(server);
|
||||
}
|
||||
|
||||
end = clock();
|
||||
test = (double)(end - begin)/CLOCKS_PER_SEC;
|
||||
|
||||
printf("CPU time used in seconds:\nDirect connection: %f\nThrough MaxScale: %f\n",baseline,test);
|
||||
|
||||
free(host);
|
||||
return rval;
|
||||
}
|
Reference in New Issue
Block a user