1. Familiar with the corresponding APIs for calling the tuxedo service in LoadRunner and C ++:
C ++:
Comparison table
|
C ++ |
LoadRunner |
Allocate memory |
Tpalloc () |
Lrt_tpalloc () |
Release memory |
Tpfree () |
Lrt_tpfree () |
Define the sending and receiving buffer |
Fbfr32 * |
Fbfr32 * |
Buffer Initialization |
Finit32 () |
Lrt_finitialize32 () |
Add a variable to the buffer |
Fadd32 () |
Lrt_fadd32_fld () |
Get the variables in the buffer |
Fget32 () |
Lrt_save32_fld_val () |
Call tuxedo Service |
Tpcall () |
Lrt_tpcall () |
These functions are mainly used. In addition, transaction statistics should be inserted before and after tacall to count the performance during interaction with Tuxedo:
Lr_start_transaction ()
Lrt_tpcall ()
Lr_end_transaction ()
2. Notes
It should be noted that the relevant function parameters in LR are not the same as those in C ++. Therefore, you must follow the syntax rules of LR:
A. Variable Declaration
All variable declarations in LR are placed in replay. VDF;
B. Passing Parameters
In C ++:
# Define fcckey (fldid32) 167776166)
Fadd32 (sndbuf, fcckey, (char *) Key, (fldlen32) 0)
LR:
Lrt_fadd32_fld (sndbuf, "id = 167776166", (char *) Key, lrt_end_of_parms );
"Id =" must be added to the incoming identifier ";
Similarly, the value must be added to the input key:
Char key [30];
Strcpy (key, "value = hellocolin ^ ");
C. Take the Parameter
In C ++:
Int resind;
Fget32 (fbfr32 *) rcvbuf, f_result_ind, OC, (char *) & resind, & maxlen );
Cout <resind;
LR:
Int resind:
Lrt_save32_fld_val (fbfr32 *) rcvbuf, "id = 5032", 0, "resind ");
Lr_output_message ("Return Value: ° % d", resind );
From the comparison, we can see that in LR, the parameter name is passed in the form of a string, and the parameter name is used internally to find and match the type, and then the corresponding data is filled;
After getting familiar with the above points, it is basically no problem to compile the LR test script of tuxedo.
Enclose a LR script for your reference:
// Replay. VDF -----------------------------------------
# Ifndef tuxvdf_h # define tuxvdf_h # definefcckey (fldid32) 167776166) fbfr32 * sndbuf; // char * sndbuf; fbfr32 * rcvbuf; char * data_2; char * data_3; char key [61]; char dataresult [513]; int Len; int resind; fldocc OC;
// Action. c -------------------------------------------------
# Include "LRT. H "# include" replay. VDF "Action () {lrt_abort_on_error (); // sndbuf = lrt_tpalloc (" string "," ", 512); Len = 65000; strcpy (key, "value = hellocolin ^"); lrt_finitialize32 (sndbuf); lrt_fadd32_fld (sndbuf, "id = 167776166", (char *) Key, lrt_end_of_parms ); /* request string buffer 1 * // lrt_strcpy (sndbuf, sbuf_1); // rcvbuf = lrt_tpalloc ("string", "", 10000000); lr_start_transaction ("colinlau "); tpresult_int = lrt_tpcall ("cc_q_1", (char *) sndbuf, 0, (char **) & rcvbuf, & olen, 0 ); /* reply string buffer 1 */If (tpresult_int =-1) {lr_end_transaction ("colinlau", lr_fail); lr_output_message ("tpquery: tpcall error"); Return 0 ;} lr_end_transaction ("classcache", lr_pass); lrt_save32_fld_val (fbfr32 *) rcvbuf, "id = 5032", 0, "resind"); lr_output_message ("results: % d ", resind); lrt_save32_fld_val (fbfr32 *) rcvbuf, "id = 167776167", 0, "dataresult"); lr_output_message ("Return Value :", lr_eval_string ("{dataresult}"); // ("{dataresult}") lrt_abort_on_error (); Return 0 ;}
Note: InCodeDuring the compilation process, you need to apply for and release the memory in vuser_init and vuser_end; otherwise, the test results will be greatly affected!
Vuser_init ---------------
# Include "LRT. H "# include" replay. VDF "vuser_init () {lrt_set_env_list (env_allow_array); Round (" wsnaddr = // 10.6.36.103: 10115 ");/* old format: round (" wsnaddr = slow "); */lr_think_time (5); tpresult_int = lrt_tpinitialize (bytes); If (sndbuf = (fbfr32 *) lrt_tpalloc (char *) "fml32", null, Len )) = NULL) {lr_output_message ("tpquery: tpalloc error"); Return 0;} If (rcvbuf = (fbfr32 *) lrt_tpalloc (char *) "fml32", null, len) = NULL) {lr_output_message ("tpquery: tpalloc error"); Return 0 ;}return 0 ;}
Vuser_end ---------------------------------
Vuser_end () {lrt_tpfree (char *) sndbuf); lrt_tpfree (char *) rcvbuf); lrt_tpterm (); Return 0 ;}
Over .!
More: Http://blog.donews.com/me1105/archive/2011/04/01/140.aspx