How to pass in double value via jmeterproperty in Jmeter - java

I am trying to parametrize some values in the Precise Throughput Timer. So that this can be passed when jmeter is run from the command line.
The xml snippet is below:
<?xml version="1.0" encoding="UTF-8"?>
<PreciseThroughputTimer guiclass="TestBeanGUI" testclass="PreciseThroughputTimer" testname="Precise Throughput Timer" enabled="true">
<doubleProp>
<name>allowedThroughputSurplus</name>
<value>1.0</value>
<savedValue>0.0</savedValue>
</doubleProp>
<intProp name="exactLimit">10000</intProp>
<doubleProp>
<name>throughput</name>
<value>${req_per_sec}</value> <!-- variable -->
<savedValue>0.0</savedValue>
</doubleProp>
<intProp name="throughputPeriod">1</intProp>
<longProp name="duration">60</longProp>
<intProp name="batchSize">1</intProp>
<intProp name="batchThreadDelay">0</intProp>
<longProp name="randomSeed">0</longProp>
</PreciseThroughputTimer>
and then I pass the value in when jmeter is started via:
...
--jmeterproperty req_per_sec=${REQ_PER_SEC} \
...
Where REQ_PER_SEC is a bash environment variable... But this fails to run with the following error:
An error occurred: Error in NonGUIDriver Problem loading XML from:'/jmeter/test.jmx'.
Cause:
NumberFormatException: For input string: "${req_per_sec}"
Detail:com.thoughtworks.xstream.converters.ConversionException:
---- Debugging information ----
cause-exception : com.thoughtworks.xstream.converters.ConversionException
cause-message :
first-jmeter-class : org.apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:105)
class : org.apache.jmeter.save.ScriptWrapper
required-type : org.apache.jmeter.save.ScriptWrapper
converter-type : org.apache.jmeter.save.ScriptWrapperConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree/PreciseThroughputTimer/doubleProp[2]/value
line number : 90
version : 5.3
-------------------------------
Looking into the logs I also see this:
Caused by: java.lang.NumberFormatException: For input string: "${req_per_sec}"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) ~[?:1.8.0_252]
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) ~[?:1.8.0_252]
at java.lang.Double.parseDouble(Double.java:538) ~[?:1.8.0_252]
at java.lang.Double.valueOf(Double.java:502) ~[?:1.8.0_252]
It seems Jmeter is reading the value as a string instead of a double? I cant figure out how to make it get the value passed in via the jmeterproperty property as double.
How do I do this?

You're using the syntax of a JMeter Variable while you're setting a JMeter Property.
You need to either change your ${req_per_sec} to __P() function call like:
${__P(req_per_sec,)}
or add User Defined Variables configuration element and declare req_per_sec global variable with the value of ${__P(req_per_sec,)} if you're using this ${req_per_sec} variable in more than one place:

Related

Unknown error in Repast: does not find some module?

I am launching a model that was created with an old version of repast (RepastSimphony 1.2.0) and I am trying to run it an the latest version of Repast.
I have imported manually the scenarios files to the best of my abilities (I am a beginner with Repast).
Now, when I launch the model in Repast, it has en error because it cannot find a certain file/library/module (I am unsure).
Now, I am not sure whether this is a Repast internal library or some piece of code that I should have been given and that is missing...
Any insight about this error will be welcome !
The error is this one:
WARN [AWT-EventQueue-0] 13:20:38,158 ObjectActionLoader - Error loading information from data. Continuing with model loading.
com.thoughtworks.xstream.converters.ConversionException: repast.score.impl.SGeographyImpl : repast.score.impl.SGeographyImpl
---- Debugging information ----
message : repast.score.impl.SGeographyImpl
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : repast.score.impl.SGeographyImpl
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter
path : /repast.simphony.visualization.engine.DefaultDisplayDescriptor/projections/repast.score.impl.SGeographyImpl
line number : 61
class[1] : repast.simphony.visualization.engine.DefaultDisplayDescriptor
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
version :
I traced that the attempt to load something from the scenario description:
<repast.score.impl.SGeographyImpl>
<name>PeopleGeography</name>
</repast.score.impl.SGeographyImpl>
</projections>
<valueLayers/>
<projectionDescriptors>
<entry>
<string>PeopleGeography</string>
<repast.simphony.visualization.engine.DefaultProjectionDescriptor>
<proj class="repast.score.impl.SGeographyImpl" reference="../../../../projections/repast.score.impl.SGeographyImpl"/>
<props/>
</repast.simphony.visualization.engine.DefaultProjectionDescriptor>
</entry>
</projectionDescriptors>
Incidentally, I tried to run a model from the model library (zombies) and it launches and works properly.

