Ah bugger, I almost forgot to answer your question regarding the benefits.

The reason is that git doesn't work well with large files (i.e. 250MB data
files).
After zipping, they shrink to 10-15MB and git handle them quite nicely.
Second thing is that when we launch such a test on Jenkins, we don't have
to worry to unpack & delete :)

Third reason is "why not?" :) You never know when such a code will come
handy in different project :)


On 9 July 2013 19:37, Deepak Shetty <[email protected]> wrote:

> >that I don't wan't to unzip those files,
> The question is why do you want to do that? whats the benefit? - Again you
> have setup and tear down threadgroups so you can do it before your test
> runs and clean it up after its done (or as part of your build) - note you
> have to factor in multiple threads too ..
>
>
> On Tue, Jul 9, 2013 at 2:28 AM, Janusz Kowalczyk
> <[email protected]>wrote:
>
> > The thing is that I don't wan't to unzip those files, but just read
> > directly from them.
> >
> > OK, maybe easier way would be just returning a list or a map of
> variables,
> > so that I could iterate over it?
> >
> > ps. I put this strange loop just for the sake of the demo, so it doesn't
> > read more that 10 lines at a time :)
> >
> >
> >
> > On 8 July 2013 23:35, Deepak Shetty <[email protected]> wrote:
> >
> > > this.vars.put(this.outputVariable, line); ==> Always overwrites the
> > current
> > > value
> > > should be the last line however unless your loop is also incorrect
> > >
> > > But the better way is to get your data in the form you want first ,
> then
> > > start the test rather than the test writing some code to read the data
> > i.e.
> > > unzip your files whatever before you mai n test begins (as part of your
> > > build or as a startup threadgroup )
> > >
> > >
> > > On Mon, Jul 8, 2013 at 12:42 PM, Janusz Kowalczyk <
> > > [email protected]
> > > > wrote:
> > >
> > > > Hi All,
> > > >
> > > > I'd like to create a script that would read a zipped text file, and
> for
> > > > example for each line (passed as variable) send a HTTP request.
> > > >
> > > > So far, I've written a script that works partially :)
> > > > Partially, because sending a new line to log.info() prints out this
> > new
> > > > line (which is good :) ), but when I set the value of a variable to
> > newly
> > > > read line, then the value of that variable remains the same and is
> > always
> > > > equal to the first line of that text file.
> > > >
> > > > Please find the code below. To test it:
> > > > - create a simple text file with just few lines of random text,
> > > > - zip that text file
> > > > - Add a JSR223 preprocessor & set the script language to Java
> > > > - configure the script accordingly
> > > > - add a HTTP sampler and add ${CONTEXT} to the "RAW Post Body" field
> > > > - check the msg value of the http request in "View Results Tree"
> > > >
> > > >
> > > > import java.io.*;
> > > > import java.util.zip.ZipEntry;
> > > > import java.util.zip.ZipFile;
> > > > import org.apache.log.Logger;
> > > > import org.apache.jmeter.threads.JMeterVariables;
> > > >
> > > > public class JmeterZipReader
> > > > {
> > > >     private String zipFile;
> > > >     private Logger log;
> > > >     private String outputVariable;
> > > >     private JMeterVariables vars;
> > > >
> > > >     JmeterZipReader(String zipFile, Logger log, String
> outputVariable,
> > > > JMeterVariables vars){
> > > >         this.zipFile = zipFile;
> > > >         this.log = log;
> > > >         this.outputVariable = outputVariable;
> > > >         this.vars = vars;
> > > >     }
> > > >
> > > >     // textFile is the name of the text file inside the zip file
> > > >     public void read(String textFile){
> > > >         ZipFile zip;
> > > >         ZipEntry ze;
> > > >         InputStream input;
> > > >         BufferedReader br;
> > > >
> > > >         try {
> > > >             zip=new ZipFile(this.zipFile);
> > > >             ze=zip.getEntry(textFile);
> > > >             input = zip.getInputStream(ze);
> > > >             br = new BufferedReader(new InputStreamReader(input,
> > > > "US-ASCII"));
> > > >
> > > >             String line;
> > > >             int cnt = 0;
> > > >             while((line = br.readLine()) != null && cnt <= 10) {
> > > >                 this.vars.put(this.outputVariable, line);
> > > >                 log.info(line);
> > > >                 cnt += 1;
> > > >             }
> > > >
> > > >             br.close();
> > > >             zip.close();
> > > >         }
> > > >         catch (Exception e) {
> > > >             log.error("Unhandled exception:");
> > > >             e.printStackTrace();
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > JmeterZipReader jzr = new JmeterZipReader("/path/to/a/test.zip", log,
> > > > "CONTEXT", ctx.getVariables());
> > > > jzr.read("test.csv");
> > > >
> > > >
> > > >
> > > > Many thanks,
> > > > Janusz
> > > >
> > >
> >
>

Reply via email to