JMeter go back to previous sampler - java

I am quite new to jmeter, I am using it to load test an application. My current setup is good if running few threads at a time but gets problems when more users get connected.
Here's the scenario,
sample_1: request table data
sample_2: set table row with empty user column as used by current user
|
'-->post_process_beanshell: check if have error message
sample_3: do other stuff
Currently I am able to check if the 2nd sample has an error message, the question is how do I tell beanshell to go back to 1st sample when the 2nd sample has an error message?

I would recommend put your "sample_3" under If Controller like:
Loop Controller (define maximum number of n-tries)
sample_1
sample_2
post_process_beanshell
If Controller: condition ${JMeterThread.last_sample_ok}
sample_3
JMeterThread.last_sample_ok - is a pre-defined variable which returns "true" if previous sampler was successful and "false" if not so if your "sample_2" will fail - "sample_3" won't be executed and the whole sequence will start over

Assuming you want to keep going back to sampler1 until sampler2 beanshell returns true, use a While controller.
Stick both sampler1 and sampler2 in a while controller which is conditional on the result of your error check.

Related

Simple GET request with Facebooks API

I am currently taking a course in app development and I am trying to use Facebooks API for GET requests on certain events. My goal is the get a JSON file containing all comments made on a certain event.
However some events return only a an "id" key with an id number such as this:
{
"id": "116445769058883"
}
That happends with this event:
https://www.facebook.com/events/116445769058883/
However other events such as (https://www.facebook.com/events/1964003870536124/) : returns only the latest comment for some reason.
I am experementing with facebook explore API:
https://developers.facebook.com/tools/explorer/
This is the following GET requests that I have been using in the explorer:
GET -> /v.10/facebook-id/?fields=comments
Any ideas? It's really tricky to understand the response since both events have the privacy set to OPEN.
Starting from v2.4 of the API, the API is now declarative which means you'll need to specify what fields you want the API to return.
For example, if you want first name and second name of the user, then you make a GET request to /me?fields=first_name,last_name else you will only get back the default fields which are id and name.
If you want to see what fields are available for a given endpoint, use metadata field. e.g. GET /me?metadata=true

how to create execution plan where exported stream and siddhi query insert into have the same name?

I tried creating a plan using the example provided in this link Create execution Plan but I get the following error.
Stream OutStats is already defined as StreamDefinition{streamId='OutStats', attributeList=[Attribute{name='meta_ip', type=STRING}, Attribute{name='userName', type=STRING}, Attribute{name='requestCount', type=LONG}]}, hence cannot define StreamDefinition{streamId='OutStats', attributeList=[Attribute{name='meta_ip', type=STRING}, Attribute{name='userName', type=STRING}, Attribute{name='searchKey', type=STRING}]}
If I change the insert into part of the query to some other name it works fine,but I'm worried it might create problems if the exported stream name and insert into aren't the same. I created both org.foo.data.search.stats and org.foo.data.out.stats before creating the execution plan.
Is this a bug or am I doing something wrong?
Also their own test case also gives the same error. Link : EventFlowTestCase
In the first stream you have Attribute{name='requestCount', type=LONG}
and in the second stream Attribute{name='searchKey', type=STRING}.
This error in your situation means that "The 4-th attribute in defined stream is not the same as 4-th attribute in input/output/other etc. stream".
Remeber, name, type and order does matter.

Creating a filter to check a case for a letter in a field in the json body in REST assured

I have a request in the form of json,which looks like this.
{"User":{"email":"test#test.com","FName":"fname"}}
When I try to send it via REST assured ,the U in the User is seen to change its case.i.e. changes to a lower case.
To send the request I have created my own serialized classes. The end-point is seen like this:
{"user":{"email":"test#test.com","FName":"fname"}}
but somehow it is not changing the case of the remaining fields.I don't knwo why this is happening.
I've even tried to create a filter for a request specification,but couldn't go any further with that too. I also then thought of first converting the serialized object to a gson,and then check the case of the User, still no luck.
Error I get is:
The class, User,does not match the payload object for payload.
Please note I am trying to use the service of another team,so I really don't have an access to their code-base(Although not needed).Observe the space between the first , and user in the above message, is it worth noting?
I finally got away with it by converting the object(JSON) into a JSON string/payload.
And while passing it as a form parameter,passed the string/payload.
Somehow,still couldn't figure out why the formparameter/formparam option in RESTAssured did not allow the serialized object to go through. But,anyway got around it this time.
Thanks for the suggestions all.

Drools render output in a webpage

I'm new to Drools Expert, currently from the Sample project of the drools what I can only do is print something to the console. Now I integrate drools to a web project and It was successful, I was be able to print something to the console depending on the interaction of the user to the page.
My rules currently is like this:
rule "A test Rule"
when
m: FLTBean ( listeningScore == 1, test : listeningScore )
then
System.out.println( test );
end
So what if I want to print it out to a web page? How would I do that? Do I need to use return to return some value back to the java page and render it to the page?
In order to display something on a web page, then you need to be using the API to invoke Drools and get some output, which can then be rendered by your web application.
Therefore, you need to consider how to get output from it within your Java code. There are a few ways of doing this.
For example, when performing a simple action such as validating a request, then just operate on the request which you insert. For instance:
rule "IBAN doesn't begin with a country ISO code."
no-loop
when
$req: IbanValidationRequest($iban:iban, $country:iban.substring(0, 2))
not Country(isoCode == $country) from countryList
then
$req.reject("The IBAN does not begin with a 2-character country code. '" + $country + "' is not a country.");
update($req);
end
In that example, I'm calling a "reject" method on the fact which I inserted. That modifies the inserted fact, so that after rules execution, I have an object in my Java code, with a flag to indicate whether it was rejected or not. This method works well for stateless knowledge sessions. i.e.
Java code - Insert request fact via API
Drools rule - Modify the request fact (flag rejection, annotate, set properties, etc)
Java code - Look at the fact to see what was done to it
The following code example of how to perform this interaction is taken from the following full colass:
https://github.com/gratiartis/sctrcd-payment-validation-web/blob/master/src/main/java/com/sctrcd/payments/validation/payment/RuleBasedPaymentValidator.java
// Create a new knowledge session from an existing knowledge base
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
// Create a validation request
PaymentValidationRequest request = new PaymentValidationRequest(payment);
// A stateless session is executed with a collection of Objects, so we
// create that collection containing just our request.
List<Object> facts = new ArrayList<Object>();
facts.add(request);
// And execute the session with that request
ksession.execute(facts);
// At this point, rules such as that above should have been activated.
// The rules modify the original request fact, setting a flag to indicate
// whether it is valid and adding annotations to indicate if/why not.
// They may have added annotations to the request, which we can now read.
FxPaymentValidationResult result = new FxPaymentValidationResult();
// Get the annotations that were added to the request by the rules.
result.addAnnotations(request.getAnnotations());
return result;
An alternative in a stateful session would be that rules could insert facts into working memory. After executing the rules, you can then query the session via the API and retrieve one or more result objects. You can get all facts in the session using the getObjects() method of the KnowledgeSession. To get facts with particular properties, there is also a getObjects(ObjectFilter) method. The project linked below has examples of using these methods in the KnowledgeEnvironment and DroolsUtil classes.
Alternatively, you could insert a service as a global variable. The rules could then invoke methods on that service.
For an example of how to use Drools within a web application, I knocked up this web site recently, which provides a REST API to invoke Drools rules and get responses.
https://github.com/gratiartis/sctrcd-payment-validation-web
If you have Maven installed, you should be able to try it out pretty quickly, and play around with the code.

NullPointerException when re-running a test

I am unit testing a Play Framework based application. As I read in the documentation, for the sake of clearing the state, before every test I reload the list of fixtures like this:
#Before
public void setUp() {
Fixtures.deleteAll();
Fixtures.load("data.yml");
Logger.info("FIXTURES RELOADED");
}
Then I go to the Web.based testing platform (http://localhost:9000/#tests), choose a test that deals with fetching some data (User u = User.findById(1l);) and then assert against the data. It works.
However, if I try to select the test again, and rerun it, it fails with:
A java.lang.NullPointerException has been caught, Try to read name on null object models.User
If I stop the application completely and restart it, it runs again (the first time), but starting and stopping takes a bit of time and is quite tedious, if you do it 10 times a minute.
I am using Play 1.2.5
The problem is auto-incrementing user ID (on every insert) while trying to get user with ID 1 on every test.
You can get the newly created user ID and use it in your test or find user by other field that you definitely know.

Categories

Resources