Unanswered question

use of java.time.Instant in javascript

How might I convert this beanshell preprocessor script in jmeter to neoload javascript?

import java.time.Instant;
String epoc = Long.toString(Instant.now().toEpochMilli());
vars.put("sequence", epoc);

In neoload I will use,
context.variableManager.setValue("sequenceNumber",epoc);

but I get error on the use of import statement.

rob J.
rob J.

rob J.

Level
0
3 / 100
points

Answers

rob J.
rob J.

rob J.

Level
0
44 / 100
points

Still have issue, but this is perhaps just a general question of how do use standard java classes like java.time in a neoload script?

Neil W.
Neil W.

Neil W.

Level
4
5000 / 5000
points
Team

Neoload javascript can call Java classes. Export your Java as a jar file and drop it into the lib/jslib folder of your project.

rob J.
rob J.

rob J.

Level
0
44 / 100
points

Since java.time.Instant is within Java SE not some custom class (https://docs.oracle.com/javase/8/docs/api/java/time/Insta...) , how can I add just that?

Neil W.
Neil W.

Neil W.

Level
4
5000 / 5000
points
Team

I only dabble with java, but your class imports the Java SE java.time.instant class, when you create a jar I would assume all the dependancies would also be in the jar? then you can just delare your method in the java script.

Not directly related to your question but it seems that your goal is to get the current time in milliseconds. Why don't you use the NeoLoad "current date" variable and choose the milliseconds format from the drop down list?

Susan W.
Susan W.

Susan W.

Level
1
234 / 750
points

Did you get this working rob J.? I'm looking to parse an ISO 8601 timestamp and instant is now recommended but I can't see how to import the JAR if it's within Java 8 SE already...