Commit 8801c1ab authored by Gábor Szalai's avatar Gábor Szalai
Browse files

Connect timeout added to MySQL



Change-Id: Ib7f533325561a6536a7980f0b1d53a35afb4da6d
Signed-off-by: Gábor Szalai's avatarGabor Szalai <gabor.szalai@ericsson.com>
parent 5c74c06e
This diff is collapsed.
---
Author: Gábor Szalai
Version: 1551-CNL 113 760, Rev. C
Date: 2015-08-17
---
= SQL Test Port for TTCN-3 Toolset with TITAN Description = SQL Test Port for TTCN-3 Toolset with TITAN Description
:author: Gábor Szalai :author: Gábor Szalai
:revnumber: 1551-CNL 113 760, Rev. C :toc: left
:revdate: 2015-08-17
:toc:
== About This Document
=== How to Read This Document
This is the User’s Guide for the SQL test port. The SQL test port is developed for the TTCN-3 Toolset with TITAN. This document is intended to be read together with Function Specification <<_3, [3]>>.
=== Prerequisite Knowledge
The knowledge of the TITAN TTCN-3 Test Executor <<_2, [2]>> and the TTCN-3 language <<_1, [1]>> is essential. Basic knowledge of the SQL is valuable when reading this document.
== System Requirements == System Requirements
...@@ -36,8 +18,6 @@ NOTE: This version of the test port is not compatible with TITAN releases earlie ...@@ -36,8 +18,6 @@ NOTE: This version of the test port is not compatible with TITAN releases earlie
The SQL test port executes SQL statement against the SQL database. The SQL test port is able to handle different SQL engines and databases, and provides a unified interface towards them. The SQL test port executes SQL statement against the SQL database. The SQL test port is able to handle different SQL engines and databases, and provides a unified interface towards them.
= The Test Port
== Overview == Overview
The communication between the SQL test port and the TITAN RTE is done by using the API functions described in <<_2, [2]>>. The SQL test port then transfers the SQL messages to the SUT. The communication between the SQL test port and the TITAN RTE is done by using the API functions described in <<_2, [2]>>. The SQL test port then transfers the SQL messages to the SUT.
...@@ -115,6 +95,9 @@ The name of the character set to use as the default character set. ...@@ -115,6 +95,9 @@ The name of the character set to use as the default character set.
* `auto_reconnect` + * `auto_reconnect` +
Enable or disable automatic reconnection to the server if the connection is found to have been lost. Reconnect has been off by default since MySQL 5.0.3; this option is new in 5.0.13 and provides a way to set reconnection behavior explicitly. Enable or disable automatic reconnection to the server if the connection is found to have been lost. Reconnect has been off by default since MySQL 5.0.3; this option is new in 5.0.13 and provides a way to set reconnection behavior explicitly.
* `connect_timeout` +
The connect timeout in seconds. Default value is 5 seconds.
=== SQLite Connector === SQLite Connector
Provides an interface towards the SQLite database via the SQLite C API. See <<_5, [5]>>. Provides an interface towards the SQLite database via the SQLite C API. See <<_5, [5]>>.
...@@ -373,9 +356,9 @@ The "demo" directory of the deliverable contains the file __SQL_demo.ttcn__. It ...@@ -373,9 +356,9 @@ The "demo" directory of the deliverable contains the file __SQL_demo.ttcn__. It
The __SQL_Parser.ttcn__ shows how to use the rollback feature. The __SQL_Parser.ttcn__ shows how to use the rollback feature.
= Function Specification == Function Specification
== Implementation === Implementation
The SQL Test port consists of two layers: The SQL Test port consists of two layers:
...@@ -385,40 +368,40 @@ Responsible for the common functions of the SQL test port. The common part provi ...@@ -385,40 +368,40 @@ Responsible for the common functions of the SQL test port. The common part provi
* SQL engine connectors: + * SQL engine connectors: +
Provides a connection towards the specific SQL engines. Handles the SQL engine specific functions. Provides a connection towards the specific SQL engines. Handles the SQL engine specific functions.
== Configuration === Configuration
The configuration of the SQL test port is done via the run time ASPs The configuration of the SQL test port is done via the run time ASPs
== Start Procedure === Start Procedure
During the start up of the SQL test port, the SQL engine connectors register their handlers in the common part. During the start up of the SQL test port, the SQL engine connectors register their handlers in the common part.
[[sending-receiving-sql-asps]] [[sending-receiving-sql-asps]]
== Sending/Receiving SQL ASPs === Sending/Receiving SQL ASPs
The common part handles the ASP call from the test suite, and forwards them to the appropriate SQL engine connector. The SQL engine connector connects to the database, executes the SQL query, and send back the result of the query to the common part. The common part converts the result into TTCN-3 data and forwards to the test suite. The common part handles the ASP call from the test suite, and forwards them to the appropriate SQL engine connector. The SQL engine connector connects to the database, executes the SQL query, and send back the result of the query to the common part. The common part converts the result into TTCN-3 data and forwards to the test suite.
=== Closing Down ==== Closing Down
The SQL test port closes down the active SQL connections. The SQL test port closes down the active SQL connections.
=== Logging ==== Logging
The logging printouts will be directed to the RTE log file. The logging printouts will be directed to the RTE log file.
=== Error Handling ==== Error Handling
Erroneous behavior detected during runtime is shown on the console and directed into the RTE log file. The following two types of messages are taken care of: Erroneous behavior detected during runtime is shown on the console and directed into the RTE log file. The following two types of messages are taken care of:
* Errors: information about errors detected is provided. If an error occurs the execution will stop immediately. * Errors: information about errors detected is provided. If an error occurs the execution will stop immediately.
* Warnings: information about warnings detected is provided. The execution continues after the warning is shown. * Warnings: information about warnings detected is provided. The execution continues after the warning is shown.
== Functions and Rollback === Functions and Rollback
In __SQL_Functions.ttcn__ there are some useful functions to use the SQL TestPort. In __SQL_Functions.ttcn__ there are some useful functions to use the SQL TestPort.
[[f-connect]] [[f-connect]]
=== `f_connect` ==== `f_connect`
[source,subs="quotes"] [source,subs="quotes"]
---- ----
...@@ -428,7 +411,7 @@ In __SQL_Functions.ttcn__ there are some useful functions to use the SQL TestPor ...@@ -428,7 +411,7 @@ In __SQL_Functions.ttcn__ there are some useful functions to use the SQL TestPor
Can connect the testport to the connection. Can connect the testport to the connection.
[[f-query]] [[f-query]]
=== `f_query` ==== `f_query`
[source,subs="quotes"] [source,subs="quotes"]
---- ----
...@@ -437,7 +420,7 @@ Can connect the testport to the connection. ...@@ -437,7 +420,7 @@ Can connect the testport to the connection.
Runs the query on the testport with the given connection id. Runs the query on the testport with the given connection id.
[[f-disconnect]] [[f-disconnect]]
=== `f_disconnect` ==== `f_disconnect`
[source,subs="quotes"] [source,subs="quotes"]
---- ----
...@@ -446,7 +429,7 @@ Runs the query on the testport with the given connection id. ...@@ -446,7 +429,7 @@ Runs the query on the testport with the given connection id.
Disconnects the port with the given connection id. Disconnects the port with the given connection id.
[[ef-sql-execute]] [[ef-sql-execute]]
=== `ef_SQL_Execute` ==== `ef_SQL_Execute`
[source,subs="quotes"] [source,subs="quotes"]
---- ----
...@@ -464,7 +447,7 @@ Execute and generate the rollback queries. You have to specify the used tables ...@@ -464,7 +447,7 @@ Execute and generate the rollback queries. You have to specify the used tables
`pl_result_record`- holds the record of the original queries result data. If the statement won’t update, insert or delete anything, it won’t register neither in the result record nor in the result. `pl_result_record`- holds the record of the original queries result data. If the statement won’t update, insert or delete anything, it won’t register neither in the result record nor in the result.
[[f-sql-rollback]] [[f-sql-rollback]]
=== `f_SQL_Rollback` ==== `f_SQL_Rollback`
[source,subs="quotes"] [source,subs="quotes"]
---- ----
...@@ -473,11 +456,11 @@ Execute and generate the rollback queries. You have to specify the used tables ...@@ -473,11 +456,11 @@ Execute and generate the rollback queries. You have to specify the used tables
If you have the rollback queries you can run them with this function. From the last to the first. If you caught an exception while the rollback, in the `pl_queries` the function will return the remaining queries. If it is empty, the rollback was complete. If you have the rollback queries you can run them with this function. From the last to the first. If you caught an exception while the rollback, in the `pl_queries` the function will return the remaining queries. If it is empty, the rollback was complete.
= Error Messages == Error Messages
The following Error messages are generated by the test port. Description is also included if the message is not self-evident. The following Error messages are generated by the test port. Description is also included if the message is not self-evident.
== SQLite Interface === SQLite Interface
`*You have to specify positive max_busy_retries parameter.*` `*You have to specify positive max_busy_retries parameter.*`
...@@ -511,7 +494,7 @@ Only SQLITE_ROW result type can be returned after SQL SELECT. ...@@ -511,7 +494,7 @@ Only SQLITE_ROW result type can be returned after SQL SELECT.
Could not start query. Could not start query.
== MySQL Interface === MySQL Interface
`*ERROR: Can not initialize the MySQL library. The mysql_init returned NULL.*` `*ERROR: Can not initialize the MySQL library. The mysql_init returned NULL.*`
...@@ -535,21 +518,18 @@ The error message is returned by MySQL. See <<_4, [4]>> for details. ...@@ -535,21 +518,18 @@ The error message is returned by MySQL. See <<_4, [4]>> for details.
MySQL can return with other error messages. They can come directly from the MySQL server, so for more details see <<_4, [4]>>. MySQL can return with other error messages. They can come directly from the MySQL server, so for more details see <<_4, [4]>>.
= Warning Messages == Warning Messages
The following Warning Message is generated by the test port. Description is also included if the message is not self-evident. The following Warning Message is generated by the test port. Description is also included if the message is not self-evident.
== SQLite interface === SQLite interface
`*_Database is busy. <repetition_number>. Retry: <query>._*` `*_Database is busy. <repetition_number>. Retry: <query>._*`
When the database is busy the test port retries the operation. By default the test port retries until success. If the `max_busy_retries` parameter is set then the attempts will be limited by this number. When the database is busy the test port retries the operation. By default the test port retries until success. If the `max_busy_retries` parameter is set then the attempts will be limited by this number.
= Terminology
No specific terminology is used.
= Abbreviations == Abbreviations
ASP:: Abstract Service Primitive ASP:: Abstract Service Primitive
...@@ -561,7 +541,7 @@ TTCN-3:: Testing and Test Control Notation version 3 ...@@ -561,7 +541,7 @@ TTCN-3:: Testing and Test Control Notation version 3
SQL:: Structured Query Language SQL:: Structured Query Language
= References == References
[[_1]] [[_1]]
[1] ETSI ES 201 873-1 (2002) + [1] ETSI ES 201 873-1 (2002) +
......
= SQL Test Port for TTCN-3 Toolset with TITAN, Change log
:author: Gábor Szalai
:toc: left
== Changes
=== R6B
Added "connect_timeout" parameter to the MySQL connector
...@@ -74,6 +74,8 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat ...@@ -74,6 +74,8 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat
unsigned long client_flag=0; unsigned long client_flag=0;
const char *char_set=NULL; const char *char_set=NULL;
const char *auto_reconnect=NULL; const char *auto_reconnect=NULL;
unsigned int conn_timeout=5;
log(SQLTP_LOG_DEBUG,"Creating new database connection."); log(SQLTP_LOG_DEBUG,"Creating new database connection.");
if(!mysql_init(&sql_handle)){ if(!mysql_init(&sql_handle)){
...@@ -109,10 +111,13 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat ...@@ -109,10 +111,13 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat
if(!strcasecmp(config_data[i].name,"char_set")){ if(!strcasecmp(config_data[i].name,"char_set")){
mysql_options(&sql_handle, MYSQL_SET_CHARSET_NAME,config_data[i].value ); mysql_options(&sql_handle, MYSQL_SET_CHARSET_NAME,config_data[i].value );
char_set=config_data[i].value; char_set=config_data[i].value;
} } else
if(!strcasecmp(config_data[i].name, "auto_reconnect")) { if(!strcasecmp(config_data[i].name, "auto_reconnect")) {
mysql_options(&sql_handle, MYSQL_OPT_RECONNECT, config_data[i].value); mysql_options(&sql_handle, MYSQL_OPT_RECONNECT, config_data[i].value);
auto_reconnect = config_data[i].value; auto_reconnect = config_data[i].value;
} else
if(!strcasecmp(config_data[i].name, "connect_timeout")){
conn_timeout=atoi(config_data[i].value);
} }
i++; i++;
} }
...@@ -127,6 +132,10 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat ...@@ -127,6 +132,10 @@ int SQL_MySQL_engine::open_database_connection(const SQL_config_data* config_dat
log(SQLTP_LOG_DEBUG,"client_flag: %lu",client_flag); log(SQLTP_LOG_DEBUG,"client_flag: %lu",client_flag);
log(SQLTP_LOG_DEBUG,"char_set: %s",char_set?char_set:"Not specified"); log(SQLTP_LOG_DEBUG,"char_set: %s",char_set?char_set:"Not specified");
log(SQLTP_LOG_DEBUG,"Auto-reconnect: %s", (auto_reconnect) ? auto_reconnect : "Not specified"); log(SQLTP_LOG_DEBUG,"Auto-reconnect: %s", (auto_reconnect) ? auto_reconnect : "Not specified");
log(SQLTP_LOG_DEBUG,"Connect timeout: %u",conn_timeout);
mysql_options(&sql_handle, MYSQL_OPT_CONNECT_TIMEOUT, &conn_timeout);
if(!mysql_real_connect(&sql_handle,host,user,passwd,db,port,unix_socket,client_flag)){ if(!mysql_real_connect(&sql_handle,host,user,passwd,db,port,unix_socket,client_flag)){
err.error_code=4; err.error_code=4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment