Jmeter: Running the nongui command using java - jmeter

I am trying to run the jmeter nongui command using java as follows:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\apache-jmeter-2.13\\bin\\jmeter.bat -t \"C:\\jmeter scripts\\test.jmx\" -n -l \"C:\\jmeter scripts\\nonGUI.csv\"");
It runs perfectly fine, until I add the argument:
-Jusers=15 inside the command mentioned above in the next run.
The property set for the number of threads is: ${__P(users,10)}
The result file does not seem to fill up and the process seems to run forever under the CPU Resource monitor.
P.S.: Please do not suggest me to run the jmeter file using the steps given in the blazemeter website. It has used one of the deprecated method and there is no resolution given for the plausible runtime errors in that website.

I was not able to reproduce your error, but here is a complete example with JMX File. I removed the need for the "".
// OSX exmaple
public class r {
public static void main(String[] args) throws Exception {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("/usr/local/bin/jmeter -t /Users/rfriedman/jmeter/SimpleUrl.jmx -Jusers=15 -n -l /Users/rfriedman/jmeter/nonGUI.csv");
}
}
Just to make sure I ran modified on Windows as well
// Windows Example
public class r {
public static void main(String[] args) throws Exception {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\Users\\rfriedman\\Desktop\\apache-jmeter-2.13\\bin\\jmeter.bat -t C:\\Users\\rfriedman\\Desktop\\SimpleUrl.jmx -Jusers=20 -n -l C:\\Users\\rfriedman\\Desktop\\nonGUI.csv");
}
}
JMeter Test Plan

It works after I add the property value for Synchronization timer similar to Thread count.
Also, if I have to pass the value of -Jusers in the form of variable, how to do it? I am trying to do the following. But it's not getting executed.
eg:
int value=10;
Process pr = rt.exec("C:\Users\rfriedman\Desktop\apache-jmeter-2.13\bin\jmeter.bat -t C:\Users\rfriedman\Desktop\SimpleUrl.jmx -Jusers=value -n -l C:\Users\rfriedman\Desktop\nonGUI.csv");
Update:
I tried with String value="10"; as well. Still the jmeter logs says:
"jmeter.reporters.Summariser: summary = 0 in 0s = ******/s Avg: 0 Min: 9223372036854775807 Max: -9223372036854775808 Err: 0 (0.00%)"

Use this snippet.
int value = 10;
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\apache-jmeter-2.13\\bin\\jmeter.bat" +
" -t \"C:\\jmeter scripts\\test.jmx\" -Jusers=" + value + " -Jsync=" + value +
" -n -l \"C:\\jmeter scripts\\nonGUI.csv\" -j \"C:\\jmeter scripts\\jmeterLogs.log\"");

Related

jcraft execute shell command returns exit status 127

I am trying to run shell script
(/sasdata/sasconfig/Lev1/Applications/SASEnterpriseGRCAdminTools/6.1/dbscripts/addxlsdata.sh -t /sasdata/Data/Loaders/IFT_tst_loader2.xls)
on remote server with java, using jcraft, but in answer I have exit status 127. I tried to run simple command "date" with my method - and all was good. Then I tried to run this script by entering command in terminal, and all was ok too. Also I tried to execute "cd" to path with addxlsdata.sh and there run
./addxlsdata.sh -t /sasdata/Data/Loaders/IFT_tst_loader2.xls
and again there was 127 exit status.
What the problem it can be?
Here is my method:
public static void executeShell(String shellScriptCommand, String userName, String password, String server) {
List<String> result = new ArrayList<String>();
try {
LOG.info("Creating session, user: " + userName);
JSch jSch = new JSch();
Session session = jSch.getSession(userName, server, sshPort);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
LOG.info("Opening exec channel");
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
LOG.info("Creating InputStream");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("sh " + shellScriptCommand);
LOG.info("Executing the shell script: " + shellScriptCommand);
channelExec.connect();
LOG.info("Reading the output from the input stream");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
CommonFunctions.freeze(3);
while (reader.ready()) {
String line = reader.readLine();
result.add(line);
}
reader.close();
LOG.info("OUTPUT is " + result);
LOG.info("Getting exit status");
int exitStatus = channelExec.getExitStatus();
LOG.info("Exit status is [" + exitStatus + "]");
channelExec.disconnect();
session.disconnect();
} catch (JSchException | IOException e) {
LOG.error(Arrays.toString(e.getStackTrace()));
throw new AutotestError("Ошибка при выпонении shell скрипта", e);
}
}
I find out one thing. This *.sh file have another script inside "./runjava.sh". Maybe here is the problem
It seems that it is my fault in connect to wrong server. Despite that I use the same address in java and winscp, when I use ls in directory with the script in java and in terminal, I have different results
I think that I have found what the problem. When I execute "cd /" in java and then "pwd", the output is "/home/username". I can't exit from Home directory to root in java. In terminal I can do this with the same user
Your java application has not permission to execute the script. Add the account (which run your java application) to the group which has ownership to script ./addxlsdata.sh. Also provide necessary execute permission as well.
First go to the directory and execute ls -ltr and provide the detail information to your Unix admin and also provide the user id detail which run the java application to add that user to the proper group. It will work once you short out this.
It was my terrible fault. I invoked my method several times with different commands. I was running executeShell "cd /" and then executeShell "pwd". And of course second time it was a new session.

Is it possible to generate UUID v1 with JMeter?

I read JMeter's manual and saw that there is __uuid() function for JMeter. It allows to generate UUID type 4 for JMeter tests. Is it possible to generate UUIDv1 in JMeter or maybe some plugin exists.
I would recommend taking the following steps:
Download Jug library (for example from here) and drop the .jar somewhere to JMeter Classpath
Restart JMeter to pick the .jar up
Once done you should be able to generate UUIDv1 using JSR223 Test Elements and Groovy language like:
import com.fasterxml.uuid.EthernetAddress
import com.fasterxml.uuid.Generators
import com.fasterxml.uuid.impl.TimeBasedGenerator
def addr = EthernetAddress.fromInterface()
def gen = Generators.timeBasedGenerator(addr)
def v1uuid = gen.generate()
log.info(v1uuid.toString())
Demo:
References:
Generating version 1 UUIDs
Groovy is the New Black
In jmeter you can add JSR 223 Sampler choose Java language and execute java code for UUID version 1:
String timeuuid = com.datastax.driver.core.utils.UUIDs.timeBased().toString();
And then add it to Jmeter variable:
vars.put("myUUID", timeuuid);
First, we'll generate the 64 least and most significant bits as long values:
private static long get64LeastSignificantBitsForVersion1() {
Random random = new Random();
long random63BitLong = random.nextLong() & 0x3FFFFFFFFFFFFFFFL;
long variant3BitFlag = 0x8000000000000000L;
return random63BitLong + variant3BitFlag;
}
private static long get64MostSignificantBitsForVersion1() {
LocalDateTime start = LocalDateTime.of(1582, 10, 15, 0, 0, 0);
Duration duration = Duration.between(start, LocalDateTime.now());
long seconds = duration.getSeconds();
long nanos = duration.getNano();
long timeForUuidIn100Nanos = seconds * 10000000 + nanos * 100;
long least12SignificatBitOfTime = (timeForUuidIn100Nanos & 0x000000000000FFFFL) >> 4;
long version = 1 << 12;
return
(timeForUuidIn100Nanos & 0xFFFFFFFFFFFF0000L) + version + least12SignificatBitOfTime;
}
We can then pass these two values to the constructor of the UUID:
public static UUID generateType1UUID() {
long most64SigBits = get64MostSignificantBitsForVersion1();
long least64SigBits = get64LeastSignificantBitsForVersion1();
return new UUID(most64SigBits, least64SigBits);
}

Spark submit using mesos dcos cli

