Last active
April 22, 2025 20:01
-
-
Save rmoff/ba1d7c8ba3de62463e80f0eb12cb553d to your computer and use it in GitHub Desktop.
IBM MQ JMeter test script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<jmeterTestPlan version="1.2" properties="4.0" jmeter="4.0 r1823414"> | |
<hashTree> | |
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"> | |
<stringProp name="TestPlan.comments"></stringProp> | |
<boolProp name="TestPlan.functional_mode">false</boolProp> | |
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp> | |
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp> | |
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> | |
<collectionProp name="Arguments.arguments"> | |
<elementProp name="setupDone" elementType="Argument"> | |
<stringProp name="Argument.name">setupDone</stringProp> | |
<stringProp name="Argument.value">false</stringProp> | |
<stringProp name="Argument.metadata">=</stringProp> | |
</elementProp> | |
<elementProp name="stopDone" elementType="Argument"> | |
<stringProp name="Argument.name">stopDone</stringProp> | |
<stringProp name="Argument.value">false</stringProp> | |
<stringProp name="Argument.metadata">=</stringProp> | |
</elementProp> | |
</collectionProp> | |
</elementProp> | |
<stringProp name="TestPlan.user_define_classpath"></stringProp> | |
</TestPlan> | |
<hashTree> | |
<SetupThreadGroup guiclass="SetupThreadGroupGui" testclass="SetupThreadGroup" testname="setUp Thread Group" enabled="true"> | |
<stringProp name="ThreadGroup.on_sample_error">stoptestnow</stringProp> | |
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> | |
<boolProp name="LoopController.continue_forever">false</boolProp> | |
<stringProp name="LoopController.loops">1</stringProp> | |
</elementProp> | |
<stringProp name="ThreadGroup.num_threads">1</stringProp> | |
<stringProp name="ThreadGroup.ramp_time">1</stringProp> | |
<boolProp name="ThreadGroup.scheduler">false</boolProp> | |
<stringProp name="ThreadGroup.duration"></stringProp> | |
<stringProp name="ThreadGroup.delay"></stringProp> | |
</SetupThreadGroup> | |
<hashTree> | |
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Create MQ Connection" enabled="true"> | |
<stringProp name="scriptLanguage">groovy</stringProp> | |
<stringProp name="parameters"></stringProp> | |
<stringProp name="filename"></stringProp> | |
<stringProp name="cacheKey">true</stringProp> | |
<stringProp name="script">import com.ibm.msg.client.jms.JmsConnectionFactory | |
import com.ibm.msg.client.jms.JmsFactoryFactory | |
import com.ibm.msg.client.wmq.WMQConstants | |
import javax.jms.Session | |
// 1 | |
def hostName = "127.0.0.1" | |
def hostPort = 1414 | |
def channelName = "DEV.APP.SVRCONN" | |
def queueManagerName = "QM1" | |
def queueName = "DEV.QUEUE.1" | |
// 2 | |
def ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER) | |
def cf = ff.createConnectionFactory() | |
// 3 | |
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName) | |
cf.setIntProperty(WMQConstants.WMQ_PORT, hostPort) | |
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channelName) | |
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT) | |
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManagerName) | |
// 4 | |
def conn = cf.createConnection("app","") | |
def sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE) | |
// 5 | |
def destination = sess.createQueue(queueName) | |
conn.start() | |
log.info("#### Start completed!") | |
// 6 | |
System.getProperties().put("Session", sess) | |
System.getProperties().put("Connection", conn) | |
System.getProperties().put("Destination", destination) | |
// 7 | |
vars.put("setupDone", "true")</stringProp> | |
</JSR223Sampler> | |
<hashTree/> | |
</hashTree> | |
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Producer" enabled="true"> | |
<stringProp name="ThreadGroup.on_sample_error">stoptestnow</stringProp> | |
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> | |
<boolProp name="LoopController.continue_forever">false</boolProp> | |
<intProp name="LoopController.loops">-1</intProp> | |
</elementProp> | |
<stringProp name="ThreadGroup.num_threads">20</stringProp> | |
<stringProp name="ThreadGroup.ramp_time">1</stringProp> | |
<boolProp name="ThreadGroup.scheduler">false</boolProp> | |
<stringProp name="ThreadGroup.duration">30</stringProp> | |
<stringProp name="ThreadGroup.delay"></stringProp> | |
</ThreadGroup> | |
<hashTree> | |
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Send messages" enabled="true"> | |
<stringProp name="cacheKey">true</stringProp> | |
<stringProp name="filename"></stringProp> | |
<stringProp name="parameters"></stringProp> | |
<stringProp name="script">import java.time.Instant | |
// 1 | |
def sess = System.getProperties().get("Session") | |
def destination = System.getProperties().get("Destination") | |
// 2 | |
def producer = sess.createProducer(destination) | |
// 3 | |
def rnd = new Random(System.currentTimeMillis()) | |
// 4 | |
def payload = String.format("JMeter...IBM MQ...rmoff...test message no. %09d!", rnd.nextInt(Integer.MAX_VALUE)) | |
def msg = sess.createTextMessage(payload) | |
def start = Instant.now() | |
// 5 | |
producer.send(msg) | |
def stop = Instant.now() | |
// 6 | |
producer.close() | |
// 7 | |
SampleResult.setResponseData(msg.toString()) | |
SampleResult.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT ) | |
SampleResult.setLatency( stop.toEpochMilli() - start.toEpochMilli() )</stringProp> | |
<stringProp name="scriptLanguage">groovy</stringProp> | |
</JSR223Sampler> | |
<hashTree/> | |
<UniformRandomTimer guiclass="UniformRandomTimerGui" testclass="UniformRandomTimer" testname="Uniform Random Timer" enabled="true"> | |
<stringProp name="ConstantTimer.delay">0</stringProp> | |
<stringProp name="RandomTimer.range">1000.0</stringProp> | |
</UniformRandomTimer> | |
<hashTree/> | |
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Sleep" enabled="true"> | |
<stringProp name="ConstantTimer.delay">500</stringProp> | |
</ConstantTimer> | |
<hashTree/> | |
</hashTree> | |
<PostThreadGroup guiclass="PostThreadGroupGui" testclass="PostThreadGroup" testname="tearDown Thread Group" enabled="true"> | |
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp> | |
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> | |
<boolProp name="LoopController.continue_forever">false</boolProp> | |
<stringProp name="LoopController.loops">1</stringProp> | |
</elementProp> | |
<stringProp name="ThreadGroup.num_threads">1</stringProp> | |
<stringProp name="ThreadGroup.ramp_time">1</stringProp> | |
<boolProp name="ThreadGroup.scheduler">false</boolProp> | |
<stringProp name="ThreadGroup.duration"></stringProp> | |
<stringProp name="ThreadGroup.delay"></stringProp> | |
</PostThreadGroup> | |
<hashTree> | |
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Close MQ Connection" enabled="true"> | |
<stringProp name="scriptLanguage">groovy</stringProp> | |
<stringProp name="parameters"></stringProp> | |
<stringProp name="filename"></stringProp> | |
<stringProp name="cacheKey">true</stringProp> | |
<stringProp name="script">// 1 | |
System.getProperties().get("Session").close() | |
System.getProperties().get("Connection").close() | |
log.info("#### Stop completed!") | |
// 2 | |
vars.put("stopDone", "true")</stringProp> | |
</JSR223Sampler> | |
<hashTree/> | |
</hashTree> | |
<ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true"> | |
<boolProp name="ResultCollector.error_logging">false</boolProp> | |
<objProp> | |
<name>saveConfig</name> | |
<value class="SampleSaveConfiguration"> | |
<time>true</time> | |
<latency>true</latency> | |
<timestamp>true</timestamp> | |
<success>true</success> | |
<label>true</label> | |
<code>true</code> | |
<message>true</message> | |
<threadName>true</threadName> | |
<dataType>true</dataType> | |
<encoding>false</encoding> | |
<assertions>true</assertions> | |
<subresults>true</subresults> | |
<responseData>false</responseData> | |
<samplerData>false</samplerData> | |
<xml>false</xml> | |
<fieldNames>true</fieldNames> | |
<responseHeaders>false</responseHeaders> | |
<requestHeaders>false</requestHeaders> | |
<responseDataOnError>false</responseDataOnError> | |
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage> | |
<assertionsResultsToSave>0</assertionsResultsToSave> | |
<bytes>true</bytes> | |
<sentBytes>true</sentBytes> | |
<threadCounts>true</threadCounts> | |
<idleTime>true</idleTime> | |
<connectTime>true</connectTime> | |
</value> | |
</objProp> | |
<stringProp name="filename"></stringProp> | |
</ResultCollector> | |
<hashTree/> | |
<ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true"> | |
<boolProp name="ResultCollector.error_logging">false</boolProp> | |
<objProp> | |
<name>saveConfig</name> | |
<value class="SampleSaveConfiguration"> | |
<time>true</time> | |
<latency>true</latency> | |
<timestamp>true</timestamp> | |
<success>true</success> | |
<label>true</label> | |
<code>true</code> | |
<message>true</message> | |
<threadName>true</threadName> | |
<dataType>true</dataType> | |
<encoding>false</encoding> | |
<assertions>true</assertions> | |
<subresults>true</subresults> | |
<responseData>false</responseData> | |
<samplerData>false</samplerData> | |
<xml>false</xml> | |
<fieldNames>true</fieldNames> | |
<responseHeaders>false</responseHeaders> | |
<requestHeaders>false</requestHeaders> | |
<responseDataOnError>false</responseDataOnError> | |
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage> | |
<assertionsResultsToSave>0</assertionsResultsToSave> | |
<bytes>true</bytes> | |
<sentBytes>true</sentBytes> | |
<threadCounts>true</threadCounts> | |
<idleTime>true</idleTime> | |
<connectTime>true</connectTime> | |
</value> | |
</objProp> | |
<stringProp name="filename"></stringProp> | |
</ResultCollector> | |
<hashTree/> | |
</hashTree> | |
</hashTree> | |
</jmeterTestPlan> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Script based largely on https://www.blazemeter.com/blog/ibm-mq-testing-with-jmeter-learn-how |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment