Passing MQTT Client Object Between JMeter Thread Groups - jmeter

I have a requirement to pass MQTT Client Object between multiple thread groups as MQTT object (not string). All the JMeter elements like Property, Inter-Process Communication, vars.getObject are considering the values in String type.
Question: How can I use this client object in another thread group with same object mqtt object type.
Please help!!!
Thanks
Pawan

As per JMeter documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
If you want to store an object into a JMeter Variable you should use vars.putObject() function to store the value and vars.getObject() to read the value
If you're intending to pass the object to different thread (no matter in this or other Thread Group) you need to use props shorthand like:
props.put('some-key', your-object-here)
and later on you will be able to read it as:
Object myObject = props.get('some-key')
More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

Related

Write to GlobalStateStore on Kafka Streams

I am trying to use addGlobalStore on a Kafka DSL where a need to store few values that I will need global access for all my threads/instances.
My problem is that I need periodically to update these values inside my topology and make all running threads aware of the new values.
I initialized the global store through builder.addGlobalStore and using the init() function of a Processor that was used as the last argument on this function, but I cannot find a way to update the values inside the global store.
The next step on my Topology is a Transformer where I can get a hook through ```init()`` on the global Store and read the stored values but unfortunately I cannot updated them globally. I mean I can update the
local copy for the running thread but other threads/instances cannot see the change.
I read somewhere that this cannot be done on Transformer, but even I use a Processor instead the issue remains
So, Is there a way to update globalStateStore on a Kafka DSL topology,
and if so how is this possible ? Or in order to use global store do I need to use the low level processor API ?
I initialized the global store through builder.addGlobalStore and using the init() function of a Processor that was used as the last argument on this function, but I cannot find a way to update the values inside the global store.
You cannot update a global store directly. Instead, you must update (= write a message to) the underlying topic of that global store.
In case it fits your needs you probably could use GlobalKTable instead of GlobalStore

Jmeter: Get SAML Token Once for all Thread Group

I need to call a Rest API ONCE to get a SAML Token to use in the Authorization Header for all other Thread Group/Users in my test. What is the preferred way of doing this? I can see where I can add a header manager and use the variables from there, but it looks like the variable is scoped to the thread group. I assume I can use a property. To make it simple I want one thread group that calls the api to get the token, so it will only call once set some property and all the other thread groups will use the property to get the SAML token. I am newbie so please be nice, it seems like this is a standard thing to do. My plan was a JSON Extractor and somehow use that to set a property.
The easier way is using JMeter Functions instead of Beanshell (moreover Beanshell scripting is a kind of performance anti-pattern). Also you don't need this 2nd "property to variable" conversion.
In 1st Thread Group use __setProperty() function in order to convert JMeter Variable into a property like
${__setProperty(token,${token},)}
In 2nd Thread Group use __P() function to get the token property value like
${__P(token,)}
In general using single SAML token for the multiple threads doesn't seem very good idea to me as normally different users should have different tokens and good load test needs to represent real life situations as close as possible. So I would recommend considering using single token per single virtual user. If you need to pass the tokens across thread groups you can go for Inter-Thread Communication Plugin, it is way easier, moreover you will have confidence that 2nd thread won't start until it receives the token from 1st thread.
I found these thread(s) that helped:
How to get value from property in BeanShell (jmeter)
Still not sure if this is the correct way, but it worked.
I called my REST API to get my Token
I Used a JSON extractor to get the Token
I Set a Global Property to hold my token using a Bean Shell Assertion
props.put("token", vars.get("token"));
In my other thread group I get the token from the property
String token = props.get("token");
vars.put("token",token );
In the HTTP Header Manager I get the token from local variable ${token}
This seems tedious, I am hoping there is better way.

Jmeter JMS point-to-point with dynamic messgae content

I am new to jmeter. I am trying to setup JMS point-to-point load test script. The request message is a fixed-length format. I need a way to read fields from csv and arrange them in fixed-length format. I tried using javascript slice function by using csv data config variables and slicing to required length, concating them all in one line. But it is not working. May be my approach is wrong. Any pointers on how to make it work with fixed length format will help.
This is what I tried:
${__javascript((" ".slice(-6))+(("0000000000000000"+${Var2}).slice(-16)) + ((" " + ${Var3}).slice(-19))+((" "+${Var4}).slice(-3))}
where Var1,Var2..Var4 are from csv.
Jmeter version:3.3
MQ: IBM Websphere MQ
With a single input message I am able to execute the test. I need to dynamically populate values from csv and/or date/time functions and arrange them in fixed-length format.
You have a typo in your code, the function should be __javaScript (mind the capital S
Your approach should work, however using JavaScript is extremely inefficient as each time you call __javaScript() function JMeter invokes Rhino or Nashorn interpreter and this may ruin your test in case of high loads. Since JMeter 3.1 users are encouraged to use __groovy() function for scripting.
And last but not the least, in order to get the most performance I would recommend using __substring() function instead of your slice() function. You can install __substring() and other Custom JMeter Functions using JMeter Plugins Manager

Mixed Write for GSON

I am using GSON object model access to construct JSON to be used as body of my POST webservice calls in Jmeter.
Now I frequently encounter : GCC Out of memory exception with the error pointing to the code section=> gson.toJson(objectToSerialize).
From the past posts, it was suggested to use gson serialization with the streaming access model.
My current code does this: Create an object of an class by populating its variables and passes this class on to the GSON serializer, gets back the constructed JSON in form of string and I use them.
Could the experts suggest, is there a way that I could integrate streaming access model into my code without having to do much of a rework. Would this be memory efficient?
PS: I took a look into Mixed writes example specified in this link but unable to get around how to construct a JSON by passing one object of the class as we do in the object model:
https://sites.google.com/site/gson/streaming
Thank you!
Why don't you just use these variables in "Body Data" mode of the HTTP Request sampler like:
If your JSON payload is large you may have to amend Java HEAP size as default allocation is just 512MB and it may be not enough for more or less large load. If you don't have enough free RAM to fit JSON data size * number of virtual users you may have to consider Distributed Testing
The other option may be you using not very efficient scripting test element. It is recommended to use JSR223 Test Elements and Groovy as a language as other options are not performing that well.
See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for more information on

Websphere MQ: Proper usage of method createQueue(java.lang.String queueName) in com.ibm.mq.jms.MQSession

I need to clarify the behavior of the method createQueue(java.lang.String queueName) from the class com.ibm.mq.jms.MQSession.
If I pass an arbitrary queue name, will it create a temporary queue? In the other hand, what String value needs to be passed to get a Queue object that represents a static queue configured in the queue manager?
For instance, if I have an object dest of type MQDestination, I could call dest.toString() or according to javadocs or dest.getStringFromDestination() (which returns a URI String). Will any of these two results work if passed to the createQueue method mentioned.
The intent of my question is to properly use a Spring's DynamicDestinationResolver (takes String and returns Destination) which behind the scenes uses this MQ specific method.
Thanks for your time
You can find the description of the JMS Session object here:
http://docs.oracle.com/javaee/7/api/javax/jms/Session.html
In JMS Session.createQueue() does not create a physical queue on the MQ queue manager, rather it's used to connect to one which has already been defined. MQSession.createQueue("Q1"); would result in a Destination object which can be used to refer to the queue 'Q1' which already exists on the queue manager.
For creating a temporary queue you need to use the createTemporaryQueue() method of the MQSession object. Though you have no control over the name of said temporary queue.

Resources