I use Gatling Java to write a performance test.
I have a session variable 'VAR_X' with a value of 'Jerry'.
My code has a 'post()' method that sends a request. It uses a custom feeder to provide a body for the request.
public ChainBuilder post() {
List<String> requestBodyList = new ArrayList<String>();
Iterator<Map<String, Object>> feeder =requestBodyList.add(Collections.singletonMap("REQUEST_BODY", (Object) "my_config { x: #{VAR_X} }")).iterator();
return feed(feeder)
.exec(http("Post request"))
.post("x_resource/")
.body(StringBody("#{REQUEST_BODY}"))
}
Currently my code results in the request body to be "my_config { x: #{VAR_X} }".
I would like the value of session variable 'VAR_X' to get inserted into the request body, by using Gatling Expression Language (GEL).
The desired request body should be:
"my_config { x: Jerry }"
How can I change my code to achieve that?
That's not possible. Gatling Expression Language is intended as a simple solution for simple use cases.
For more complex use cases, you have to switch to using functions and the Session API.
Related
Runnable returns void in Java. Why does Mono.fromRunnable return Mono<T> instead of Mono<Void>?
API documentation of Mono#fromRunnable states about the type parameter:
The generic type of the upstream, which is preserved by this operator
It allows to use it as part of an operation chain without altering the resulting type.
Example:
This code:
Mono<String> myMono = Mono.empty();
myMono = myMono.switchIfEmpty(Mono.fromRunnable(()
-> System.err.println("WARNING, empty signal !")));
String value = myMono.block(Duration.ofSeconds(1));
System.out.println("Exported value is "+value);
Produces:
WARNING, empty signal !
Exported value is null
The code above compiles fine, and provide a Mono for a String without having to add additional casts.
The posted example is not very good, but I suppose that this signature allows to use fromRunnable to launch side-effects in some case, without disturbing value type of the overall operation chain.
It's kinda like Mono.empty() with additional computing embedded with it.
what are the changes that I need to make if I am using jdk 7 and want to use lambda expression?
I am comparing 2 xml files and want to ignore specific nodes hence using this expression
final Diff documentDiff = DiffBuilder
.compare(expectedSource)
.withTest(actualSource)
.withNodeFilter(node -> !node.getNodeName().equals(someName))
.build();
error: Syntax error on token '-',-- expected
Try this.
final Diff documentDiff = DiffBuilder
.compare(expectedSource)
.withTest(actualSource)
.withNodeFilter(new Predicate<Node>() {
#Override
public boolean test(Node node) {
return !node.getNodeName().equals(someName);
}
})
.build();
This is redundant, but JDK7 will accept it.
I don't know if you can realize what you want to do with this.
lambda expression can not be used in java 7. The syntax itself is only allowed in java8. However the functionality you can achieve by writing more code or with out using lamda expression. You need to write a filter method which checks the name of node with someName if it returns true then proceed with building document Difference. You will need to write multiple statement and if case to check name equality.
You can also achieve this using xslt. which is very fast for long xml files but then you will need to write a lot of code as xslt is declarative and based upon functional programming.
I wanted to know if you guys do know if it is possible in Scala to make a call to a Java REST client function which takes #FormParam params.
If my function in the Java client is this :
#Path("registerEmail")
#POST
public RegisterEmailResult doRegisterEmail(#FormParam("email") final String email, #FormParam("password") String password/* Some other params */) {
How can I pass some #FormParam params in Scala ? I tried this :
def registerEmail(registerEmail: RegisterEmail): Future[Boolean] =
post(
url("/theUrl/registerEmail"),
new Gson().toJson(registerEmail)
).map {
case data => true
}.recover {
case _ => false
}
The RegisterEmail model has all the field of the parameters of the Java function.
Did I miss something ? Otherwise I will have to do the Java function again with like #QueryParams, it seems to be maybe a better way.
It is simpler to understand your code if you include part of your imports as well. The url (which I assume is Play's play.api.libs.ws.WS.url(...)) can be utilised like this to pass form data:
WS.url("/theUrl/registerEmail")
.post(Map("email" -> Seq("someone#somewhere.com"),
"password" -> Seq("secretish")))
See https://www.playframework.com/documentation/2.3.x/ScalaWS for more details (specifically search for "Submitting form data")
I need to send a request using Java to an existing REST service using GET with multiple input parameters.
If the initial url for the calculation I want is:
https://api.restservice123.com/api/calculate
I want to make a calc object e with the following parameters:
calcObj e = new calcObj();
e.token="token_ABC123";
e.country="US";
e.amount = 100;
e.price = 24;
e.customer = "bob";
the url should look something like this:
https://api.restservice123.com/api/calculate?token=token_ABC123&country=US&amount=100&price=24&customer=bob
Is there any framework that will combine the parameters from the calc object and reformat them into the url appropirate format and combine them with the api url?
I ended up making a method in the calc object that puts all the non null parameters into a list of strings and combines them using a Joiner from google common and connecting to the url using an HttpURLConnection. But this method looks bad as I'm hoping there's something out there that can already do all of this much more elegantly, but I couldn't find it.
The URIBuilder class works well for this. It has a method setParameters(java.util.List) that takes a list of name value pairs and builds a URI from them.
I am planning to implement a JavaScript parser in java. I know that there are several ways to do it. There are view frameworks/engines/parsers which could help to do it right, like:
ANTLR 3/4:
it seems like there is only a js grammer for v3
Mozilla Rhino: atm i can parse variable names on initital (top-) namespace. but i am not able to parse nested scopes e.g. object members.. hm..
Nashorn: maybe i should give it a try..?
Maybe:
closure-compiler: IMHO this is very nice. but not for "non-google" js-code :) e.g. you have to apply several coding conventions to your javascript sources to get it working properly..
maybe it is possible to adapt Packer to do it? Is there a Java implementation of Packer???
There is EcmaScript 5.1 related to this article. it seems to be very comfortable. But this is not exactly what I´am looking for.. And still no java :)
My question is:
What could/would be the best way to parse JavaScript for:
(object-)function names
(object-)member names e.g. variables
Is it even possible to do it?
What would be your approach? For me it is not essential to parse ALL special markups of JavaScript.. The important factor would be to parse function/variables in a consistent context for the typical markups like this:
// Avoid `console` errors in browsers that lack a console.
function Object() {
var method;
var noop = function() {
};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
};
var obj = new Object();
var test = "Hello World";
The parse should be able to deliver this information:
Node: Object
Node: Object.method
Node: Object.noop
Node: Object.length
Node: Object.console
Node: Object
Node: obj
Node: test
There is no direct need of any determination if the node is a function/variable.