Jmeter how to modify a variable in BeanShell - jmeter

I have the following situation with jmeter:
I have two thread groups and I want to use a variable extracted from a response from the first one into the second thread.
What I am doing:
the variable is extracted with JSON/YAML Path Extractor and then it is set as a property with BeanShell Assertion ${__setProperty(id, ${id})};
Then in the second thread group I have a BeanShell PreProcessor where I am trying to modify the value with the following script
String ids2 = props.get("id");
String ids3 = vars.put(${__intSum(2,-4)});
String ids = vars.put(ids,"${__intSum(${ids2},${ids3})}");
As result I am getting an exception in jmeter
ava.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.8.0_221]
at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_221]
at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_221]
at org.apache.jmeter.functions.IntSum.execute(IntSum.java:66) ~[ApacheJMeter_functions.jar:5.4.1]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:138) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:113) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:91) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.testbeans.TestBeanHelper.unwrapProperty(TestBeanHelper.java:129) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:84) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.engine.StandardJMeterEngine.notifyTestListenersOfStart(StandardJMeterEngine.java:202) ~[ApacheJMeter_core.jar:5.4.1]
at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:382) ~[ApacheJMeter_core.jar:5.4.1]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
The goal is to reduce the variable with 2 and then to transfer it to another variable which I will use only in the second thread group
Any help will be highly appreciated

Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
Your approach might work for 1 thread but if you will have > 1 thread the property will be overwritten, if you want each thread (virtual user) to have its own value you should add the current thread number as the prefix or postfix for the property. The relevant function is __threadNum() or if you prefer scripting you can call ctx.getThreadNum() function
In the vast majority of cases Inter-Thread Communication Plugin is easier to use

Related

How to pass a 2-D array from one thread to another thread in Jmeter

So I am using a bean shell post processor and towards the end I am storing the result in a 2-D array. Result is stored this way.
testArray[0][0] = "1"
testArray[0][1] = "Test"
testArray[1][0] = "2"
testArray[1][1] = "STG"
My requirement is that I need to pass this 2-D array to the next thread. How am I supposed to proceed ?
First of all since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so consider migrating to Groovy.
Coming back to your question just use props shorthand like:
In first thread:
props.put("testArray", testArray);
in the other thread:
testArray = props.get("testArray");
you might also want to add the current thread number as the prefix/postfix so different threads could have different arrays with separate values like:
props.put("testArray_" + ctx.getThreadNum(), testArray);
where ctx stand for JMeterContext class instance
More information on these ctx, props and other JMeter API shortcuts available for JSR223 Test elements: Top 8 JMeter Java Classes You Should Be Using with Groovy

JMeter - groovy MultipleCompilationErrorsException in JSR223 Sampler

