You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Robert Godfrey <RG...@buildonline.com> on 2004/09/23 12:44:36 UTC

Simulating a dropped connection

Hi 

I've just come across cactus and was wondering whether it is possible to
simulate a dropped connection whilst sending request data. The scenario I'm
am trying to emulate is that of a large file upload (multipart request) that
is terminated due to a dropped connection or a user cancelling the request.
My limited understanding of Cactus (c. 2 hours) suggests that whilst I
should be able to set up a test to simulate a multipart request, it may not
be so easy to simulate a dropped connection. Does anyone have any
suggestions? For example is there a suitable extension point within cactus
from where one could potentially control the http connection and data stream
being sent.

Thanks Rob

RE: Multipart Requests

Posted by Andrew Swan <an...@bisinfo.com.au>.
In HTTP, a multi-part request is one whose "Content-type" starts with the
string "multipart/form-data". This type of request is created when a user
uploads one or more files to a server by submitting an HTML form from their
browser, where the form contains a tag like:

	input type='file' name='file-name'

(I've left out the HTML angle brackets in case they screw up the email). The
browser usually renders this as a text field (where the user can type in a
local file path) and a browse button (which the user can click to choose a
file from their local file system). Maybe you call this type of request
something else - I sure hope I'm not teaching you how to suck eggs!

Anyway, the reason I can't use a normal mock request (such as
com.mockrunner.mock.web.MockHttpServletRequest) is that you don't access the
parameters of a multi-part HTTP request in the same way as you would those
of a normal request (i.e. with req.getParameter(String)). I have therefore
created my own method for parsing a multi-part request into a custom Java
class (because I couldn't find anything to do this job in javax.servlet) and
it's this method that I want to unit test, by passing it a mock multi-part
request.

Does this make sense? Does such a mock object exist, to your (or anyone
else's) knowledge?

Thanks,

Andrew

-----Original Message-----
From: Vincent Massol [mailto:vmassol@pivolis.com]
Sent: Friday, 24 September 2004 4:55 PM
To: 'Cactus Users List'; andrews@bisinfo.com.au
Subject: RE: Simulating a dropped connection


Hi Andrew,

> -----Original Message-----
> From: Andrew Swan [mailto:andrews@bisinfo.com.au]
> Sent: vendredi 24 septembre 2004 01:04
> To: 'Cactus Users List'
> Subject: RE: Simulating a dropped connection
>
> I've been using MockRunner, and it seems good for normal HttpRequests.
>
> What I'd like to know (and I hope this isn't too far off-topic) is can one
> make a mock multi-part request?

I don't know what class you mean by "multi-part request" but if it's either
an interface or even a class you can create a mock for it (check easymock
for example, it has an extension to create mocks out of class). All that
said, it's usually a better idea to wrap the calling class by one of your
class which you can often mock more easily as you control it.

>
> Thanks in advance,
>
> Andrew
>
> P.S.	I bought your book, Vincent!  :-)

Very cool! :-)

-Vincent

>
> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@pivolis.com]
> Sent: Thursday, 23 September 2004 9:17 PM
> To: 'Cactus Users List'
> Subject: RE: Simulating a dropped connection
>
>
> Hi Rob,
>
> I don't think Cactus can help here. However you should be able to do what
> you wish by using MockObjects. Say you have a method called
> processRequest(HttpRequest) that processes the upload. You should be able
> to
> easily test it unitarily by using a mock HttpRequest and telling it to
> throw
> an exception after such amount of data has been read, etc.
>
> Cactus is about executing the tests with real objects from the container
> (i.e. real HttpRequests). With Mock Objects you can simulate them. See
> www.mockobjects.com (I also recommend my book JUnit in Action of course...
> ;-)).
>
> Thanks
> -Vincent
>
> > -----Original Message-----
> > From: Robert Godfrey [mailto:RGodfrey@buildonline.com]
> > Sent: jeudi 23 septembre 2004 12:45
> > To: 'cactus-user@jakarta.apache.org'
> > Subject: Simulating a dropped connection
> >
> > Hi
> >
> > I've just come across cactus and was wondering whether it is possible to
> > simulate a dropped connection whilst sending request data. The scenario
> > I'm
> > am trying to emulate is that of a large file upload (multipart request)
> > that
> > is terminated due to a dropped connection or a user cancelling the
> > request.
> > My limited understanding of Cactus (c. 2 hours) suggests that whilst I
> > should be able to set up a test to simulate a multipart request, it may
> > not
> > be so easy to simulate a dropped connection. Does anyone have any
> > suggestions? For example is there a suitable extension point within
> cactus
> > from where one could potentially control the http connection and data
> > stream
> > being sent.
> >
> > Thanks Rob
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org




RE: Simulating a dropped connection

Posted by Vincent Massol <vm...@pivolis.com>.
Hi Andrew,

> -----Original Message-----
> From: Andrew Swan [mailto:andrews@bisinfo.com.au]
> Sent: vendredi 24 septembre 2004 01:04
> To: 'Cactus Users List'
> Subject: RE: Simulating a dropped connection
> 
> I've been using MockRunner, and it seems good for normal HttpRequests.
> 
> What I'd like to know (and I hope this isn't too far off-topic) is can one
> make a mock multi-part request?

I don't know what class you mean by "multi-part request" but if it's either
an interface or even a class you can create a mock for it (check easymock
for example, it has an extension to create mocks out of class). All that
said, it's usually a better idea to wrap the calling class by one of your
class which you can often mock more easily as you control it.

