I'm using JMeter to load test a webapp written in GWT.
I've found SyncProxy lets me write Java code to execute remote methods on the appserver as if I were a client (browser).
I've wrapped my Java code into a class that implements JavaSamplerClient from JMeter. What this开发者_Python百科 means is that I can run my own Java code inside a JMeter object and it gets executed according to test logic.
Now the problem. Since I'm not using JMeter's HTTPSampler, my users don't behave in the way I want them to, namely to be independent from one another. I never had that problem when using HTTPSampler + HTTP Authentication Manager + HTTP Cookie Manager.
I solved the Basic Authentication part by modifying SyncProxy to send authentication data as an extra HTTP header with each request.
And the question: How to best implement the tools I have at my disposal so that my users are independent and stop stealing each other's sessions from time to time?
I am in the process of doing something very similar.
My approach is to have a separate java sampler acting as a session creation and login mechanism.
syncproxy has a multisession option. The session instance is stored in a static list class with session information selectable by a token. The token reference is constructed from the jmeter thread variable.
When you then use your main syncproxy java sampler, re use the thread variable in your parameter list and pick up the correct session from the list for the correct jmeter thread.
NB If you are using multiple sessions and have used the AutoSyncProxy patch then you will have to modify AutoSyncProxy.newProxyInstance method to allow the definition of a session.
You might consider restructuring slightly.
Use JMETER samplers to login and maintain your session, and pass the userID and session information (cookie or sessionID) into your java class.
Using the beanshell sampler, you can execute java code and have access to jmeter variables (userID and session info, in this case)
精彩评论