You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Abram Catalano <ab...@adaptx.com> on 2008/01/05 00:15:14 UTC

JDBC response assertions

Apologies in advance if this is obvious.  I crawled google and the  
archives and didn't see what I needed.

I have a JDBC sampler set up, and I want to make some assertions on  
the rows' data returned.  I see that I can dump the JDBC response to a  
file, and then subsequently iterate over the file, but that is not  
getting me far enough.

1) I dont really want to use a file, I just want to iterate over the  
jdbc reponse in memory.  They're small responses  (a few rows).  how?
2) One issue I am having is that some of the rows contain timestamps.   
It appears any response data I see is "toString()"ing the data, so  
timestamps just appear as their Java class/mem address  (e.g.  
"oracle.sql.TIMESTAMP@1bb9f3f" )

Is there some way to provide a row object (and some mapping code,  
something like Spring's JdbcTemplate provides), and be able to iterate  
over a list of row objects?  I need to do things like see if a  
timestamp is within +- 5 seconds of what it should be.

I haven't looked at BeanShell much yet.  I'd prefer some simple Java  
code that validates/tests JDBC response data.  (e.g. boolean  
verify(List<Row> response) )

Also, if there is an easy extension point for JDBC response processing  
(that takes a ResultSet as an argument), I'd be interested in writing  
up some code to help out in this area.

Thanks in advance.
-Abram

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


Re: JDBC response assertions

Posted by sebb <se...@gmail.com>.
On 03/03/2008, Abram Catalano <ab...@adaptx.com> wrote:
> Sebb, has there been any news on this enhancement?  I'm not sure if you
>  filed a bug or not.

No, I did not file an enhancement request. I thought you were going to
do that...

>  It would be great to get this in, for me, so I don't have to package
>  jmeter and distribute our own version of JMeter internally.  I don't
>  have "complete" code (to submit a patch) - just as much as I needed to
>  get access to the actual resultSet data for select statements.  What can
>  I do to help?  I don't want to finish coding this up if my patch is just
>  going to be rejected anyways.  Whats the process here?
>

The process is:

==

Discuss change on user list (not always necessary; depends on change).

Create a Bugzilla enhancement with details of the proposed change.
If a patch is available, that can then be attached. Ideally the patch
will include test case(s) and documentation updates as needed.

Make sure that you have created the patch against the latest code in
trunk, and that it compiles and tests OK on the base version of Java
(currently 1.4 for JMeter).

If the patch is substantial, a CLA
(http://www.apache.org/licenses/#clas) may also be needed.

==

In this case, I'm still a bit wary of adding a new field to the
SampleResult class.

This is because of compatibility concerns (hopefully a full test would
show if that is a problem or not). Also, adding the field means a
reference will be kept, which can increase the memory requirements.
Not all JDBC test cases will need this, so I think the functionality
needs to be optional.

If we do add another SampleResult field, it needs to be an Object, so
we can re-use the field for other samplers if necessary.

Otherwise, to solve just this case, one could just store the data in a
variable; the JDBC Sampler screen could be extended to add an optional
variable name. i.e. if the name is specified, save the data reference
in the variable. This can easily be accessed from BeanShell etc. using
vars.getObject("VARNAME")

>
>  sebb wrote:
>  > On 07/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
>  >
>  >>  > This can get complicated, so it might be useful to extend the JDBC
>  >> sampler to make such checks easier.
>  >> Yeah, I'm not bad at regex, but I'd rather deal with columns, values and
>  >> newlines as structured data.
>  >>
>  >>  > Bugzilla can be used for enhancement requests too ... but it might be
>  >> best to discuss the proposal on JMeter user first. I'll start a thread
>  >> if no-one beats me to it.
>  >>
>  >>
>  >> What I've done locally here is add 1) "rawResponseData" to
>  >> SampleResult.java
>  >>
>  >
>  > This may perhaps affect JTL files.
>  >
>  >
>  >> 2) add res.setRawResponseData(data) in JDBCSampler.
>  >> Code below.  There are a bunch of cases I didn't catch with this  (when
>  >> _queryType != SELECT).
>  >>
>  >>  if (SELECT.equals(_queryType)) {
>  >>                stmt = conn.createStatement();
>  >>                ResultSet rs = null;
>  >>                try {
>  >>                    rs = stmt.executeQuery(getQuery());
>  >>                    Data data = getDataFromResultSet(rs);
>  >>                    res.setRawResponseData(data);
>  >>                    res.setResponseData(data.toString().getBytes());
>  >>                } finally {
>  >>                    close(rs);
>  >>                }
>  >>
>  >>
>  >> Then, I have the rawResponseData Data object available in BeanShell.
>  >>
>  >
>  > Which for some people may be as hard as using an RE     ;-)
>  >
>  >
>  >> Quick example:
>  >>
>  >>  (BeanShell code)
>  >>
>  >> import org.apache.jorphan.collections.*;
>  >> System.out.println("Headers");
>  >> header = SampleResult.getRawResponseData().getHeaders();
>  >> System.out.println("header length = "+header.length);
>  >>
>  >>
>  >>
>  >>
>  >>
>  >> ---------------------------------------------------------------------
>  >> 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
>  >
>  >
>
>

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