> 
> Thanks in advance,
> 
> Andrew
> 
> P.S.	I bought your book, Vincent!  :-)

Very cool! :-)

-Vincent

> 
> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@pivolis.com]
> Sent: Thursday, 23 September 2004 9:17 PM
> To: 'Cactus Users List'
> Subject: RE: Simulating a dropped connection
> 
> 
> Hi Rob,
> 
> I don't think Cactus can help here. However you should be able to do what
> you wish by using MockObjects. Say you have a method called
> processRequest(HttpRequest) that processes the upload. You should be able
> to
> easily test it unitarily by using a mock HttpRequest and telling it to
> throw
> an exception after such amount of data has been read, etc.
> 
> Cactus is about executing the tests with real objects from the container
> (i.e. real HttpRequests). With Mock Objects you can simulate them. See
> www.mockobjects.com (I also recommend my book JUnit in Action of course...
> ;-)).
> 
> Thanks
> -Vincent
> 
> > -----Original Message-----
> > From: Robert Godfrey [mailto:RGodfrey@buildonline.com]
> > Sent: jeudi 23 septembre 2004 12:45
> > To: 'cactus-user@jakarta.apache.org'
> > Subject: Simulating a dropped connection
> >
> > Hi
> >
> > I've just come across cactus and was wondering whether it is possible to
> > simulate a dropped connection whilst sending request data. The scenario
> > I'm
> > am trying to emulate is that of a large file upload (multipart request)
> > that
> > is terminated due to a dropped connection or a user cancelling the
> > request.
> > My limited understanding of Cactus (c. 2 hours) suggests that whilst I
> > should be able to set up a test to simulate a multipart request, it may
> > not
> > be so easy to simulate a dropped connection. Does anyone have any
> > suggestions? For example is there a suitable extension point within
> cactus
> > from where one could potentially control the http connection and data
> > stream
> > being sent.
> >
> > Thanks Rob
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> >
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org




RE: Simulating a dropped connection

Posted by Andrew Swan <an...@bisinfo.com.au>.
I've been using MockRunner, and it seems good for normal HttpRequests.

What I'd like to know (and I hope this isn't too far off-topic) is can one
make a mock multi-part request?

Thanks in advance,

Andrew

P.S.	I bought your book, Vincent!  :-)

-----Original Message-----
From: Vincent Massol [mailto:vmassol@pivolis.com]
Sent: Thursday, 23 September 2004 9:17 PM
To: 'Cactus Users List'
Subject: RE: Simulating a dropped connection


Hi Rob,

I don't think Cactus can help here. However you should be able to do what
you wish by using MockObjects. Say you have a method called
processRequest(HttpRequest) that processes the upload. You should be able to
easily test it unitarily by using a mock HttpRequest and telling it to throw
an exception after such amount of data has been read, etc.

Cactus is about executing the tests with real objects from the container
(i.e. real HttpRequests). With Mock Objects you can simulate them. See
www.mockobjects.com (I also recommend my book JUnit in Action of course...
;-)).

Thanks
-Vincent

> -----Original Message-----
> From: Robert Godfrey [mailto:RGodfrey@buildonline.com]
> Sent: jeudi 23 septembre 2004 12:45
> To: 'cactus-user@jakarta.apache.org'
> Subject: Simulating a dropped connection
>
> Hi
>
> I've just come across cactus and was wondering whether it is possible to
> simulate a dropped connection whilst sending request data. The scenario
> I'm
> am trying to emulate is that of a large file upload (multipart request)
> that
> is terminated due to a dropped connection or a user cancelling the
> request.
> My limited understanding of Cactus (c. 2 hours) suggests that whilst I
> should be able to set up a test to simulate a multipart request, it may
> not
> be so easy to simulate a dropped connection. Does anyone have any
> suggestions? For example is there a suitable extension point within cactus
> from where one could potentially control the http connection and data
> stream
> being sent.
>
> Thanks Rob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>




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


RE: Simulating a dropped connection

Posted by Vincent Massol <vm...@pivolis.com>.
Hi Rob,

I don't think Cactus can help here. However you should be able to do what
you wish by using MockObjects. Say you have a method called
processRequest(HttpRequest) that processes the upload. You should be able to
easily test it unitarily by using a mock HttpRequest and telling it to throw
an exception after such amount of data has been read, etc.

Cactus is about executing the tests with real objects from the container
(i.e. real HttpRequests). With Mock Objects you can simulate them. See
www.mockobjects.com (I also recommend my book JUnit in Action of course...
;-)).

Thanks
-Vincent

> -----Original Message-----
> From: Robert Godfrey [mailto:RGodfrey@buildonline.com]
> Sent: jeudi 23 septembre 2004 12:45
> To: 'cactus-user@jakarta.apache.org'
> Subject: Simulating a dropped connection
> 
> Hi
> 
> I've just come across cactus and was wondering whether it is possible to
> simulate a dropped connection whilst sending request data. The scenario
> I'm
> am trying to emulate is that of a large file upload (multipart request)
> that
> is terminated due to a dropped connection or a user cancelling the
> request.
> My limited understanding of Cactus (c. 2 hours) suggests that whilst I
> should be able to set up a test to simulate a multipart request, it may
> not
> be so easy to simulate a dropped connection. Does anyone have any
> suggestions? For example is there a suitable extension point within cactus
> from where one could potentially control the http connection and data
> stream
> being sent.
> 
> Thanks Rob
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>