Some character are missing when getting properties with : java.lang.System.getProperty();

I'm trying to get value from properties but some of them contains > which seems to cause an issue...
for exemple :
I have 3 tomcat properties
-DTEST_USERNAME=admin
-DTEST_PASSWORD=Pa$$w0rd>
-DTEST_HOST=google.com
the following line :
console.log(java.lang.System.getProperty('TEST_PASSWORD'));
should return : Pa$$w0rd>
but insteed return : [console.log]<no source name> - Pa$$w0rd=google.com
is this how it's supposed to work or some kind of issue ?
should I change the password to remove the > ?
Additional information : java 8
Link to javadoc : https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getProperty-java.lang.String-
The greater than ">" is a file redirection in some terminals / shells. On Windows use double quotes around the definition:
java "-DTEST_PASSWORD=Pa$$w0rd>" ...
On Unix/Gnu/Linux/Bash use single quote or double quote with escaped \$ which avoids having $$ replaced by process id:
java '-DTEST_PASSWORD=Pa$$w0rd>' ...
java -DTEST_PASSWORD='Pa$$w0rd>' ...
java "-DTEST_PASSWORD=Pa\$\$w0rd>" ...
On later JDK versions you can validate that your settings would be passed in correctly by using -XshowSettings:properties parameter. For example, try:
java -XshowSettings:properties "-Dsomeproperty=val>ue" 2>&1 | more
Which should print:
Property settings:
...
someproperty= val>ue
I solved my issue by putting the Pa$$w0rd> in Base64
-DTEST_PASSWORD=UGEkJHcwcmQ+
and then decoding the value in javascript with return : Pa$$w0rd>

Thorntail load external properties from Java Properties file

Thorntail using project-defaults.yaml
Using the below command line arguments to start the application.
Trying to pass location of a Java .properties file to use as system properties.
java -jar application-thorntail.jar -P ../config/application.properties -P ../config/application-dev.properties -s ../config/project-defaults.yaml
Property key value in
application.properties
mail.smtp.password=testpass
tds.username=username
In yaml i want to evaluate the value as below
mail:
mail-sessions:
default:
smtp-server:
username: ${mail.smtp.user}
password: ${mail.smtp.password}
outbound-socket-binding-ref: mail-smtp
jndi-name: java:jboss/mail/Default
However, on a statup values are not getting evaluated
Error getting subresources for ConnectionDefinitions
java.lang.RuntimeException: Failed to adopt value java.lang.String
at org.wildfly.swarm.config.runtime.invocation.EntityAdapter.fromEntity(EntityAdapter.java:346)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:33)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshal(Marshaller.java:23)
at org.wildfly.swarm.container.runtime.marshal.SubsystemMarshaller.marshal(SubsystemMarshaller.java:59)
at org.wildfly.swarm.container.runtime.marshal.SubsystemMarshaller$Proxy$_$$_WeldClientProxy.marshal(Unknown Source)
at org.wildfly.swarm.container.runtime.marshal.DMRMarshaller.marshal(DMRMarshaller.java:70)
at org.wildfly.swarm.container.runtime.marshal.DMRMarshaller$Proxy$_$$_WeldClientProxy.marshal(Unknown Source)
at org.wildfly.swarm.container.runtime.RuntimeServer.start(RuntimeServer.java:194)
at org.wildfly.swarm.container.runtime.RuntimeServer$Proxy$_$$_WeldClientProxy.start(Unknown Source)
at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$bootstrap$1(ServerBootstrapImpl.java:159)
at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:43)
at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:113)
at org.wildfly.swarm.Swarm.start(Swarm.java:401)
at org.wildfly.swarm.Swarm.main(Swarm.java:745)
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.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:57)
at org.wildfly.swarm.bootstrap.Main.run(Main.java:134)
at org.wildfly.swarm.bootstrap.Main.main(Main.java:87)
Caused by: java.lang.IllegalStateException: Failed to resolve expression: ${tds.username}
at org.jboss.dmr.ValueExpressionResolver.resolve(ValueExpressionResolver.java:128)
at org.jboss.dmr.ValueExpression.resolveString(ValueExpression.java:163)
at org.jboss.dmr.ValueExpression.resolveString(ValueExpression.java:153)
at org.wildfly.swarm.config.runtime.invocation.SimpleTypeAdapter.toDmr(SimpleTypeAdapter.java:22)
at org.wildfly.swarm.config.runtime.invocation.EntityAdapter.fromEntity(EntityAdapter.java:343)
... 26 more
Well, first of all you defined your property as tds.username, but you are tring to access it as mail.smtp.user.
If this was just a mistake when writing the example, maybe you could try using ${env.XXX}.
Change your property file from mail.smtp.user to MAIL_SMTP_USER and then, on project-defaults, use username: ${env.MAIL_SMTP_USER}.
If this works, you could even propose a default value (in the example below, "defaultusername"):
username: ${env.MAIL_SMTP_USER:defaultusername}
Important to note that I don't have the tools to test it.

