by Chaitanya Bhatt
LoadRunner: A thread-safe duplicate file creator function which also automatically assigns unique names to files
Note:
1.Make sure you copy the upload file into your script folder by right clicking on the action pane and pressing the “Add files to script” option
2.Adding a file to script makes sure that your file automatically gets copied to the LoadGenerators during load test execution.
3.After the load test completes – ensure to cleanup your %TEMP% folders as several duplicate files may be created during test execution.
4.I have used randAlphaNumrGenerator.h which hosts a helper function to create random alphanumeric codes which can be used as names for duplicate files.
5.I have also used strLastOccr() function which I explained in my previous post. In the current context I have used it to extract the extension of the file.
6.In the below example I have added dataFile.xlsx into my script folder using the “Add files to script” option. This is the file I intend to duplicate during execution.
Function call sample:
char fileName[20]="dataFile.xlsx"; fileDuplication(fileName); return 0;
Global Declaration:
#ifndef _GLOBALS_H #define _GLOBALS_H //-------------------------------------------------------------------- // Include Files #include "lrun.h" #include "web_api.h" #include "lrw_custom_body.h" #include "randAlphaNumrGenerator.h" #define DIR_LEN 512 #define BUFFER_SIZE 10240 // 10 KB //-------------------------------------------------------------------- // Global Variables #endif // _GLOBALS_H
The duplicate file creator function
int fileDuplication(char *fileToDuplicate)
{
long fp, count;
int id, scid;
char filename[1024];
char cmdPWD[1024];
char cmdCopy[2024] ;
char buffer[BUFFER_SIZE];
char original_dir[DIR_LEN];
char *vuser_group;
lr_output_message("Actual Filename with Extension = \"%s\"",
fileToDuplicate);
strLastOccr(fileToDuplicate, "fileExtension", ".");
lr_output_message("File Extension= %s",
lr_eval_string("{fileExtension}"));
lr_whoami(&id, &vuser_group, &scid);
alphNumGen("randFilename");
lr_output_message("%s",getcwd (original_dir, DIR_LEN));
sprintf(cmdPWD, "cd %s", original_dir);
lr_output_message("%s",cmdPWD); //Present Working Directory
system(cmdPWD);
sprintf(cmdCopy, "copy %s.%s %s.%s",fileToDuplicate,lr_eval_string("{fileExtension}"), lr_eval_string("{randFilename}"), lr_eval_string("{fileExtension}"));
lr_output_message("cmdCopy = %s", cmdCopy);
fp = popen(cmdCopy, "r");
if (fp == NULL) {
lr_error_message("Error opening stream.");
return -1;
}
count = fread(buffer, sizeof(char), BUFFER_SIZE, fp); // read up to 10KB
if (feof(fp) == 0) {
lr_error_message("Couldn't reach end of stream. Try increasing BUFFER_SIZE.");
return -1;
}
if (ferror(fp)) {
lr_error_message ("Error during read operation.");
return -1;
}
buffer[count] = NULL;
lr_output_message("Copy Status for Vuser-%d is %s. FileName=%s.%s", id, buffer,lr_eval_string("{randFilename}"),lr_eval_string("{fileExtension}"));
pclose(fp);
return 0;
}
Output:
Running Vuser... Starting iteration 1. Starting action Action. globals.h(61): Actual Filename with Extension = "dataFile.xlsx" globals.h(66): File Extension= xlsx Max: 1 globals.h(74): Z:\temp\FUS\noname68 globals.h(76): cd Z:\temp\FUS\noname68 globals.h(79): cmdCopy = copy dataFile.xlsx n25579.xlsx globals.h(99): Copy Status for Vuser--1 is 1 file(s) copied. . FileName=n25579.xlsx Ending action Action. Ending iteration 1. Starting iteration 2. Starting action Action. globals.h(61): Actual Filename with Extension = "dataFile.xlsx" globals.h(66): File Extension= xlsx Max: 1 globals.h(74): Z:\temp\FUS\noname68 globals.h(76): cd Z:\temp\FUS\noname68 globals.h(79): cmdCopy = copy dataFile.xlsx X25459.xlsx globals.h(99): Copy Status for Vuser--1 is 1 file(s) copied. . FileName=X25459.xlsx Ending action Action. Ending iteration 2. Ending Vuser...
No comments yet.
- Dosimeter
- ch products fighterstick usb
- cosmetic dentist palm beach
- Top Penny Stocks
- Wholesale
- papel
- Boston estate planning attorney
- Boston estate planning lawyer
- Massachusetts probate lawyer
- Boston, MA elder law
- kullan hinta
- raha
- revimax
- Texas Insurance Services
- Boston, MA elder law
- Massachusetts probate attorney
- TX Insurance
- tarot meaning
- HYIP MONITOR
- Lopare
- Directory
- dentist palm beach gardens
- gatsby wax
- How to keep fit
- jeep dealer
- make money sharing music
- download free music
- benchtops auckland
- organize laundry room
- clothing wholesale
- http://www.echelletelescopique.org/
- Cudo
- solar panels uk
- classifieds
- Feather hair extensions
- facebook marketing
- Mens leather jackets
- Gifts for grandma