Re: JDBC response assertions

Posted by Abram Catalano <ab...@adaptx.com>.
Sebb, has there been any news on this enhancement?  I'm not sure if you 
filed a bug or not. 

It would be great to get this in, for me, so I don't have to package 
jmeter and distribute our own version of JMeter internally.  I don't 
have "complete" code (to submit a patch) - just as much as I needed to 
get access to the actual resultSet data for select statements.  What can 
I do to help?  I don't want to finish coding this up if my patch is just 
going to be rejected anyways.  Whats the process here?


sebb wrote:
> On 07/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
>   
>>  > This can get complicated, so it might be useful to extend the JDBC
>> sampler to make such checks easier.
>> Yeah, I'm not bad at regex, but I'd rather deal with columns, values and
>> newlines as structured data.
>>
>>  > Bugzilla can be used for enhancement requests too ... but it might be
>> best to discuss the proposal on JMeter user first. I'll start a thread
>> if no-one beats me to it.
>>
>>
>> What I've done locally here is add 1) "rawResponseData" to
>> SampleResult.java
>>     
>
> This may perhaps affect JTL files.
>
>   
>> 2) add res.setRawResponseData(data) in JDBCSampler.
>> Code below.  There are a bunch of cases I didn't catch with this  (when
>> _queryType != SELECT).
>>
>>  if (SELECT.equals(_queryType)) {
>>                stmt = conn.createStatement();
>>                ResultSet rs = null;
>>                try {
>>                    rs = stmt.executeQuery(getQuery());
>>                    Data data = getDataFromResultSet(rs);
>>                    res.setRawResponseData(data);
>>                    res.setResponseData(data.toString().getBytes());
>>                } finally {
>>                    close(rs);
>>                }
>>
>>
>> Then, I have the rawResponseData Data object available in BeanShell.
>>     
>
> Which for some people may be as hard as using an RE     ;-)
>
>   
>> Quick example:
>>
>>  (BeanShell code)
>>
>> import org.apache.jorphan.collections.*;
>> System.out.println("Headers");
>> header = SampleResult.getRawResponseData().getHeaders();
>> System.out.println("header length = "+header.length);
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>   


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


Re: JDBC response assertions

Posted by sebb <se...@gmail.com>.
On 07/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
>  > This can get complicated, so it might be useful to extend the JDBC
> sampler to make such checks easier.
> Yeah, I'm not bad at regex, but I'd rather deal with columns, values and
> newlines as structured data.
>
>  > Bugzilla can be used for enhancement requests too ... but it might be
> best to discuss the proposal on JMeter user first. I'll start a thread
> if no-one beats me to it.
>
>
> What I've done locally here is add 1) "rawResponseData" to
> SampleResult.java

This may perhaps affect JTL files.

> 2) add res.setRawResponseData(data) in JDBCSampler.
> Code below.  There are a bunch of cases I didn't catch with this  (when
> _queryType != SELECT).
>
>  if (SELECT.equals(_queryType)) {
>                stmt = conn.createStatement();
>                ResultSet rs = null;
>                try {
>                    rs = stmt.executeQuery(getQuery());
>                    Data data = getDataFromResultSet(rs);
>                    res.setRawResponseData(data);
>                    res.setResponseData(data.toString().getBytes());
>                } finally {
>                    close(rs);
>                }
>
>
> Then, I have the rawResponseData Data object available in BeanShell.

Which for some people may be as hard as using an RE     ;-)

