Re: extending HTTPRequest
Joan Picanyol i Puig <[email protected]>
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <[email protected]> |
I see. I didn't see until now this nit in the javadocs
http://grinder.sourceforge.net/g3/script-javadoc/net/grinder/script/Test.html#record%28java.lang.Object,%20net.grinder.script.Test.InstrumentationFilter%29
Some instrumenters, including the Jython instrumenter, do not
support selective instrumentation. If an instrumenter can handle the
target, but does not support selective instrumentation, this method
will throw NonInstrumentableTypeException. The non-selective version
of record(Object) should be used instead.
Thanks for nudging me in the right direction.
--
pica
* Philip Aston <[email protected]> [20140323 15:45]:
>
> This is a limitation of the Jython instrumentation engine.
>
> There are a couple of workarounds.
>
> 1. You could implement MyHTTPRequest in Java.
>
> 2. You could avoid selective instrumentation. For example:
>
> class MyHTTPRequest(HTTPRequest):
> def __init__(self, url):
> HTTPRequest.__init__(self)
> self.url = url
>
> def processResponse(self, response):
> # ...
>
> def createRequest(test, url, headers=None):
> """Create an instrumented HTTPRequest."""
> request = MyHTTPRequest(url=url)
> if headers: request.headers=headers
> test.record(request.GET)
> test.record(request.POST)# etc
> return request
>
>
> NB, fix to the MyHTTPRequest constructor to set the URL.
>
> HTH,
>
> - Phil
>
>
> On 17/03/14 17:33, Joan Picanyol i Puig wrote:
> > Hi,
> >
> > I'm trying to modify a test recorded with the TCPProxy & HTTP filter so
> > that all HTTP failures fail the tests.
> >
> > I thought I'd be as easy as extending HTTPRequest to raise an Exception
> > and use it in the createRequest() method, but I'm getting a
> > net.grinder.script.NonInstrumentableTypeException: The Jython instrumenters do not support selective instrumenters
> >
> > I've been unable to gather from
> > http://grinder.sourceforge.net/g3/instrumentation.html#Selective+instrumentation
> > what the correct approach would be. Any ideas?
> >
> > For the record, I'm modifying the generated script with:
> >
> > class MyHTTPRequest(HTTPRequest):
> > def __init__(self, url):
> > # super(MyHTTPRequest, self).__init__()
> > HTTPRequest.__init__(self)
> >
> > def processResponse(self, response):
> > if response.getStatusCode >= 400:
> > log("KO %(status)s: %(msg)s" %
> > {"status": response.getStatusCode(), "msg": response.getText()})
> > raise Exception(response.getText())
> >
> > def createRequest(test, url, headers=None):
> > """Create an instrumented HTTPRequest."""
> > # request = HTTPRequest(url=url)
> > request = MyHTTPRequest(url=url)
> > if headers: request.headers = headers
> > test.record(request, HTTPRequest.getHttpMethodFilter())
> > return request
> >
> > And this is the exception I'm getting:
> >
> > net.grinder.script.NonInstrumentableTypeException: The Jython instrumenters do not support selective instrumenters
> > at net.grinder.scriptengine.jython.instrumentation.dcr.AbstractJythonDCRInstrumenter.disallowSelectiveFilter(AbstractJythonDCRInstrumenter.java:183) ~[grinder-core-3.11.jar:na]
> > at net.grinder.scriptengine.jython.instrumentation.dcr.AbstractJythonDCRInstrumenter.instrument(AbstractJythonDCRInstrumenter.java:167) ~[grinder-core-3.11.jar:na]
> > at net.grinder.scriptengine.AbstractDCRInstrumenter.instrument(AbstractDCRInstrumenter.java:93) ~[grinder-core-3.11.jar:na]
> > at net.grinder.scriptengine.CompositeInstrumenter.instrument(CompositeInstrumenter.java:103) ~[grinder-core-3.11.jar:na]
> >
> > tks
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech