You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Shane Petroff <sh...@mayet.ca> on 2007/12/30 06:39:24 UTC
SQL and javascript replace
Hello,
I'm having trouble doing a simple text substitution. I am currently
pulling query type and query data for use in a JDBC Sampler out of a CSV
file. I wanted to do some simple text substitution on the query strings
before execution, and the __javaScript function seemed to be the answer.
The query string I am using is:
${__javaScript('${query_value}'.replace('randomText'\,'testing 123'))}
Where the 'query_value' variable holds the sql command string. I've
interspersed the CSV file with instances of 'randomText' and was hoping
to replace them with a block of randomly generated characters. The idea
being that if one loops through the CSV file multiple times, then every
update gets executed multiple times and the db figures out that there is
nothing to update. I was hoping to push test values through to disk
every time by updating with random text. E.g. "update table_1 set
a_string = 'randomText' where a_key = 1" would be executed as something
like "update table_1 set a_string = 'qd8v4Bg' where a_key = 1" and each
loop would push through a new value because a_string would always be
different. I was hoping to handle inserts in a similar manner,
generating new keys each time. However, there are a large percentage of
queries in which this strategy fails. I'm not exactly sure why it fails,
but I end up with scads of exceptions in the log file (and a good number
of queries which succeed).
2007/12/29 23:18:10 ERROR - jmeter.threads.JMeterThread:
org.mozilla.javascript.EvaluatorException: missing ; before statement
(<cmd>#1)
at
org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:98)
at
org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:85)
at org.mozilla.javascript.Parser.addError(Parser.java:126)
at org.mozilla.javascript.Parser.reportError(Parser.java:132)
at org.mozilla.javascript.Parser.statementHelper(Parser.java:1175)
at org.mozilla.javascript.Parser.statement(Parser.java:623)
at org.mozilla.javascript.Parser.parse(Parser.java:355)
at org.mozilla.javascript.Parser.parse(Parser.java:293)
at org.mozilla.javascript.Context.compileImpl(Context.java:2238)
at org.mozilla.javascript.Context.compileString(Context.java:1284)
at org.mozilla.javascript.Context.compileString(Context.java:1273)
at org.mozilla.javascript.Context.evaluateString(Context.java:1129)
at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:91)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:128)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:97)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:70)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:297)
at java.lang.Thread.run(Unknown Source)
It's as though the sql text itself is being interpreted and not
surprisingly bombs. Any idea what is going wrong? Is there any way to
avoid simply recycling values on each loop of a jdbc test? Thanks.
--
Shane
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: SQL and javascript replace
Posted by sebb <se...@gmail.com>.
If the query string contains single-quotes, then these need to be
escaped otherwise the string will not be properly enclosed.
Versions of JMeter after 2.3 (i.e. currently just 2.3.1) give
javascript access to the JMeter vars object, so you can use
vars.get("query_value").replace(...
instead of
'${query_value}'.replace(...
and avoid the problem
On 31/12/2007, Shane Petroff <sh...@mayet.ca> wrote:
> sebb wrote:
> > Check that there is no extraneous whitespace after the function call.
> >
> There is no extraneous whitespace. Moreover, the function seems to
> succeed around 75% of the time; it mainly barfs on inserts and updates.
>
> Shane
> > On 30/12/2007, Shane Petroff <sh...@mayet.ca> wrote:
> >
> >> Hello,
> >>
> >> I'm having trouble doing a simple text substitution. I am currently
> >> pulling query type and query data for use in a JDBC Sampler out of a CSV
> >> file. I wanted to do some simple text substitution on the query strings
> >> before execution, and the __javaScript function seemed to be the answer.
> >> The query string I am using is:
> >>
> >> ${__javaScript('${query_value}'.replace('randomText'\,'testing 123'))}
> >>
> >> Where the 'query_value' variable holds the sql command string. I've
> >> interspersed the CSV file with instances of 'randomText' and was hoping
> >> to replace them with a block of randomly generated characters. The idea
> >> being that if one loops through the CSV file multiple times, then every
> >> update gets executed multiple times and the db figures out that there is
> >> nothing to update. I was hoping to push test values through to disk
> >> every time by updating with random text. E.g. "update table_1 set
> >> a_string = 'randomText' where a_key = 1" would be executed as something
> >> like "update table_1 set a_string = 'qd8v4Bg' where a_key = 1" and each
> >> loop would push through a new value because a_string would always be
> >> different. I was hoping to handle inserts in a similar manner,
> >> generating new keys each time. However, there are a large percentage of
> >> queries in which this strategy fails. I'm not exactly sure why it fails,
> >> but I end up with scads of exceptions in the log file (and a good number
> >> of queries which succeed).
> >>
> >> 2007/12/29 23:18:10 ERROR - jmeter.threads.JMeterThread:
> >> org.mozilla.javascript.EvaluatorException: missing ; before statement
> >> (<cmd>#1)
> >> at
> >> org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:98)
> >> at
> >> org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:85)
> >> at org.mozilla.javascript.Parser.addError(Parser.java:126)
> >> at org.mozilla.javascript.Parser.reportError(Parser.java:132)
> >> at org.mozilla.javascript.Parser.statementHelper(Parser.java:1175)
> >> at org.mozilla.javascript.Parser.statement(Parser.java:623)
> >> at org.mozilla.javascript.Parser.parse(Parser.java:355)
> >> at org.mozilla.javascript.Parser.parse(Parser.java:293)
> >> at org.mozilla.javascript.Context.compileImpl(Context.java:2238)
> >> at org.mozilla.javascript.Context.compileString(Context.java:1284)
> >> at org.mozilla.javascript.Context.compileString(Context.java:1273)
> >> at org.mozilla.javascript.Context.evaluateString(Context.java:1129)
> >> at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:91)
> >> at
> >> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:128)
> >> at
> >> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:97)
> >> at
> >> org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
> >> at
> >> org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:70)
> >> at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:297)
> >> at java.lang.Thread.run(Unknown Source)
> >>
> >> It's as though the sql text itself is being interpreted and not
> >> surprisingly bombs. Any idea what is going wrong? Is there any way to
> >> avoid simply recycling values on each loop of a jdbc test? Thanks.
> >>
> >> --
> >> Shane
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
> >
>
>
> --
> Shane
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: SQL and javascript replace
Posted by Shane Petroff <sh...@mayet.ca>.
sebb wrote:
> Check that there is no extraneous whitespace after the function call.
>
There is no extraneous whitespace. Moreover, the function seems to
succeed around 75% of the time; it mainly barfs on inserts and updates.
Shane
> On 30/12/2007, Shane Petroff <sh...@mayet.ca> wrote:
>
>> Hello,
>>
>> I'm having trouble doing a simple text substitution. I am currently
>> pulling query type and query data for use in a JDBC Sampler out of a CSV
>> file. I wanted to do some simple text substitution on the query strings
>> before execution, and the __javaScript function seemed to be the answer.
>> The query string I am using is:
>>
>> ${__javaScript('${query_value}'.replace('randomText'\,'testing 123'))}
>>
>> Where the 'query_value' variable holds the sql command string. I've
>> interspersed the CSV file with instances of 'randomText' and was hoping
>> to replace them with a block of randomly generated characters. The idea
>> being that if one loops through the CSV file multiple times, then every
>> update gets executed multiple times and the db figures out that there is
>> nothing to update. I was hoping to push test values through to disk
>> every time by updating with random text. E.g. "update table_1 set
>> a_string = 'randomText' where a_key = 1" would be executed as something
>> like "update table_1 set a_string = 'qd8v4Bg' where a_key = 1" and each
>> loop would push through a new value because a_string would always be
>> different. I was hoping to handle inserts in a similar manner,
>> generating new keys each time. However, there are a large percentage of
>> queries in which this strategy fails. I'm not exactly sure why it fails,
>> but I end up with scads of exceptions in the log file (and a good number
>> of queries which succeed).
>>
>> 2007/12/29 23:18:10 ERROR - jmeter.threads.JMeterThread:
>> org.mozilla.javascript.EvaluatorException: missing ; before statement
>> (<cmd>#1)
>> at
>> org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:98)
>> at
>> org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:85)
>> at org.mozilla.javascript.Parser.addError(Parser.java:126)
>> at org.mozilla.javascript.Parser.reportError(Parser.java:132)
>> at org.mozilla.javascript.Parser.statementHelper(Parser.java:1175)
>> at org.mozilla.javascript.Parser.statement(Parser.java:623)
>> at org.mozilla.javascript.Parser.parse(Parser.java:355)
>> at org.mozilla.javascript.Parser.parse(Parser.java:293)
>> at org.mozilla.javascript.Context.compileImpl(Context.java:2238)
>> at org.mozilla.javascript.Context.compileString(Context.java:1284)
>> at org.mozilla.javascript.Context.compileString(Context.java:1273)
>> at org.mozilla.javascript.Context.evaluateString(Context.java:1129)
>> at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:91)
>> at
>> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:128)
>> at
>> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:97)
>> at
>> org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
>> at
>> org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:70)
>> at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:297)
>> at java.lang.Thread.run(Unknown Source)
>>
>> It's as though the sql text itself is being interpreted and not
>> surprisingly bombs. Any idea what is going wrong? Is there any way to
>> avoid simply recycling values on each loop of a jdbc test? Thanks.
>>
>> --
>> Shane
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
>
--
Shane
Re: SQL and javascript replace
Posted by sebb <se...@gmail.com>.
Check that there is no extraneous whitespace after the function call.
On 30/12/2007, Shane Petroff <sh...@mayet.ca> wrote:
> Hello,
>
> I'm having trouble doing a simple text substitution. I am currently
> pulling query type and query data for use in a JDBC Sampler out of a CSV
> file. I wanted to do some simple text substitution on the query strings
> before execution, and the __javaScript function seemed to be the answer.
> The query string I am using is:
>
> ${__javaScript('${query_value}'.replace('randomText'\,'testing 123'))}
>
> Where the 'query_value' variable holds the sql command string. I've
> interspersed the CSV file with instances of 'randomText' and was hoping
> to replace them with a block of randomly generated characters. The idea
> being that if one loops through the CSV file multiple times, then every
> update gets executed multiple times and the db figures out that there is
> nothing to update. I was hoping to push test values through to disk
> every time by updating with random text. E.g. "update table_1 set
> a_string = 'randomText' where a_key = 1" would be executed as something
> like "update table_1 set a_string = 'qd8v4Bg' where a_key = 1" and each
> loop would push through a new value because a_string would always be
> different. I was hoping to handle inserts in a similar manner,
> generating new keys each time. However, there are a large percentage of
> queries in which this strategy fails. I'm not exactly sure why it fails,
> but I end up with scads of exceptions in the log file (and a good number
> of queries which succeed).
>
> 2007/12/29 23:18:10 ERROR - jmeter.threads.JMeterThread:
> org.mozilla.javascript.EvaluatorException: missing ; before statement
> (<cmd>#1)
> at
> org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:98)
> at
> org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:85)
> at org.mozilla.javascript.Parser.addError(Parser.java:126)
> at org.mozilla.javascript.Parser.reportError(Parser.java:132)
> at org.mozilla.javascript.Parser.statementHelper(Parser.java:1175)
> at org.mozilla.javascript.Parser.statement(Parser.java:623)
> at org.mozilla.javascript.Parser.parse(Parser.java:355)
> at org.mozilla.javascript.Parser.parse(Parser.java:293)
> at org.mozilla.javascript.Context.compileImpl(Context.java:2238)
> at org.mozilla.javascript.Context.compileString(Context.java:1284)
> at org.mozilla.javascript.Context.compileString(Context.java:1273)
> at org.mozilla.javascript.Context.evaluateString(Context.java:1129)
> at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:91)
> at
> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:128)
> at
> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:97)
> at
> org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
> at
> org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:70)
> at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:297)
> at java.lang.Thread.run(Unknown Source)
>
> It's as though the sql text itself is being interpreted and not
> surprisingly bombs. Any idea what is going wrong? Is there any way to
> avoid simply recycling values on each loop of a jdbc test? Thanks.
>
> --
> Shane
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org