> Quick example:
>
>  (BeanShell code)
>
> import org.apache.jorphan.collections.*;
> System.out.println("Headers");
> header = SampleResult.getRawResponseData().getHeaders();
> System.out.println("header length = "+header.length);
>
>
>
>
>
> ---------------------------------------------------------------------
> 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


Re: JDBC response assertions

Posted by Abram Catalano <ab...@adaptx.com>.
 > This can get complicated, so it might be useful to extend the JDBC 
sampler to make such checks easier.
Yeah, I'm not bad at regex, but I'd rather deal with columns, values and 
newlines as structured data.

 > Bugzilla can be used for enhancement requests too ... but it might be 
best to discuss the proposal on JMeter user first. I'll start a thread 
if no-one beats me to it.


What I've done locally here is add 1) "rawResponseData" to 
SampleResult.java 2) add res.setRawResponseData(data) in JDBCSampler.  
Code below.  There are a bunch of cases I didn't catch with this  (when 
_queryType != SELECT).

 if (SELECT.equals(_queryType)) {
                stmt = conn.createStatement();
                ResultSet rs = null;
                try {
                    rs = stmt.executeQuery(getQuery());
                    Data data = getDataFromResultSet(rs);
                    res.setRawResponseData(data);
                    res.setResponseData(data.toString().getBytes());
                } finally {
                    close(rs);
                }


Then, I have the rawResponseData Data object available in BeanShell.  
Quick example:

 (BeanShell code)

import org.apache.jorphan.collections.*;
System.out.println("Headers");
header = SampleResult.getRawResponseData().getHeaders();
System.out.println("header length = "+header.length);





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


Re: JDBC response assertions

Posted by sebb <se...@gmail.com>.
On 07/01/2008, Sonam Chauhan <so...@ce.com.au> wrote:
> Hi Abram -
>
> We use Oracle here, and in JMeter the timestamps show up in a normal
> looking text datetime format.

Thanks; useful to know this. Looks like maybe there is a problem with
the driver...

> > I still find it hard to believe noone has needed to, say, assert the
> > number of rows returned, or check the value of a specific column.
>
> For this I just use regular expressions in the response assertion
> (asserted against the text response.)
>

This can get complicated, so it might be useful to extend the JDBC
sampler to make such checks easier.

Bugzilla can be used for enhancement requests too ... but it might be
best to discuss the proposal on JMeter user first. I'll start a thread
if no-one beats me to it.

> Regards,
> Sonam
>
> -----Original Message-----
> From: Abram Catalano [mailto:abram@adaptx.com]
> Sent: Monday, 7 January 2008 9:16 AM
> To: JMeter Users List
> Subject: Re: JDBC response assertions
>
> Thanks for the response sebb.
>
> I still find it hard to believe noone has needed to, say, assert the
> number of rows returned, or check the value of a specific column.
>
> Looks like I'm going to have to amend the JDBC sampler code.  I'll start
>
> another thread on the dev list to discuss how they'd want it done (if
> they even want my change).  Ideally I think the SampleResult should get
> the data in _another_ "responseData" field (with the real data being set
>
> in it), so as to not break anyone's tests or JMeters assertion code for
> the current byte[] responseData that is expecting a string.
>
> There isn't a problem with the oracle jdbc driver, its just printing
> what toString() returns.  Printing dates and times is always tricky
> anyways.
>
> Thanks,
> -Abram Catalano
>
>
>
> sebb wrote:
> > On 05/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
> >
> >> So, digging into the JDBCSampler.java class, I see:
> >>
> >> Data data = getDataFromResultSet(rs);
> >> res.setResponseData(data.toString().getBytes());
> >>
> >> Is there any way to get the "data" object into the "res"
> (SampleResult)
> >> object, so I can at least have beanshell access to the columns of the
> >> result set?
> >>
> >
> > Only by amending the JDBC  sampler code.
> >
> > Normally toString() produces sensible output. I don't recall ever
> > seeing output such as you describe, but then I've only used Derby and
> > MySql. Not sure if the test databases I used had date columns.
> >
> > Maybe there is a problem with the Oracle JDBC driver?
> >
> > Might be worth checking if the same behaviour occurs with other
> > databases and timestamps.
> >
> >
> >> Full example below:
> >>
> >> public SampleResult sample(Entry e) {
> >> ......
> >>
> >> if (SELECT.equals(_queryType)) {
> >>                stmt = conn.createStatement();
> >>                ResultSet rs = null;
> >>                try {
> >>                    rs = stmt.executeQuery(getQuery());
> >>                    Data data = getDataFromResultSet(rs);
> >>                    res.setResponseData(data.toString().getBytes());
> >>                } finally {
> >>                    close(rs);
> >>                }
> >>            }
> >> ....
> >> }
> >>
> >> How has noone else needed this?
> >>
> >> Thanks in advance,
> >> -Abram
> >>
> >>
> >> Abram Catalano wrote:
> >>
> >>> Apologies in advance if this is obvious.  I crawled google and the
> >>> archives and didn't see what I needed.
> >>>
> >>> I have a JDBC sampler set up, and I want to make some assertions on
> >>> the rows' data returned.  I see that I can dump the JDBC response to
> a
> >>> file, and then subsequently iterate over the file, but that is not
> >>> getting me far enough.
> >>>
> >>> 1) I dont really want to use a file, I just want to iterate over the
> >>> jdbc reponse in memory.  They're small responses  (a few rows).
> how?
> >>> 2) One issue I am having is that some of the rows contain
> timestamps.
> >>> It appears any response data I see is "toString()"ing the data, so
> >>> timestamps just appear as their Java class/mem address  (e.g.
> >>> "oracle.sql.TIMESTAMP@1bb9f3f" )
> >>>
> >>> Is there some way to provide a row object (and some mapping code,
> >>> something like Spring's JdbcTemplate provides), and be able to
> iterate
> >>> over a list of row objects?  I need to do things like see if a
> >>> timestamp is within +- 5 seconds of what it should be.
> >>>
> >>> I haven't looked at BeanShell much yet.  I'd prefer some simple Java
> >>> code that validates/tests JDBC response data.  (e.g. boolean
> >>> verify(List<Row> response) )
> >>>
> >>> Also, if there is an easy extension point for JDBC response
> processing
> >>> (that takes a ResultSet as an argument), I'd be interested in
> writing
> >>> up some code to help out in this area.
> >>>
> >>> Thanks in advance.
> >>> -Abram
> >>>
> >>>
> ---------------------------------------------------------------------
> >>> 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
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> The information contained in this email and any attached files are strictly private and confidential. This email should be read by the intended addressee only.  If the recipient of this message is not the intended addressee, please call Corporate Express Australia Limited on +61 2 9335 0555 or Corporate Express New Zealand Limited on +64 9 279 2555 and promptly delete this email and any attachments.  The intended recipient of this email may only use, reproduce, disclose or distribute the information contained in this email and any attached files with Corporate Express' permission. If you are not the intended addressee, you are strictly prohibited from using, reproducing, disclosing or distributing the information contained in this email and any attached files.  Corporate Express advises that this email and any attached files should be scanned to detect viruses. Corporate Express accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files.
>
> ---------------------------------------------------------------------
> 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


Re: JDBC response assertions

Posted by Abram Catalano <ab...@adaptx.com>.
I'm not sure how it works for you, unless you aren't using 
oracle.sql.TIMESTAMP objects.

I'd guess the problem has to do with that class not having toString() 
defined (or its parent).  It does have stringValue() though, which I 
accessed with bsh, and it does give the timestamp as a string.  Without 
looking at the code, I assume JMeter is trying to do a toString().


Sonam Chauhan wrote:
> Hi Abram - 
>
> We use Oracle here, and in JMeter the timestamps show up in a normal
> looking text datetime format. 
>
>   
>> I still find it hard to believe noone has needed to, say, assert the 
>> number of rows returned, or check the value of a specific column.
>>     
>
> For this I just use regular expressions in the response assertion
> (asserted against the text response.)
>
> Regards,
> Sonam
>   


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


RE: JDBC response assertions

Posted by Sonam Chauhan <so...@ce.com.au>.
Hi Abram - 

We use Oracle here, and in JMeter the timestamps show up in a normal
looking text datetime format. 

> I still find it hard to believe noone has needed to, say, assert the 
> number of rows returned, or check the value of a specific column.

For this I just use regular expressions in the response assertion
(asserted against the text response.)

Regards,
Sonam

-----Original Message-----
From: Abram Catalano [mailto:abram@adaptx.com] 
Sent: Monday, 7 January 2008 9:16 AM
To: JMeter Users List
Subject: Re: JDBC response assertions

Thanks for the response sebb.

I still find it hard to believe noone has needed to, say, assert the 
number of rows returned, or check the value of a specific column.

Looks like I'm going to have to amend the JDBC sampler code.  I'll start

another thread on the dev list to discuss how they'd want it done (if 
they even want my change).  Ideally I think the SampleResult should get 
the data in _another_ "responseData" field (with the real data being set

in it), so as to not break anyone's tests or JMeters assertion code for 
the current byte[] responseData that is expecting a string. 