I'm using groovy for JMeter JSR223 sampler . Below code is working fine from JMeter GUI.
String user = vars.get("username"); # abc.com\user1
String domainVal = ""
String userVal = ""
System.out.println(user)
if(user.contains("\\")){
String[] arrOfStr = user.split("\\\\", 2);
domainVal =arrOfStr[0]
userVal = arrOfStr[1]
}else{
userVal = user
}
System.out.println(domainVal)
System.out.println(userVal)
But same script I'm trying from JMeter headless is giving me error
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script8.groovy: 20: Missing ')' # line 20, column 18.
if(user.contains("\")){
^
1 error
I am clueless , what is causing the issue .
Update
I found the root cause it is caused by , if I remove below line (Jmeter thread number) it's working fine. Not a groovy issue, JMeter issue for sure.
int thread_count = ${__threadNum};
Don't use JMeter function in JSR223 script, replacement for __threadNum:
int threadNum = ctx.getThreadNum()
The function returns a number between one and the max number of running threads. Note that if you're using JSR223 code with JMeterContext object (ctx variable), the below code returns a number between zero and (max number of running threads minus one)
ctx.getThreadNum()
I cannot reproduce your issue:
with regards to your int thread_count = ${__threadNum}; piece of "code", you shouldn't be inlining JMeter Functions or Variables into Groovy scripts because:
The syntax conflicts with Groovy's GString Template Engine
The values will be cached and re-used on next occurrence
So you should either use "Parameters" section or code-based equivalents
More information: JSR223 Sampler Documentation
where ctx stands for JMeterContext class, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details on this and other JMeter API shorthands available for JSR223 Test Elements

How can I configurate the late acceptance algorithm?

I am encountering some problems when it comes to modifying the applied algorithms:
First, it seems I cannot change the late acceptance algorithm configuration. This is my local search configuration, which works nicely when I am not specifying neither acceptor nor forager:
<localSearch>
<localSearchType>LATE_ACCEPTANCE</localSearchType>
<acceptor>
<lateAcceptanceSize>5000</lateAcceptanceSize>
<entityTabuRatio>0.1</entityTabuRatio>
<!--valueTabuSize>10000</valueTabuSize-->
</acceptor>
<forager>
<acceptedCountLimit>1</acceptedCountLimit>
</forager>
<termination>
<minutesSpentLimit>10</minutesSpentLimit>
<bestScoreLimit>[0/11496/11496]hard/[0]soft</bestScoreLimit>
</termination>
</localSearch>
I get this error message as part of the output
java.lang.IllegalArgumentException: The localSearchType (...
java.lang.IllegalArgumentException: The localSearchType (LATE_ACCEPTANCE) must not be configured if the acceptorConfig (AcceptorConfig()) is explicitly configured.
at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildAcceptor(LocalSearchPhaseConfig.java:182)
at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildDecider(LocalSearchPhaseConfig.java:132)
at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:117)
at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:54)
at org.optaplanner.core.config.solver.SolverConfig.buildPhaseList(SolverConfig.java:364)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:270)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
at com.gmv.g2gmps.CBand.App.main(App.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(Thread.java:748)
Finally, I was told that the configuration of LATE_ACCEPTANCE and lateAcceptanceSize at the same time is incompatible. Therefore I set late acceptance size as the only parameter (therefore Late acceptance as an acceptor) instead of writing it down as the local search type.
<localSearch>
<acceptor>
<lateAcceptanceSize>5000</lateAcceptanceSize>
<entityTabuRatio>0.1</entityTabuRatio>
<!--valueTabuSize>10000</valueTabuSize-->
</acceptor>
<forager>
<acceptedCountLimit>1</acceptedCountLimit>
</forager>
<termination>
<minutesSpentLimit>10</minutesSpentLimit>
<bestScoreLimit>[0/11496/11496]hard/[0]soft</bestScoreLimit>
</termination>
</localSearch>

ELKI COPAC implementation

I tried to run COPAC ELKI implementation on the example dataset provided on the official site (mouse.csv) but I get a NullPointerException which leads me to think that there is some detail that I omit (shame on me).
The exception is the following:
Task failed java.lang.NullPointerException at
de.lmu.ifi.dbs.elki.database.ids.integer.DoubleDistanceIntegerDBIDPair.compareByDistance(Unknown
Source) at
de.lmu.ifi.dbs.elki.distance.distanceresultlist.AbstractKNNHeap$Comp.compare(Unknown
Source) at
de.lmu.ifi.dbs.elki.distance.distanceresultlist.AbstractKNNHeap$Comp.compare(Unknown
Source) at
de.lmu.ifi.dbs.elki.utilities.datastructures.heap.TopBoundedHeap.add(Unknown
Source) at
de.lmu.ifi.dbs.elki.database.query.knn.LinearScanRawDoubleDistanceKNNQuery.getKNNForObjectBenchmarked(Unknown
Source) at
de.lmu.ifi.dbs.elki.database.query.knn.LinearScanRawDoubleDistanceKNNQuery.getKNNForObject(Unknown
Source) at
de.lmu.ifi.dbs.elki.database.query.knn.LinearScanRawDoubleDistanceKNNQuery.getKNNForDBID(Unknown
Source) at
de.lmu.ifi.dbs.elki.index.preprocessed.localpca.KNNQueryFilteredPCAIndex.objectsForPCA(Unknown
Source) at
de.lmu.ifi.dbs.elki.index.preprocessed.localpca.KNNQueryFilteredPCAIndex.objectsForPCA(Unknown
Source) at
de.lmu.ifi.dbs.elki.index.preprocessed.localpca.AbstractFilteredPCAIndex.preprocess(Unknown
Source) at
de.lmu.ifi.dbs.elki.index.preprocessed.localpca.AbstractFilteredPCAIndex.getLocalProjection(Unknown
Source) at
de.lmu.ifi.dbs.elki.index.preprocessed.localpca.AbstractFilteredPCAIndex.getLocalProjection(Unknown
Source) at
de.lmu.ifi.dbs.elki.algorithm.clustering.correlation.COPAC.run(Unknown
Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616) at
de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm.run(Unknown Source)
at de.lmu.ifi.dbs.elki.workflow.AlgorithmStep.runAlgorithms(Unknown
Source) at [...]
This is the setting of the parameters that I use:
-dbc.in
[PATH OMITTED]/mouse.csv
-algorithm
clustering.correlation.COPAC
-copac.preprocessor
localpca.KNNQueryFilteredPCAIndex
-copac.partitionAlgorithm
gdbscan.GeneralizedDBSCAN
-dbscan.epsilon
0.00400000
-dbscan.minpts
3
Can anyone give me some info?
You must specify the k parameter for kNN Local PCA:
-localpca.k 10
there is a slight bug in the last ELKI release, where the parameter is incorrectly marked as optional. It is not optional. Note that k should be significantly larger than the data dimensionality to give stable PCA results.
Note that using COPAC on a low dimensional data set such as the mouse example does not make sense.

Unknown error in XPath

One of our web application, which has been running in our production environment for a long time, most recently it is running into an weird error when there is a high volume of transactions. We couldn't figure out what is exactly the root cause of the problem, but we found some similar issues in the previous version, WebSphere 6, related to a bug in Xalan version used by the app server. Our application server actually is WebSphere 7, which is supposed to have it fixed, besides it's not using Xalan under the hood anymore. Our application doesn't have Xalan jar embedded too.
To have it fixed we just restart the application itself.
One important note is that the Document is being cached (docs.get(tableName)) and reused to execute the XPath evaluation. We did it to avoid the cost of parsing the Document every time.
The app code is
Document doc = null;
try {
doc = docs.get(tableName);
if (doc == null)
return null;
XPathFactory xFactory = XPathFactory.newInstance();
XPath xpath = xFactory.newXPath();
XPathExpression expr = xpath.compile(toUpper(xPathQuery));
Object result = expr.evaluate(doc, XPathConstants.NODESET);
return (NodeList) result;
} catch (XPathExpressionException e) {
logger.error("Error executing XPath", e);
}
And the error stack is here
javax.xml.transform.TransformerException: Unknown error in XPath.
at java.lang.Throwable.<init>(Throwable.java:67)
at javax.xml.transform.TransformerException.<init>(Unknown Source)
at org.apache.xpath.XPath.execute(Unknown Source)
at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(Unknown Source)
Caused by: java.lang.NullPointerException
at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source)
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.processNamespacesAndAttributes(Unknown Source)
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(Unknown Source)
at org.apache.xml.dtm.ref.DTMDefaultBase._nextsib(Unknown Source)
at org.apache.xml.dtm.ref.DTMDefaultBase.getNextSibling(Unknown Source)
at org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$ChildTraverser.next(Unknown Source)
at org.apache.xpath.axes.AxesWalker.getNextNode(Unknown Source)
at org.apache.xpath.axes.AxesWalker.nextNode(Unknown Source)
at org.apache.xpath.axes.WalkingIterator.nextNode(Unknown Source)
at org.apache.xpath.axes.NodeSequence.nextNode(Unknown Source)
at org.apache.xpath.axes.NodeSequence.runTo(Unknown Source)
at org.apache.xpath.axes.NodeSequence.setRoot(Unknown Source)
at org.apache.xpath.axes.LocPathIterator.execute(Unknown Source)
... 16 more
This is the similar issue what I mentioned.
http://www-01.ibm.com/support/docview.wss?uid=swg1PK42574
Thakns.
Many people don't realise that the DOM is not thread-safe (even if you are only doing reads). If you are caching a DOM object, make sure you synchronize all access to it.
Frankly, this makes DOM unsuited to this kind of application. I know I'm biased, but I would suggest switching to Saxon, whose native tree implementation is not only far faster than DOM, but also thread-safe. One user recently tweeted about getting a 100x performance improvement when they made this switch.

Resources