I'm trying to start a spark streaming job on mesos using the DCOS cli.
I'm able to start the job. My program expects a config file to be passed as cli parameter. How do I achieve this with dcos spark run --submit-args?
I tried --files http://server/path/to//file hoping it will download files but that didn't work. Driver starts but fails because config file is missing.
I also tried to roll up the jar and config file as tar and submitted it. I can see in Mesos logs that the tar was fetched and untar. Both config and jar file are seen in the working directory. But job fails with ClassNotFoundException. I suspect something was not right about how spark-submit was started.
dcos spark run --submit-args="--supervise --deploy-mode cluster --class package.name.classname http://file-server:8000/Streaming.tar.gz Streaming.conf"
Any hint on how to proceed? Also, in which log file can I see the underlying spark-submit command used by DCOS?
Here is the example of a command you should launch in order to make it work:
dcos spark run --submit-args='--conf spark.mesos.uris=https://s3-us-west-2.amazonaws.com/andrey-so-36323287/pi.conf --class JavaSparkPiConf https://s3-us-west-2.amazonaws.com/andrey-so-36323287/sparkPi_without_config_file.jar /mnt/mesos/sandbox/pi.conf'
Where
--conf spark.mesos.uris=... A comma-separated list of URIs to be downloaded to the sandbox when driver or executor is launched by Mesos. This applies to both coarse-grained and fine-grained mode.
/mnt/mesos/sandbox/pi.conf A path to the downloaded file which your main class receives as a 0th parameter (see the code snippet below). /mnt/mesos/sandbox/ is a standard path inside a container which is mapped to a corespondent mesos-task sandbox.
public final class JavaSparkPiConf {
public static void main(String[] args) throws Exception {
SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi");
JavaSparkContext jsc = new JavaSparkContext(sparkConf);
Scanner scanner = new Scanner(new FileInputStream(args[0]));
int slices;
if (scanner.hasNextInt()) {
slices = scanner.nextInt();
} else {
slices = 2;
}
int n = 100000 * slices;
List<Integer> l = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
l.add(i);
}
JavaRDD<Integer> dataSet = jsc.parallelize(l, slices);
int count = dataSet.map(new Function<Integer, Integer>() {
#Override
public Integer call(Integer integer) {
double x = Math.random() * 2 - 1;
double y = Math.random() * 2 - 1;
return (x * x + y * y < 1) ? 1 : 0;
}
}).reduce(new Function2<Integer, Integer, Integer>() {
#Override
public Integer call(Integer integer, Integer integer2) {
return integer + integer2;
}
});
System.out.println("Pi is roughly " + 4.0 * count / n);
jsc.stop();
}
}
Streaming.conf is just a string that will be passed to your driver. Your driver must be able to see it. The easiest way to do this is to place it in an accessible location, the specify that you want it downloaded to the sandbox via spark.mesos.uris [1]. You could alternately write your application to support reading from a remote location, and just pass the location on the CLI.
--files is used to place files at the executors, but you're trying to pass a file to the driver, so that won't work.
[1] http://spark.apache.org/docs/latest/running-on-mesos.html
Michael Gummelt
Mesosphere

Executing shell commands through beanshell in jmeter

Executing shell commands through beanshell in jmeter. I want to execute shell commands in beanshell preprocessor in jmeter
Can any one tell how to do so.
Beanshell is JAVA (scripting language).
Below statement should help.
Runtime.getRuntime().exec("COMMAND");
Based on #vins answer I cloud create my ping test to verify my email server is available.
Additionally if you want to log the output of the Runtime.getRuntime().exec("COMMAND"); use something similar to this in your jmeter BeanShell Sampler:
// ********
// Ping the email server to verify it's accessible from the execution server
//
// Preconditions:
// custom variable is available named "emailServer" which contains the IP-Adress of the machine to ping
//
// ********
log.info(Thread.currentThread().getName()+": "+SampleLabel+": Ping email server: " + vars.get("emailServer"));
// Select the ping command depending on your machine type windows or Unix machine.
//String command = "ping -n 2 " + vars.get("emailServer"); // for windows
String command = "ping -c2 " + vars.get("emailServer"); // for Unix
// Print the generated ping command
log.info(command);
// Create a process object and let this object execute the ping command
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
log.info("Execution complete.");
// Read the output of the ping command and log it
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder logCommandOutput = new StringBuilder();
String line;
while( (line = in.readLine()) != null) {
logCommandOutput.append(line);
}
in.close();
log.info("Output: " + logCommandOutput.toString());

D: executeShell on Windows to run another program not returning immediately

I'm using D as a scripting language for Windows 7 console stuff to automate boring tasks. One of my scripts (open.exe) is supposed to allow me to open stuff from the command line without me having to specify which program I use (I have a configuration file with this stuff). Now, I use executeShell to do this, and call something like start [name of program I want to use] [name of input file]. If I do this directly from the shell, it returns immediately, but if I do it using my D script, it doesn't return until the program that it opens is closed. What should I do to allow it to return immediately?
For reference purposes, this is the business logic of my script (the main method just does some argument parsing for piping purposes):
immutable path = "some//path//going//to//config//file.conf";
void process(string input) {
string extension = split(input,".")[1]; //get file extension from input
auto config = File(path,"r"); auto found = false;
while (!config.eof()){
auto line = chomp(config.readln());
if (line[0]!='#') { //skip comment lines
auto divided = split(line, ":");
if (divided[0] == extension) {
found = true;
auto command = "start " ~ divided[1] ~ " " ~ input;
auto result = executeShell(command);
//test for error code and output if necessary
writeln(result.output);
}
}
}
if (!found)
writeln("ERROR: Don't know how to open " ~ input);
}
From the top of the std.process documentation:
Execute and wait for completion, collect output - executeShell
The Windows start program spawns a process and exits immediately. D's executeShell does something else. If you'd like to spawn another program, use the appropriate functions: spawnProcess or spawnShell.

Resources