Package dev.galasa.jmeter
Interface IJMeterSession
public interface IJMeterSession
Interface for creation, management, deletion of JMeter sessions
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyProperties(InputStream propStream) Apply properties to the JMeter session from a properties file stream.voidapplyProperties(InputStream propStream, Map<String, Object> properties) Apply properties to the JMeter session from both a properties file stream and additional dynamic properties.Retrieve the console output from the JMeter execution.longGet the exit code from the JMeter process execution.Retrieve the JMX test plan file content as a UTF-8 encoded string.getListenerFile(String fileName) Retrieve a specific listener output file from the JMeter execution.Retrieve the JMeter log file content as a UTF-8 encoded string.intGet the unique session identifier for this JMeter session.booleanCheck whether the JMeter test executed successfully.voidsetChangedParametersJmxFile(InputStream jmxStream, Map<String, Object> parameters) Set the JMX test plan file for this session using a parameterized JMX template.voidsetDefaultGeneratedJmxFile(InputStream jmxStream) Set the JMX test plan file for this session using a static (non-parameterized) JMX file.voidStart the JMeter test execution with the default timeout of 60 seconds.voidstartJmeter(int timeout) Start the JMeter test execution with a specified timeout.booleanDeprecated.voidstopTest()Stop the JMeter test execution and clean up resources.
-
Method Details
-
applyProperties
Apply properties to the JMeter session from a properties file stream. This method should be called before starting the JMeter test.- Parameters:
propStream- An InputStream containing the properties file content- Throws:
JMeterManagerException- if properties cannot be applied
-
applyProperties
void applyProperties(InputStream propStream, Map<String, Object> properties) throws JMeterManagerExceptionApply properties to the JMeter session from both a properties file stream and additional dynamic properties. This method should be called before starting the JMeter test. The dynamic properties map will be merged with properties from the stream, with dynamic properties taking precedence.- Parameters:
propStream- An InputStream containing the properties file contentproperties- A Map of additional dynamic properties to apply- Throws:
JMeterManagerException- if properties cannot be applied
-
startJmeter
Start the JMeter test execution with the default timeout of 60 seconds. All results are automatically stored in the Result Archive Store (RAS).- Throws:
JMeterManagerException- if the test fails to start or execute
-
startJmeter
Start the JMeter test execution with a specified timeout. All results are automatically stored in the Result Archive Store (RAS).- Parameters:
timeout- The maximum time in milliseconds to wait for test completion- Throws:
JMeterManagerException- if the test fails to start, execute, or times out
-
setDefaultGeneratedJmxFile
Set the JMX test plan file for this session using a static (non-parameterized) JMX file. Use this method when your JMX file does not require dynamic parameter substitution.- Parameters:
jmxStream- An InputStream containing the JMX test plan content- Throws:
JMeterManagerException- if the JMX file cannot be stored or is invalid
-
setChangedParametersJmxFile
void setChangedParametersJmxFile(InputStream jmxStream, Map<String, Object> parameters) throws JMeterManagerExceptionSet the JMX test plan file for this session using a parameterized JMX template. This method processes the JMX template using Velocity, replacing variables with provided values.To prepare your JMX file for parameterization:
- Replace JMeter's ${__P(VARIABLE)} notation with Velocity's $VARIABLE notation
- Provide parameter values in a Map
Example:
Map<String,Object> params = new HashMap<>(); params.put("HOST", "galasa.dev"); params.put("PORT", 8080); session.setChangedParametersJmxFile(jmxStream, params);- Parameters:
jmxStream- An InputStream containing the JMX template contentparameters- A Map of parameter names to values for template substitution- Throws:
JMeterManagerException- if the JMX template cannot be processed or stored
-
getJmxFile
Retrieve the JMX test plan file content as a UTF-8 encoded string.- Returns:
- The JMX file content
- Throws:
JMeterManagerException- if the file cannot be retrieved
-
getLogFile
Retrieve the JMeter log file content as a UTF-8 encoded string. The log file contains JMeter's execution logs and diagnostic information.- Returns:
- The log file content
- Throws:
JMeterManagerException- if the file cannot be retrieved
-
getConsoleOutput
Retrieve the console output from the JMeter execution.- Returns:
- The console output as a string
- Throws:
JMeterManagerException- if the console output cannot be retrieved
-
getListenerFile
Retrieve a specific listener output file from the JMeter execution. Listener files contain test results in various formats (e.g., .jtl files).- Parameters:
fileName- The name of the listener file to retrieve- Returns:
- The listener file content as a string
- Throws:
JMeterManagerException- if the file cannot be retrieved or fileName is invalid
-
statusTest
Deprecated.UseisTestSuccessful()instead. This method will be removed in a future release.Check whether the JMeter test executed successfully.- Returns:
- true if the test completed successfully, false otherwise
- Throws:
JMeterManagerException- if the test status cannot be determined or the test failed
-
isTestSuccessful
Check whether the JMeter test executed successfully.For LOCAL mode: Returns true if exit code is 0
For DOCKER mode: Returns true if log contains expected completion markers
- Returns:
- true if the test completed successfully, false otherwise
- Throws:
JMeterManagerException- if the test status cannot be determined or the test failed
-
stopTest
Stop the JMeter test execution and clean up resources.For LOCAL mode: This is a no-op as binary execution completes automatically
For DOCKER mode: Stops the container and removes it from active sessions
- Throws:
JMeterManagerException- if the test cannot be stopped or cleanup fails
-
getExitCode
Get the exit code from the JMeter process execution.- Returns:
- The exit code (0 indicates success, non-zero indicates failure)
- Throws:
JMeterManagerException- if the exit code cannot be retrieved
-
getSessionID
int getSessionID()Get the unique session identifier for this JMeter session.- Returns:
- The session ID
-
isTestSuccessful()instead.