0

Lets say, CSV file (abc.csv) contains 10 records of Login credentials(Email, Password), and I want to fetch those values at once using Beanshell script just to make sure that CSV has to get open only once and avoid opening CSV file 10 times for fetching every single record which creates problem of following error:

"Too many open files" in Response data.

Is there any way to do it?

Anonymous
  • 858
  • 4
  • 27
  • 54

2 Answers2

0

You can do that with something like:

import org.apache.jmeter.threads.JMeterContextService;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Hashmap;
import java.util.Map;

File csvFile = new File("/home/yourname/folder/csvFile.csv");
csvData = new Hashmap<String,String>();

csvData = null;

try (Scanner scanner = new Scanner(csvFile)) {
    while (scanner.hasNextLine()) {
        String[] line = scanner.nextLine().split(",");
        csvData.put(line[0],line[1]);
    }
} catch (FileNotFoundException ex) {
    ex.printStackTrace();
}

JMeterContextService.getContext().getVariables().put("csvHashmap", csvData);

This can be done in the beginning, you would open file just once and afterwards use the hash map object stored in memory.

Iske
  • 1,150
  • 9
  • 18
  • But that shows error as: 2016/08/05 16:15:31 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``import org.apache.jmeter.threads.JMeterContextService; import java.io.File; impo . . . '' Encountered "," at line 8, column 17. – Anonymous Aug 05 '16 at 10:48
  • I could see 2 potential problems... Let me make an edit. – Iske Aug 05 '16 at 12:05
  • I have initialized hashtable and replaced diamond operator. – Iske Aug 05 '16 at 12:07
0

I don't think your issue with "too many open files" will be fixed by the workaround you think about.

IMHO, it will just make your test less maintainable and less scalable.

It's a server configuration issue for your account.

You should apply what has been advised to you in question:

Community
  • 1
  • 1
UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116