There isn't a problem with the oracle jdbc driver, its just printing 
what toString() returns.  Printing dates and times is always tricky
anyways.

Thanks,
-Abram Catalano



sebb wrote:
> On 05/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
>   
>> So, digging into the JDBCSampler.java class, I see:
>>
>> Data data = getDataFromResultSet(rs);
>> res.setResponseData(data.toString().getBytes());
>>
>> Is there any way to get the "data" object into the "res"
(SampleResult)
>> object, so I can at least have beanshell access to the columns of the
>> result set?
>>     
>
> Only by amending the JDBC  sampler code.
>
> Normally toString() produces sensible output. I don't recall ever
> seeing output such as you describe, but then I've only used Derby and
> MySql. Not sure if the test databases I used had date columns.
>
> Maybe there is a problem with the Oracle JDBC driver?
>
> Might be worth checking if the same behaviour occurs with other
> databases and timestamps.
>
>   
>> Full example below:
>>
>> public SampleResult sample(Entry e) {
>> ......
>>
>> if (SELECT.equals(_queryType)) {
>>                stmt = conn.createStatement();
>>                ResultSet rs = null;
>>                try {
>>                    rs = stmt.executeQuery(getQuery());
>>                    Data data = getDataFromResultSet(rs);
>>                    res.setResponseData(data.toString().getBytes());
>>                } finally {
>>                    close(rs);
>>                }
>>            }
>> ....
>> }
>>
>> How has noone else needed this?
>>
>> Thanks in advance,
>> -Abram
>>
>>
>> Abram Catalano wrote:
>>     
>>> Apologies in advance if this is obvious.  I crawled google and the
>>> archives and didn't see what I needed.
>>>
>>> I have a JDBC sampler set up, and I want to make some assertions on
>>> the rows' data returned.  I see that I can dump the JDBC response to
a
>>> file, and then subsequently iterate over the file, but that is not
>>> getting me far enough.
>>>
>>> 1) I dont really want to use a file, I just want to iterate over the
>>> jdbc reponse in memory.  They're small responses  (a few rows).
how?
>>> 2) One issue I am having is that some of the rows contain
timestamps.
>>> It appears any response data I see is "toString()"ing the data, so
>>> timestamps just appear as their Java class/mem address  (e.g.
>>> "oracle.sql.TIMESTAMP@1bb9f3f" )
>>>
>>> Is there some way to provide a row object (and some mapping code,
>>> something like Spring's JdbcTemplate provides), and be able to
iterate
>>> over a list of row objects?  I need to do things like see if a
>>> timestamp is within +- 5 seconds of what it should be.
>>>
>>> I haven't looked at BeanShell much yet.  I'd prefer some simple Java
>>> code that validates/tests JDBC response data.  (e.g. boolean
>>> verify(List<Row> response) )
>>>
>>> Also, if there is an easy extension point for JDBC response
processing
>>> (that takes a ResultSet as an argument), I'd be interested in
writing
>>> up some code to help out in this area.
>>>
>>> Thanks in advance.
>>> -Abram
>>>
>>>
---------------------------------------------------------------------
>>> 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
>>
>>
>>     
>
> ---------------------------------------------------------------------
> 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


The information contained in this email and any attached files are strictly private and confidential. This email should be read by the intended addressee only.  If the recipient of this message is not the intended addressee, please call Corporate Express Australia Limited on +61 2 9335 0555 or Corporate Express New Zealand Limited on +64 9 279 2555 and promptly delete this email and any attachments.  The intended recipient of this email may only use, reproduce, disclose or distribute the information contained in this email and any attached files with Corporate Express� permission. If you are not the intended addressee, you are strictly prohibited from using, reproducing, disclosing or distributing the information contained in this email and any attached files.  Corporate Express advises that this email and any attached files should be scanned to detect viruses. Corporate Express accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files.

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


Re: JDBC response assertions

Posted by Abram Catalano <ab...@adaptx.com>.
Thanks for the response sebb.

I still find it hard to believe noone has needed to, say, assert the 
number of rows returned, or check the value of a specific column.

Looks like I'm going to have to amend the JDBC sampler code.  I'll start 
another thread on the dev list to discuss how they'd want it done (if 
they even want my change).  Ideally I think the SampleResult should get 
the data in _another_ "responseData" field (with the real data being set 
in it), so as to not break anyone's tests or JMeters assertion code for 
the current byte[] responseData that is expecting a string. 

