Jmeter - how to pass cookie captured in one thread to another thread - cookies

I am trying to use same cookie(i.e. capturing cookies in main thread and trying to pass it in support threads) in different threads in Jmeter. I have already read the article give at
https://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell
but its not working in my case. Can someone please help in recognizing what mistake I am doing while implementing the logic given in above link.
please find below steps I am following
Test Plan
- HTTP Cache Manager
- HTTP Header Manager
- HTTP Cookie Manager
- Main Thread(login page under main thread)
- Login (BeanShell PostProcessor under login)
- BeanShell PostProcessor
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
props.put("cookiecount", String.valueOf(manager.getCookieCount()));
for (int i = 0; i < manager.getCookieCount(); i++)
{
props.put("cookie_name" + i, manager.get(i).getName());
props.put("cookie_value" + i, manager.get(i).getValue());
props.put("cookie_domain" + i, manager.get(i).getDomain());
props.put("cookie_path" + i, manager.get(i).getPath());
props.put("cookie_expires" + i, String.valueOf(manager.get(i).getExpires()));
props.put("cookie_secure" + i, String.valueOf(manager.get(i).getSecure()));
}
- Support Thread 1
- BeanShell PreProcessor
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.testelement.property.JMeterProperty;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
int count = Integer.parseInt(props.getProperty("cookiecount"));
for (int i = 0; i < count; i++) {
Cookie cookie = new Cookie(props.getProperty("cookie_name" + i),
props.getProperty("cookie_value" + i),
props.getProperty("cookie_domain" + i),
props.getProperty("cookie_path" + i),
Boolean.parseBoolean(props.getProperty("cookie_secure" + i)),
Long.parseLong(props.getProperty("cookie_expires" + i)));
manager.add(cookie);
}
JMeterProperty cookieprop = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager");
cookieprop.setObjectValue(manager);
ctx.getCurrentSampler().setProperty(cookieprop);
- HTTP Request
After running it for 1 thread - 1 loop getting different cookies for both threads something like below
- Main Thread
Cookie Data:
JSESSIONID=PvRSWmBXNp9y65njGkRWbLlxLM1pvxLzpnyjThQDny3pMy6Gkcjv!486373045
- Support Thread
Cookie Data:
JSESSIONID=YVGsWmQSXdGt1xqfDDvlkgkHLpqJ3WRD2sDyqXp62rChfTDbM0Vj!486373045
I have set CookieManager.save.cookies=true.

Just use 2 different HTTP Cookie Manager test elements for different thread groups.
P.S. If you already have CookieManager.save.cookies=true property set and you know cookie names - you can use __setProperty() function to pass variables which hold cookie values between thread groups like:
In 1st Thread Group convert variable to property like ${__setProperty(JSESSIONID,COOKIE_JSESSIONID,)}
In 2nd Thread Group refer the property as ${__P(JSESSIONID,)}
The approach is described in details in the How to Use Variables in Different Thread Groups article.

Related

Liferay : unable to read full value from cookies in Controller

I want read value from cookie using Java code.
Example:
I have store value in cookie . like email=abc#xyz.com
When I am trying to fetch email value from cookie using below code I am only get "abc". But I want full value "abc#xyz.com"
I am using below code
Cookie[] cookies = renderRequest.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
System.out.print("Name : " + cookie.getName( ) + ", ");
System.out.println("Value: " + cookie.getValue( ));
}
I'm not sure if the RenderRequest gives you the same cookies as the HttpServletRequest: After all, it's a portlet-request. If you have set the value yourself, and you're not getting the same value back, you probably made a mistake encoding the value when you set it.
Also, as you're obviously in a render request handler, that might be the request of someone who is logged in anyway, and there's no need to set a specific cookie: You can just get the value for the currently signed in user (unless you're looking for somebody else's mail address - however that gets stored in the cookie)

Google Apps Script / Regular expression to show only latest message in an email "train"

email train = entire contents of a single email including previous messages
email thread = a Google Apps Script array of messages
QUESTION: In Google Apps Script, how can I import only the latest email from within an email train?
I have a simple Google Apps Script based on the GmailApp class. Eventually, this will import all emails TO and FROM a given address (using a search query) into a spreadsheet:
var threads = GmailApp.search('from: test#gmail.com OR to: test#gmail.com');
Logger.log("Thread count: " + threads.length);
for (var i = 0; i < threads.length; i++) {
Logger.log("Subject:" + threads[i].getFirstMessageSubject());
Logger.log("ID:" + threads[i].getId());
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
Logger.log(messages[j].getPlainBody());
}
}
The problem with email in general is that when someone replies to an email, it includes the original text. After 5 or 6 replies, each individual message gets very long, and when importing all messages within a Gmail thread as above, there's a tonne of duplication.
The gmail.com web interface gets around this problem with the use of the ellipsis button:
How do I replicate this black magic?
I understand any given solution will be non-perfect.
My first thought is to use some kind of regular expression, but I don't know where to start.
Indeed, a regular expression can offer a non-perfect solution to this problem. For U.S. standard of time and date, the following matches the Gmail datetime string that precedes a quoted message:
var prev = /On (?:Sun|Mon|Tue|Wed|Thu|Fri|Sat), (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2}, \d{4} at \d{1,2}:\d{2} [AP]M,/;
Then in the loop, one can truncate each message starting at such datetime.
for (var j = 0; j < messages.length; j++) {
var text = messages[j].getPlainBody();
var match = text.match(prev);
if (match) {
text = text.slice(0, match.index);
}
Logger.log(text);
}
This will fail if some participants use different locale settings for Gmail. Of course one can try to adjust this, e.g., by making day-of-week and [AP]M optional.

