Hi,
I am using __*Gatling*__ 2.2.2
I have been reading this page: http://gatling.io/docs/2.2.2/http/http_request.html
I am trying to create a Gatling simulation that uses a __*HttpRequestBuilder*__ with an __*InputStreamBody*__
My goal is to create a very fast and efficient HTTP request that generates on-the-fly N (N around 1-2 GB) random bytes to be sent via __*POST*__ method.
It is not important how the bytes are generated, but I don't want to store them in memory or in a resource/file.
And everything needs to be fast, using a stream.
I discarded the ideas of using __*RawFileBody*__ or __*ByteArrayBody*__ or *StringBody*, and I thought to pass an __*InputStream*__ to __*InputStreamBody*__
Below you can find my current code, which seems fine. But for some reasons it does not work correctly over 50kB.
Could you check if you spot anything wrong? Do I need to specify special headers in the request? What are your suggestions?
If I use __*RawFileBody*__ I can upload the without problems and quickly files over 1 GB. But as I said before I do not want to store files, I would like to be able to generate the bytes using a stream.
Thanks a lot
Stefano
// maximum Int value = 2147483647
def postInputStream(size: Int) = {
val postUploadUrl = "SOME_HTTP_URL"
val DUMMY_BYTE: Byte = 'A'.toByte
def generateFakeInputStream(n: Int): InputStream = {
require(n > 0)
val dummyInputStream = new InputStream {
var counter: Int = 0
def resetAndCloseStream: Int = {
counter = 0
-1 // end of stream
}
override def read(): Int = {
counter += 1
if (counter <= n) DUMMY_BYTE
else resetAndCloseStream
}
}
dummyInputStream
}
val headers = Map(
"Content-Length" -> String.valueOf(size),
"Content-Type" -> "text/plain"
)
def apiRequest(httpRequest: HttpRequestBuilder): HttpRequestBuilder =
httpRequest.check(status.saveAs("statusCode"))
val is: InputStream = StreamUtils.generateFakeInputStream(size)
val httpRequest = apiRequest(
http(s"POST with Upload Bytes $size")
.post(postUploadUrl)
.headers(headers)
.body(InputStreamBody(is))
.check(status.is(200)))
// is.close()
httpRequest
}
Have you tried with current snapshot?
I am trying now with 2.3.0-SNAPSHOT, but I do not see differences
Hi I am trying to do something similar but in a different way.
in my exec() i have:
Actually I just tried the above posted method. Same issue. I get an empty body.