Forum Discussion

Michael_Eddingt's avatar
Michael_Eddingt
Occasional Contributor
17 years ago

GroovyDataSource and readLine issues

I have a Groovy DataSource with the following script.  The script does not perform as one would expect.  Instead each call to readLine() reads a line at some random spot way down the file (assuming the file is large enough).  The expected result would be the first line, then the second, etc.

Could this be an issue with Groovy?  Or something else?

The work around is to say "readLines()" and store the result in context.  However, for large files this uses alot of memory.


// Read values from a text file.

if(context["peach"] == null)
{
context["peach"] = new File("c:/strings.txt").newInputStream()
}

result["value1"] = context["peach"].readLine()

// end

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    hmm.. sounds strange.. soapUI 2.0.1 will upgrade to groovy 1.5.1. How are you checking that the order is no ok? Directly after the read or "somewhere else"?

    regards,

    /Ole
    eviware.com
  • Michael_Eddingt's avatar
    Michael_Eddingt
    Occasional Contributor
    From the GroovyDataSource pane just hit the run button and say 10 iterations and look at the values produced.  The text file would have lines line:

    string1
    string2
    string3
    ...

    So one would expect the values displayed to be string1, string2, ... but instead you get string1 then string1000 or something.  Very strange.

    mike
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Michael,

    I wonder if you could try the following initialization for peach instead:

    context["peach"] = new java.io.BufferedReader( new java.io.FileReader( "c:/strings.txt"))

    ?

    Does that help?

    regards,

    /Ole
    eviware.com