Meteor regex find() far slower than in MongoDB console

I've been researching A LOT for past 2 weeks and can't pinpoint the exact reason of my Meteor app returning results too slow.
Currently I have only a single collection in my Mongo database with around 2,00,000 documents. And to search I am using Meteor subscriptions on the basis of a given keyword. Here is my query:
db.collection.find({$or:[
{title:{$regex:".*java.*", $options:"i"}},
{company:{$regex:".*java.*", $options:"i"}}
]})
When I run above query in mongo shell, the results are returned instantly. But when I use it in Meteor client, the results take almost 40 seconds to return from server. Here is my meteor client code:
Template.testing.onCreated(function () {
var instance = this;
// initialize the reactive variables
instance.loaded = new ReactiveVar(0);
instance.limit = new ReactiveVar(20);
instance.autorun(function () {
// get the limit
var limit = instance.limit.get();
var keyword = Router.current().params.query.k;
var searchByLocation = Router.current().params.query.l;
var startDate = Session.get("startDate");
var endDate = Session.get("endDate");
// subscribe to the posts publication
var subscription = instance.subscribe('sub_testing', limit,keyword,searchByLocation,startDate,endDate);
// if subscription is ready, set limit to newLimit
$('#searchbutton').val('Searching');
if (subscription.ready()) {
$('#searchbutton').val('Search');
instance.loaded.set(limit);
} else {
console.log("> Subscription is not ready yet. \n\n");
}
});
instance.testing = function() {
return Collection.find({}, {sort:{id:-1},limit: instance.loaded.get()});
}
And here is my meteor server code:
Meteor.publish('sub_testing', function(limit,keyword,searchByLocation,startDate,endDate) {
Meteor._sleepForMs(200);
var pat = ".*" + keyword + ".*";
var pat2 = ".*" + searchByLocation + ".*";
return Jobstesting.find({$or:[{title:{$regex: pat, $options:"i"}}, { company:{$regex:pat,$options:"i"}},{ description:{$regex:pat,$options:"i"}},{location:{$regex:pat2,$options:"i"}},{country:{$regex:pat2,$options:"i"}}],$and:[{date_posted: { $gte : endDate, $lt: startDate }},{sort:{date_posted:-1},limit: limit,skip: limit});
});
One point I'd also like to mention here that I use "Load More" pagination and by default the limit parameter gets 20 records. On each "Load More" click, I increment the limit parameter by 20 so on first click it is 20, on second click 40 and so on...
Any help where I'm going wrong would be appreciated.
But when I use it in Meteor client, the results take almost 40 seconds to return from server.
You may be misunderstanding how Meteor is accessing your data.
Queries run on the client are processed on the client.
Meteor.publish - Makes data available on the server
Meteor.subscribe - Downloads that data from the server to the client.
Collection.find - Looks through the data on the client.
If you think the Meteor side is slow, you should time it server side (print time before/after) and file a bug.
If you're implementing a pager, you might try a meteor method instead, or
a pager package.

How to trace a users path on a map?

I am developing an iOS app using Rubymotion.
In this app I want to be able to show the user on a map exactly which way he or she have driven or walked. I also want to save this path on the server.
How can I trace this patch in iOS?
All input and hints about a solution is welcome.
i guess your app needs a timer:
count = 0
timer = EM.add_periodic_timer 1.0 do
count = count + 1
puts "Great scott!"
(count < 10) || EM.cancel_timer(timer)
end
and then find the current location:
BW::Location.get do |result|
p "From Lat #{result[:from].latitude}, Long #{result[:from].longitude}"
p "To Lat #{result[:to].latitude}, Long #{result[:to].longitude}"
end
all this is BubbleWrap: https://github.com/rubymotion/BubbleWrap

jmeter - counting cookie values

I'm playing around with jmeter to validate a bug fix.
Server logic sets the cookie "mygroup" it can be either "groupa" or "groupb". I want to be able fire a series of requests and be able to see there is a proper balanced distribution between the values of this cookie. Ie make 100 requests and 50 times the cookie will be set to "groupa" and "groupb".
I'm a bit stuck on this. I currently have the following. I can see the cookies being set in the results tree but I'd like to be able to display the a table with the version and the number of requests of each.
Thread Group
HTTP Cookie Manager
HTTP Request
View Results Tree
Within the results tree I can see Set-Cookie: mygroup="groupa" and also sometimes mygroup="groupb" how do I tabulize this ??
You can have cookies values exported as JMeter variables by setting:
CookieManager.save.cookies=true
in user.properties.
Add a Cookie Manager to your Test Plan.
In this case you will have the var COOKIE_mygroup set by JMeter.
You can then count it like this using a JSR223 Sampler + Groovy (add groovy-all-version.jar in jmeter/lib folder:
String value = vars.get("COOKIE_mygroup");
Integer counterB = vars.getObject("counterB");
Integer counterA = vars.getObject("counterA");
if(counterA == null) {
counterA = new Integer(0);
vars.putObject("counterA", counterA);
}
if(counterB == null) {
counterB = new Integer(0);
vars.putObject("counterB", counterB);
}
if(value.equals("groupa")) {
counterA = counterA+1;
vars.putObject("counterA", counterA);
} else {
counterB = counterB+1;
vars.putObject("counterB", counterB);
}
Asyou have only one thread, at end of loop you can then compare the 2 values or just display the value:
add a debug sampler
add a view tree result
Run test plan, in view result tree click on debug sampler , select response tab and you should have your values