Category: 4. Software Design/Architecture/testing 2010-01-08 17:48 5635 people read reviews (3) favorite reports Loadrunnermysql script Database SQL Server Test
Recently did a few weeks of loadrunner test, have some experience, recorded, in order to find later.
The LoadRunner test database is a simulated client to connect to the database server, and therefore requires protocol (or driver support). The LoadRunner itself directly supports Oracle, SQL Server databases, which can record scripts directly from the two databases by selecting the appropriate protocol. The MySQL database can only use the ODBC Protocol to record (write) the script, so you have to MySQL ODBC driver, and ODBC-enabled Query Analyzer (recording scripts need to write their own do not need).
1, first to install the MySQL ODBC driver, MyODBC 3.51.11 WIN.
2. Open "Data source ODBC" from "Control Panel" if not found (not found on my computer). To the desktop, create a new shortcut to the target location:%systemroot%/system32/odbcad32.exe.
3, open the ODBC management program, add the driver for "MySQL ODBC 3.51 Driver", and then fill in some IP, user name, password and so on, test it. (This step is not necessary, if you write a connection string, you do not need, if you want to use the DNS database name, it is necessary)
4, install a Query Analyzer, this Query Analyzer must be supported by ODBC (this is necessary, otherwise not recorded), this is very difficult to find. I looked for one, not good enough, called "Universal Database Query Analyzer." Http://www.onlinedown.net/soft/31366.htm.
5, Start loadrunner,create scripts;application type select Win32 applications;program record Select the 4th step of the Query Analyzer location, remember the Query Analyzer select "ODBC", Before you can record it, it's OK to run it.
6, Run Load tests, if the failure, see if license support, with GLOBAL-100 license on it.
The recorded script was miserable (and smelly and long), so I tried to manually write a simple one, each line has comments, if you want to advanced, please refer to LoadRunner's help documentation.
[CPP]View Plaincopy
- #include "Lrd.h"
- Action ()
- {
- Static Lrd_init_info Initinfo = {Lrd_init_info_eyecat};
- Static lrd_default_db_version dbtypeversion[] =
- {
- {LRD_DBTYPE_ODBC, lrd_dbversion_odbc_30},
- {Lrd_dbtype_none, Lrd_dbversion_none}
- };
- Static Lrd_context FAR * CTX1;
- Static lrd_connection FAR * CON1;
- Static Lrd_cursor FAR * CSR1;
- The above defined code is defined in Vdf.h if the script is recorded, and there are some other files
- If you have a handwritten script, you need to add it manually, mostly by defining variables
- Number of rows queried
- unsigned long count=0;
- Initial
- Lrd_init (&initinfo, dbtypeversion);
- Open context
- Lrd_open_context (&ctx1, LRD_DBTYPE_ODBC, 0, 0, 0);
- Request a connected memory
- Lrd_alloc_connection (&con1, Lrd_dbtype_odbc, Ctx1, 0 /*unused*/, 0);
- Open the connection, note that the driver is installed above
- Lrd_open_connection (&con1, Lrd_dbtype_odbc, "", "", "" , " driver=mysql ODBC 3.51 DRIVER; Uid=root; pwd=123456; Server=192.168.1.99;database=testdb ", Ctx1, 1, 0);
- Open cursor
- Lrd_open_cursor (&CSR1, Con1, 0);
- SQL statement, note that 1 means to execute immediately
- Lrd_stmt (CSR1, "select Column1 from table1 where colum1 = 1",-1, 1, 0 /*none*/, 0);
- Counting rows to the count variable
- Lrd_row_count (CSR1, &count, 0);
- Print messages
- Lr_message ("count=%d", count);
- Close the cursor first
- Lrd_close_cursor (&CSR1, 0);
- Close the connection again
- Lrd_close_connection (&con1, 0, 0);
- Release the connection, and echo the alloc, otherwise there is a memory leak
- Lrd_free_connection (&con1, 0 /*unused*/, 0);
- Close the context again
- Lrd_close_context (&ctx1, 0, 0);
- Finished, return 0
- return 0;
- }
Finish it, run it yourself. You can view the log as follows:
------------------------------------------------------------------------------
Starting Iteration 1.
Starting action action.
ACTION.C (8): lrd_open_connection:user= "", server= ""
ACTION.C (one): Lrd_stmt:select column1 from table1 where colum1 = 1;
Count= 1
ACTION.C (+): lrd_close_connection:user= "", server= ""
Ending action action.
------------------------------------------------------------------------------
Count = 1 indicates that the query succeeded
==========================================================================
LoadRunner using ODBC to write MySQL scripts