com.thoughtworks.xstream.converters.ConversionException

[EDITED]
The project i'm working on is a 3 folder project in Java J2EE with servlets and Hibernate for the persistance. The structure is as follow: - Admin -> the main program with the beans and HTML/CSS - Jar -> with the jars, Hibernate tools and classes - War -> with the Servlets
Between them, I use Xstream to share the classes and important info.
I'm using Eclipse and Tomcat 7.
Hope that with this all of you get the global idea.
This what the Xstream debugger said:
Caused by: com.thoughtworks.xstream.converters.ConversionException: satdata.musicoterapia.hibernate.Terapeuta0 : satdata.musicoterapia.hibernate.Terapeuta0
---- Debugging information ----
message : satdata.musicoterapia.hibernate.Terapeuta0
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : satdata.musicoterapia.hibernate.Terapeuta0
class : satdata.musicoterapia.hibernate.Usuario
required-type : satdata.musicoterapia.hibernate.Usuario
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /list/Usuario[2]/terapeuta
class[1] : java.util.ArrayList
converter-type[1] : com.thoughtworks.xstream.converters.collections.CollectionConverter
version : null
Links (I don't have enough reputiation for have more than 2 links):
Complete StackTrace: http://pastebin.com/6vXyD6hC
XML: http://pastebin.com/YM9q3uvq
Servlet: below, in the comment
Where the problem occurs: below, in the comment
Java classes: below, in the comment
If something is missing, ask and I'll put it here. Thanks for all!!!
In your servlet code you are are mentioning :
xstream.alias("Terapeuta", Terapeuta.class);
In XML file it is given as:
<terapeuta class="satdata.musicoterapia.hibernate.Terapeuta0" resolves-to="Terapeuta">
So in logs you are getting error as:
The exception in logs says:
com.thoughtworks.xstream.mapper.CannotResolveClassException:
satdata.musicoterapia.hibernate.Terapeuta0
it seems your class namein MXL should be satdata.musicoterapia.hibernate.Terapeuta
satdata.musicoterapia.hibernate.Terapeuta0

Calling system() or IPC::Run3 commands from perl don't seem to pass environment variable ($ENV{JAVA_HOME})

I've been struggling with launching a java process from perl. The root of the problem is that the java process is missing the JAVA_HOME environment variable causing a ClassNotFoundException.
I started by using IPC::Run3 because of its relatively elegant redirection of STDIN/STDOUT.
Assuming IPC::Run3 would use %ENV, I tried adding $ENV{JAVA_HOME}.
When that didn't work I tried doing system(). That didn't work, so finally, I got it to work using system("JAVA_HOME=/path/to/java && /path/to/java_program");
My test program is below. Naturally I'd uncomment the proper block to test the appropriate invocation.
#!/usr/bin/perl -w
use strict;
use IPC::Run3;
use vars qw(%Config $nutch_stdout $nutch_stderr);
%Config = (
'nutch_binary' => q[/home/crawl/nutch/runtime/local/bin/nutch],
'nutch_crawl_dir' => q[/home/crawl/nutch-crawl/crawl/crawldb/current/part-00000],
'nutch_seed_dir' => q[/home/crawl/urls],
'solr_url' => q[http://localhost:8080/solr],
);
my #nutch_command = ("$Config{nutch_binary}",
"crawl $Config{nutch_seed_dir}",
"-solr $Config{solr_url}",
"-d $Config{nutch_crawl_dir}",
"-threads 1",
"-depth 1");
$ENV{JAVA_HOME} = '/usr/lib/jvm/java-1.6.0';
while ((my $key,my $value) = each %ENV) {
print "$key=$value\n";
}
print "Running #nutch_command\n";
# My original code. Next few lines are shown in first batch of output below.
#run3 \#nutch_command, undef, \$nutch_stdout, \$nutch_stderr;
#print "Output from Nutch:\n";
#print $nutch_stdout;
#print "Errors from Nutch:\n";
#print $nutch_stderr;
# Second try. The next line's output is the second batch of output.
#system(#nutch_command);
# Third try. Despite setting and displaying %ENV, this is the only thing I tried that worked
system("JAVA_HOME=/usr/lib/jvm/java-1.6.0 && #nutch_command");
Here's the output of running the run3:
-bash-3.2$ ./test.pl
... [snip] ...
JAVA_HOME=/usr/lib/jvm/java-1.6.0
... [snip] ...
Running /home/crawl/nutch/runtime/local/bin/nutch crawl /home/crawl/urls -solr http://localhost:8080/solr -d /home/crawl/nutch-crawl/crawl/crawldb/current/part-00000 -threads 1 -depth 1
Output from Nutch:
Errors from Nutch:
Exception in thread "main" java.lang.NoClassDefFoundError: crawl
Caused by: java.lang.ClassNotFoundException: crawl
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: crawl. Program will exit.
And the output of the first system() call:
-bash-3.2$ ./test.pl
... [snip] ...
JAVA_HOME=/usr/lib/jvm/java-1.6.0
... [snip] ...
Running /home/crawl/nutch/runtime/local/bin/nutch crawl /home/crawl/urls -solr http://localhost:8080/solr -d /home/crawl/nutch-crawl/crawl/crawldb/current/part-00000 -threads 1 -depth 1
Exception in thread "main" java.lang.NoClassDefFoundError: crawl
Caused by: java.lang.ClassNotFoundException: crawl
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: crawl. Program will exit.
Finally, the third system call-- the only one that worked!-- with the environment variable set inline:
-bash-3.2$ ./test.pl
... [snip] ...
JAVA_HOME=/usr/lib/jvm/java-1.6.0
... [snip] ...
Running /home/crawl/nutch/runtime/local/bin/nutch crawl /home/crawl/urls -solr http://localhost:8080/solr -d /home/crawl/nutch-crawl/crawl/crawldb/current/part-00000 -threads 1 -depth 1
crawl started in: crawl-20120216133832
... continue success stdout output
Finally to the question: Aside from having to set the environment in-line with the system() call, what's the appropriate way to pass an environment var to a IPC::Run3 or a system() call?
(Note: output of %ENV is truncated to only relevant lines... lines like PATH, SHELL, _, etc. not relevant to the question omitted)
In case it's relevant:
-bash-3.2$ uname -a
Linux hostname 2.6.18-238.el5xen #1 SMP Thu Jan 13 16:41:45 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
-bash-3.2$ perl --version
This is perl, v5.8.8 built for x86_64-linux-thread-multi
The root of the problem is that the java process is missing the JAVA_HOME environment variable causing a ClassNotFoundException.
REVISED
That is not the root of the problem. In fact, Java itself does not require JAVA_HOME to be set.
The immediate cause of the problem is one of the following:
The wrapper is not setting the classpath correctly for the application that you are trying to execute.
The wrapper using the wrong class name. The class name "nutch" is unusual and suspicious - there's no package name.
It seems likely that the real root cause is that you are assembling the argument list incorrectly. Each of those arguments with a space inside them should really be two arguments; i.e.
my #nutch_command = ("$Config{nutch_binary}",
"crawl", "$Config{nutch_seed_dir}",
"-solr", "$Config{solr_url}",
"-d", "$Config{nutch_crawl_dir}",
"-threads", "1",
"-depth", "1");
I suspect that this has confused the nutch wrapper script, and caused it to use the wrong classname (among other things). When you pass the entire command as one string and let the shell parse it, the problem (naturally) goes away.

Categories