There isn't a problem with the oracle jdbc driver, its just printing 
what toString() returns.  Printing dates and times is always tricky anyways.

Thanks,
-Abram Catalano



sebb wrote:
> On 05/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
>   
>> So, digging into the JDBCSampler.java class, I see:
>>
>> Data data = getDataFromResultSet(rs);
>> res.setResponseData(data.toString().getBytes());
>>
>> Is there any way to get the "data" object into the "res" (SampleResult)
>> object, so I can at least have beanshell access to the columns of the
>> result set?
>>     
>
> Only by amending the JDBC  sampler code.
>
> Normally toString() produces sensible output. I don't recall ever
> seeing output such as you describe, but then I've only used Derby and
> MySql. Not sure if the test databases I used had date columns.
>
> Maybe there is a problem with the Oracle JDBC driver?
>
> Might be worth checking if the same behaviour occurs with other
> databases and timestamps.
>
>   
>> Full example below:
>>
>> public SampleResult sample(Entry e) {
>> ......
>>
>> if (SELECT.equals(_queryType)) {
>>                stmt = conn.createStatement();
>>                ResultSet rs = null;
>>                try {
>>                    rs = stmt.executeQuery(getQuery());
>>                    Data data = getDataFromResultSet(rs);
>>                    res.setResponseData(data.toString().getBytes());
>>                } finally {
>>                    close(rs);
>>                }
>>            }
>> ....
>> }
>>
>> How has noone else needed this?
>>
>> Thanks in advance,
>> -Abram
>>
>>
>> Abram Catalano wrote:
>>     
>>> Apologies in advance if this is obvious.  I crawled google and the
>>> archives and didn't see what I needed.
>>>
>>> I have a JDBC sampler set up, and I want to make some assertions on
>>> the rows' data returned.  I see that I can dump the JDBC response to a
>>> file, and then subsequently iterate over the file, but that is not
>>> getting me far enough.
>>>
>>> 1) I dont really want to use a file, I just want to iterate over the
>>> jdbc reponse in memory.  They're small responses  (a few rows).  how?
>>> 2) One issue I am having is that some of the rows contain timestamps.
>>> It appears any response data I see is "toString()"ing the data, so
>>> timestamps just appear as their Java class/mem address  (e.g.
>>> "oracle.sql.TIMESTAMP@1bb9f3f" )
>>>
>>> Is there some way to provide a row object (and some mapping code,
>>> something like Spring's JdbcTemplate provides), and be able to iterate
>>> over a list of row objects?  I need to do things like see if a
>>> timestamp is within +- 5 seconds of what it should be.
>>>
>>> I haven't looked at BeanShell much yet.  I'd prefer some simple Java
>>> code that validates/tests JDBC response data.  (e.g. boolean
>>> verify(List<Row> response) )
>>>
>>> Also, if there is an easy extension point for JDBC response processing
>>> (that takes a ResultSet as an argument), I'd be interested in writing
>>> up some code to help out in this area.
>>>
>>> Thanks in advance.
>>> -Abram
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>     
>
> ---------------------------------------------------------------------
> 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


Re: JDBC response assertions

Posted by sebb <se...@gmail.com>.
On 05/01/2008, Abram Catalano <ab...@adaptx.com> wrote:
> So, digging into the JDBCSampler.java class, I see:
>
> Data data = getDataFromResultSet(rs);
> res.setResponseData(data.toString().getBytes());
>
> Is there any way to get the "data" object into the "res" (SampleResult)
> object, so I can at least have beanshell access to the columns of the
> result set?

Only by amending the JDBC  sampler code.

Normally toString() produces sensible output. I don't recall ever
seeing output such as you describe, but then I've only used Derby and
MySql. Not sure if the test databases I used had date columns.

Maybe there is a problem with the Oracle JDBC driver?

Might be worth checking if the same behaviour occurs with other
databases and timestamps.

>
> Full example below:
>
> public SampleResult sample(Entry e) {
> ......
>
> if (SELECT.equals(_queryType)) {
>                stmt = conn.createStatement();
>                ResultSet rs = null;
>                try {
>                    rs = stmt.executeQuery(getQuery());
>                    Data data = getDataFromResultSet(rs);
>                    res.setResponseData(data.toString().getBytes());
>                } finally {
>                    close(rs);
>                }
>            }
> ....
> }
>
> How has noone else needed this?
>
> Thanks in advance,
> -Abram
>
>
> Abram Catalano wrote:
> > Apologies in advance if this is obvious.  I crawled google and the
> > archives and didn't see what I needed.
> >
> > I have a JDBC sampler set up, and I want to make some assertions on
> > the rows' data returned.  I see that I can dump the JDBC response to a
> > file, and then subsequently iterate over the file, but that is not
> > getting me far enough.
> >
> > 1) I dont really want to use a file, I just want to iterate over the
> > jdbc reponse in memory.  They're small responses  (a few rows).  how?
> > 2) One issue I am having is that some of the rows contain timestamps.
> > It appears any response data I see is "toString()"ing the data, so
> > timestamps just appear as their Java class/mem address  (e.g.
> > "oracle.sql.TIMESTAMP@1bb9f3f" )
> >
> > Is there some way to provide a row object (and some mapping code,
> > something like Spring's JdbcTemplate provides), and be able to iterate
> > over a list of row objects?  I need to do things like see if a
> > timestamp is within +- 5 seconds of what it should be.
> >
> > I haven't looked at BeanShell much yet.  I'd prefer some simple Java
> > code that validates/tests JDBC response data.  (e.g. boolean
> > verify(List<Row> response) )
> >
> > Also, if there is an easy extension point for JDBC response processing
> > (that takes a ResultSet as an argument), I'd be interested in writing
> > up some code to help out in this area.
> >
> > Thanks in advance.
> > -Abram
> >
> > ---------------------------------------------------------------------
> > 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
>
>

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


Re: JDBC response assertions

Posted by Abram Catalano <ab...@adaptx.com>.
So, digging into the JDBCSampler.java class, I see:

Data data = getDataFromResultSet(rs);
res.setResponseData(data.toString().getBytes());

Is there any way to get the "data" object into the "res" (SampleResult) 
object, so I can at least have beanshell access to the columns of the 
result set?


Full example below:

public SampleResult sample(Entry e) {
......

if (SELECT.equals(_queryType)) {
                stmt = conn.createStatement();
                ResultSet rs = null;
                try {
                    rs = stmt.executeQuery(getQuery());
                    Data data = getDataFromResultSet(rs);
                    res.setResponseData(data.toString().getBytes());
                } finally {
                    close(rs);
                }
            }
....
}

How has noone else needed this?

Thanks in advance,
-Abram


Abram Catalano wrote:
> Apologies in advance if this is obvious.  I crawled google and the 
> archives and didn't see what I needed.
>
> I have a JDBC sampler set up, and I want to make some assertions on 
> the rows' data returned.  I see that I can dump the JDBC response to a 
> file, and then subsequently iterate over the file, but that is not 
> getting me far enough.
>
> 1) I dont really want to use a file, I just want to iterate over the 
> jdbc reponse in memory.  They're small responses  (a few rows).  how?
> 2) One issue I am having is that some of the rows contain timestamps.  
> It appears any response data I see is "toString()"ing the data, so 
> timestamps just appear as their Java class/mem address  (e.g. 
> "oracle.sql.TIMESTAMP@1bb9f3f" )
>
> Is there some way to provide a row object (and some mapping code, 
> something like Spring's JdbcTemplate provides), and be able to iterate 
> over a list of row objects?  I need to do things like see if a 
> timestamp is within +- 5 seconds of what it should be.
>
> I haven't looked at BeanShell much yet.  I'd prefer some simple Java 
> code that validates/tests JDBC response data.  (e.g. boolean 
> verify(List<Row> response) )
>
> Also, if there is an easy extension point for JDBC response processing 
> (that takes a ResultSet as an argument), I'd be interested in writing 
> up some code to help out in this area.
>
> Thanks in advance.
> -Abram
>
> ---------------------------------------------------------------------
> 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