You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by ll...@oreillyauto.com on 2012/05/14 18:30:16 UTC

Question about __logn()

I have a BeanShell Sampler that I have placed into a Once Only Controller.

In it, I have some code to help randomize my test in ways that I can't
easily do.

The code is :

<start code>
import java.io.*;
import java.util.*;
int n = 0;
for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
\\job_titles.txt") ); sc.hasNext(); )
{
 String line = sc.nextLine();
 line = line.replaceAll(" ", "+");
 vars.put("otl_JOB_TITLES_" + n, line);
 n++;
}

vars.put("otl_Counter", Integer.toString(n));

</end code>


However, as I am still developing this, I wanted to add a line to write the
value of the counter variable to the logfile.

When I add ${__logn(Counter is: ${otl_Counter})}; to the end of the file,
after the final vars.put(), I get the following error:


2012/05/14 11:22:43 ERROR - jmeter.util.BeanShellInterpreter: Error
invoking bsh method: eval	Sourced file: inline evaluation of: ``import
java.io.*; import java.util.*; int n = 0; for(Scanner sc = new Scanner
( n . . . '' Token Parsing Error: Lexical error at line 4, column 50.
Encountered: "L" (76), after : "\"..\\tests\\"

What am I doing wrong? Based on some Google searches and the jmeter docs, I
would think that would work.


For clarity, here is the full code that produces the error:

<start code>
import java.io.*;
import java.util.*;
int n = 0;
for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
\\job_titles.txt") ); sc.hasNext(); )
{
 String line = sc.nextLine();
 line = line.replaceAll(" ", "+");
 vars.put("otl_JOB_TITLES_" + n, line);
 n++;
}

vars.put("otl_Counter", Integer.toString(n));
${__logn(Counter is: ${otl_Counter})};
</end code>



Thank you.


Lee Lowder

This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS � 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Question about __logn()

Posted by sebb <se...@gmail.com>.
On 15 May 2012 13:46,  <ll...@oreillyauto.com> wrote:
> sebb <se...@gmail.com> wrote on 05/14/2012 12:44:31 PM:
>
>> From: sebb <se...@gmail.com>
>> To: JMeter Users List <us...@jmeter.apache.org>
>> Date: 05/14/2012 12:51 PM
>> Subject: Re: Question about __logn()
>>
>> On 14 May 2012 17:30,  <ll...@oreillyauto.com> wrote:
>> > I have a BeanShell Sampler that I have placed into a Once Only
> Controller.
>> >
>> > In it, I have some code to help randomize my test in ways that I can't
>> > easily do.
>> >
>> > The code is :
>> >
>> > <start code>
>> > import java.io.*;
>> > import java.util.*;
>> > int n = 0;
>> > for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
>> > \\job_titles.txt") ); sc.hasNext(); )
>> > {
>> >  String line = sc.nextLine();
>> >  line = line.replaceAll(" ", "+");
>> >  vars.put("otl_JOB_TITLES_" + n, line);
>> >  n++;
>> > }
>> >
>> > vars.put("otl_Counter", Integer.toString(n));
>> >
>> > </end code>
>> >
>> >
>> > However, as I am still developing this, I wanted to add a line to write
> the
>> > value of the counter variable to the logfile.
>> >
>> > When I add ${__logn(Counter is: ${otl_Counter})}; to the end of the
> file,
>> > after the final vars.put(), I get the following error:
>> >
>> >
>> > 2012/05/14 11:22:43 ERROR - jmeter.util.BeanShellInterpreter: Error
>> > invoking bsh method: eval       Sourced file: inline evaluation of:
> ``import
>> > java.io.*; import java.util.*; int n = 0; for(Scanner sc = new Scanner
>> > ( n . . . '' Token Parsing Error: Lexical error at line 4, column 50.
>> > Encountered: "L" (76), after : "\"..\\tests\\"
>>
>
>
>> Read the error message - it's complaining about "L" after "tests\\"
>
> It's not actually an escaping issue - this code works without error if I
> don't have the call to the __logn() function.

So don't use the function call.

It does not make sense anyway to use it in a BeanShell script, because
it will be processed before the script is passed to the interpreter.

If you want to log from a BeanShell script, use the "log" object which
is provided.

> I've seen it do this before, where I had an error later in the code that
> was being masked by an escaping error.
>
>>
>> Looks like an escaping error.
>>
>
>
> This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS § 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Question about __logn()

Posted by ll...@oreillyauto.com.
sebb <se...@gmail.com> wrote on 05/14/2012 12:44:31 PM:

> From: sebb <se...@gmail.com>
> To: JMeter Users List <us...@jmeter.apache.org>
> Date: 05/14/2012 12:51 PM
> Subject: Re: Question about __logn()
>
> On 14 May 2012 17:30,  <ll...@oreillyauto.com> wrote:
> > I have a BeanShell Sampler that I have placed into a Once Only
Controller.
> >
> > In it, I have some code to help randomize my test in ways that I can't
> > easily do.
> >
> > The code is :
> >
> > <start code>
> > import java.io.*;
> > import java.util.*;
> > int n = 0;
> > for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
> > \\job_titles.txt") ); sc.hasNext(); )
> > {
> >  String line = sc.nextLine();
> >  line = line.replaceAll(" ", "+");
> >  vars.put("otl_JOB_TITLES_" + n, line);
> >  n++;
> > }
> >
> > vars.put("otl_Counter", Integer.toString(n));
> >
> > </end code>
> >
> >
> > However, as I am still developing this, I wanted to add a line to write
the
> > value of the counter variable to the logfile.
> >
> > When I add ${__logn(Counter is: ${otl_Counter})}; to the end of the
file,
> > after the final vars.put(), I get the following error:
> >
> >
> > 2012/05/14 11:22:43 ERROR - jmeter.util.BeanShellInterpreter: Error
> > invoking bsh method: eval       Sourced file: inline evaluation of:
``import
> > java.io.*; import java.util.*; int n = 0; for(Scanner sc = new Scanner
> > ( n . . . '' Token Parsing Error: Lexical error at line 4, column 50.
> > Encountered: "L" (76), after : "\"..\\tests\\"
>


> Read the error message - it's complaining about "L" after "tests\\"

It's not actually an escaping issue - this code works without error if I
don't have the call to the __logn() function.

I've seen it do this before, where I had an error later in the code that
was being masked by an escaping error.

>
> Looks like an escaping error.
>


This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS § 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Question about __logn()

Posted by sebb <se...@gmail.com>.
On 14 May 2012 17:30,  <ll...@oreillyauto.com> wrote:
> I have a BeanShell Sampler that I have placed into a Once Only Controller.
>
> In it, I have some code to help randomize my test in ways that I can't
> easily do.
>
> The code is :
>
> <start code>
> import java.io.*;
> import java.util.*;
> int n = 0;
> for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
> \\job_titles.txt") ); sc.hasNext(); )
> {
>  String line = sc.nextLine();
>  line = line.replaceAll(" ", "+");
>  vars.put("otl_JOB_TITLES_" + n, line);
>  n++;
> }
>
> vars.put("otl_Counter", Integer.toString(n));
>
> </end code>
>
>
> However, as I am still developing this, I wanted to add a line to write the
> value of the counter variable to the logfile.
>
> When I add ${__logn(Counter is: ${otl_Counter})}; to the end of the file,
> after the final vars.put(), I get the following error:
>
>
> 2012/05/14 11:22:43 ERROR - jmeter.util.BeanShellInterpreter: Error
> invoking bsh method: eval       Sourced file: inline evaluation of: ``import
> java.io.*; import java.util.*; int n = 0; for(Scanner sc = new Scanner
> ( n . . . '' Token Parsing Error: Lexical error at line 4, column 50.
> Encountered: "L" (76), after : "\"..\\tests\\"

Read the error message - it's complaining about "L" after "tests\\"

Looks like an escaping error.

Try using / instead of \\ in the path name.

> What am I doing wrong? Based on some Google searches and the jmeter docs, I
> would think that would work.
>
>
> For clarity, here is the full code that produces the error:
>
> <start code>
> import java.io.*;
> import java.util.*;
> int n = 0;
> for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
> \\job_titles.txt") ); sc.hasNext(); )
> {
>  String line = sc.nextLine();
>  line = line.replaceAll(" ", "+");
>  vars.put("otl_JOB_TITLES_" + n, line);
>  n++;
> }
>
> vars.put("otl_Counter", Integer.toString(n));
> ${__logn(Counter is: ${otl_Counter})};
> </end code>
>
>
>
> Thank you.
>
>
> Lee Lowder
>
> This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS § 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org