0
votes

What I try to do:

I build a java service that load a testplan and run that one. I'm not using any Bash scripts and jmeter GUI. The java App is built as a service so that can run in the cloud. The Idea is, just to create some diameter Traffic data.

When I run the src on intellij (locally), all works fine.

Starting the app, all OK.

java -jar -Dserver.port=8090 diameter-service-0.0.1-SNAPSHOT.jar

Run REST request:

localhost:8090/api/v1/encode

after the request I get following error:

java.io.FileNotFoundException: file:/Users/myuser/Downloads/diameter-service-0.0.1-SNAPSHOT.jar!/jmeter/bin/saveservice.properties (No such file or directory)

The first thing what I checked was jMeter Home. system out on console:

HOME: file:/Users/myuser/Downloads/diameter-service-0.0.1-SNAPSHOT.jar!/jmeter

The files are also available and located under bin, and slo in the class path.

/src/main/resources/jmeter/bin/saveservice.properties
/src/main/resources/jmeter/bin/jmeter.properties
/src/main/resources/jmeter/bin/user.properties

I think the jMeter Home path is OK. ..or is that a wrong presumption? Way jMeter can not load the saveservice.properties?

Is that because jmeter try to open the file with the FILE Class? How can java load the saveservice.properties? or is that not necessary because jMeter Home is set?

private static final String jMeterHomePath = "/jmeter";
private static final String jMeterPropertiesFile = jMeterHomePath + "/bin/jmeter.properties";
...


File propertiesFile = FileStreamUtil.jMeterPropertiesToTempFile(jMeterPropertiesFile);
String jMeterPropertiesPath = propertiesFile.getPath();

StandardJMeterEngine jMeter = new StandardJMeterEngine();    JMeterUtils.setJMeterHome(Encoder.class.getResource(jMeterHomePath).getPath());

JMeterUtils.loadJMeterProperties(jMeterPropertiesPath);

JMeterUtils.initLogging();
JMeterUtils.initLocale();

String home = JMeterUtils.getJMeterHome();
System.out.println("HOME: "+home);

SaveService.loadProperties();
2
Open your jar and check you have this resource : jmeter/bin/saveservice.properties in a classpath dir or at the root of the jardavidxxx
Actually, I've made it run to the cloud. Last commentPascal

2 Answers

0
votes

As per SaveService class source saveservice.properties file is being read as follows:

// some code

private static final String SAVESERVICE_PROPERTIES_FILE = "/bin/saveservice.properties"; 

// Property name used to define file name
private static final String SAVESERVICE_PROPERTIES = "saveservice_properties"; // $NON-NLS-1$

// some more code


public static Properties loadProperties() throws IOException{
    Properties nameMap = new Properties();
    try (FileInputStream fis = new FileInputStream(JMeterUtils.getJMeterHome()
            + JMeterUtils.getPropDefault(SAVESERVICE_PROPERTIES, SAVESERVICE_PROPERTIES_FILE))){
        nameMap.load(fis);
    }
    return nameMap;
}

So you need to ensure you have bin/saveservice.properties file under your JMeter Home, this way it will work as expected.

If you are packaging JMeter into your solution you will need to unpack it somewhere in order to make it work. Otherwise you will need to patch the aforementioned SaveService class so it would read properties from resources file.

See Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on programmatic execution of JMeter test with some examples.

0
votes

You can't open a file with File class when that file is within a Jar. It can't handle the exclamation mark (!) in your file url.

If that's your problem, check for solution here: Accessing a file inside a .jar file