0

Further to this question Unable to print the individually reporting status using Label of JSR223 Sampler in HTML Dashboard Report of JMeter. I am executing a test plan on the server where I have moved files from source to destination folder.

   Below is the destination folder hierarchy: 
  1. /sourceFolder/filesThatNeedToBeMoved to /destinationFolder/Input/

  2. /destinationFolder/Input/FilesThatAreMovedByMEfromSourceFolder

  3. /destinationFolder/Output/FilesThatAreMovedAutomaticallyFromInputTOOutputByServer

    On the server-side, The destination folder has two subfolders i.e. INPUT and OUTPUT, when files are moved or copy in the destination folder INPUT then those files get automatically deleted by the server and moves to the destination folder OUTPUT. I just want to calculate the time of processing of files that are moved from INPUT to OUTPUT folder automatically by the server.

How Can I achieve this using Jmeter? Below I have shared my groovy script where I have written logic for moving the files from source to destination folder INPUT. And unable to calculate the time between INPUT To OUTPUT folder.

Can we run the script until the specific files get deleted from the INPUT folder or not?

import org.apache.jmeter.services.FileServer
log.info("############################################################# START #############################################################");

def SOURCE = vars.get('source');
log.info("SOURCE IS : " + SOURCE);
def DESTINATION = vars.get('destination');
def DATA = vars.get('data');
def SMS = vars.get('sms');
def VOICE = vars.get('voice');

def baseDestinationFolder = new String(DESTINATION);

log.info(baseDestinationFolder); 
def dataDestFolder = baseDestinationFolder + DATA;
def SMSDestFolder = baseDestinationFolder + SMS;
def VoiceDestFolder = baseDestinationFolder + VOICE;
log.info("dataDestFolder : " + dataDestFolder);
log.info("SMSDestFolder : "+SMSDestFolder);
log.info("VoiceDestFolder : " + VoiceDestFolder);

File sourceFolder = new File(SOURCE); 
log.info("******* SOURCE FOLDER IS ******** : " + sourceFolder);
File[] datafiles = sourceFolder.listFiles();     


for (File inputFile : datafiles){
        def fileName = "" + inputFile.getName();
        log.info("fileName : " + fileName);
        def finalPath;
        if(fileName.contains("data")){
            SampleResult.setSampleLabel("Source: " + SOURCE + "::" + "Destination: " +  DESTINATION + DATA);
            log.info( "The Sample Label is : " + SampleResult.getSampleLabel() );
            finalPath = dataDestFolder + fileName;
        }else if(fileName.contains("voice")){
            SampleResult.setSampleLabel("Source: " + SOURCE + "::" + "Destination: " +  DESTINATION + VOICE);
            log.info( "The Sample Label is : " + SampleResult.getSampleLabel() );
            finalPath = VoiceDestFolder + fileName;
        }else if(fileName.contains("sms")){
            SampleResult.setSampleLabel("Source: " + SOURCE + "::" + "Destination: " +  DESTINATION + SMS);
            log.info( "The Sample Label is : " + SampleResult.getSampleLabel() );
            finalPath = SMSDestFolder + fileName;
        }

        log.info("finalPath is : " + finalPath);
        def newFile = new File(finalPath);
        newFile << inputFile.text
    }


log.info("############################################################# END #############################################################");

1 Answer 1

1

If you need to check only the file processing time by your server and report it, you can measure this time using JSR223 PostProcessor like:

def start = System.currentTimeMillis()
while (!new File('/destinationFolder/Output/').list().toList().containsAll('file1', 'file2', 'file3')) {
    sleep(100)
}
def end = System.currentTimeMillis()
prev.time = (end - start)

it will wait until all files you expect to be under /destinationFolder/Output/ will appear there and then update the parent JSR223 Sampler execution time with the server processing time

More information: The Groovy Templates Cheat Sheet for JMeter

2
  • If I move 100 files, then I have to send 100 files like this or is there any way to send simply a list object in .containsAll().method. And, Can I use direct JSR223 sampler variables in JSR223 post processor?
    – Rajan
    Commented May 25, 2020 at 17:35
  • Hi Dmitri, I just want the processing time by my server. I don't want to add the processing time to the prev.time. So how can we remove the previous time response and add only the file processing time to it?
    – Rajan
    Commented May 27, 2020 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.