Re: Dynamically changing the content of HTTPRequest defaultdata
Philip Aston <[email protected]>
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <[email protected]> |
setDataFromFile() reads the file and sets the "data" for the request to
its bytes.
Supposing you just want to change the report_id string, you might script
that as follows:
from java.lang import String
# ...
request3 = createRequest(Test(203, 'POST importWeb'), url0)
request3.setDataFromFile('http-data-0.dat')
dataAsString = String(request3.getData()) #1
dataAsString = String(dataAsString.replace("report_id",
"some_other_id")) #2
result = request3.POST('/importWeb',
dataAsString.getBytes(), #3
(NVPair('Content-Type', 'multipart/form-data'), ))
Here we get the byte array and convert it to a Java string (#1); use the
Java String replace() method to alter the content (#2); then convert it
back to a Java byte array (#3).
How you generate "some_other_id" is up to you. See
http://grinder.sourceforge.net/faq.html#simulating-users for an example
of picking strings randomly from a file.
- Phil
On 26/09/13 19:42, Antonio Osorio wrote:
> Hi,
>
> I'm load testing a web api call used to import data into my
> application, I used the proxy recorder to record my session and it
> generated the following call (slightly edited)
>
> request3 = createRequest(Test(203, 'POST importWeb'), url0)
> request3.setDataFromFile('http-data-0.dat')
> result = request3.POST('/importWeb',
> request3.getData(),
> (NVPair('Content-Type', 'multipart/form-data'), ))
>
>
> and created the file "http-data-0,dat" with contents:
>
> -----------------------------1705984948108958842379964678
> Content-Disposition: form-data; name="report_id"
>
> 865
> -----------------------------1705984948108958842379964678
> Content-Disposition: form-data; name="compounds";
> filename="ideas.sdf"
> Content-Type: application/vnd.stardivision.math
>
> 21335604.finalpose
> Canvas 00000000002D
>
> 34 39 0 0 0 0 0 0 0 0999 V2000
> -6.8315 4.6621 0.0000 O 0 0 0
> -6.8315 3.3621 0.0000 C 0 0 0
> -7.9573 2.7121 0.0000 N 0 0 0
> -7.9573 1.4121 0.0000 C 0 0 0
> -6.8315 0.7621 0.0000 C 0 0 0
> -5.7057 1.4121 0.0000 C 0 0 0
> -4.5798 0.7621 0.0000 C 0 0 0
> -3.4540 1.4121 0.0000 C 0 0 0
>
>
> When running load tests the report_id that this data is supposed to be
> loaded to will change everytime, but the proxy recorder has hardcoded
> it in the http-data-0.dat file. How can I modify it during runtime?
>
> Regards,
>
> Antonio
>
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use