Wiremock

Performance testing early in the product development life cycle often means that a full end to end environment is not available. This is where the use of mocks and stubs can be very helpful to plug the gaps.

I recently came across a light weight and rapid mock application called Wiremock (http://wiremock.org/). It is a standalone Java program that can be configured using flat JSON files. You simply need JAVA installed on the server to create a mock. The product is free to download and use and there is Pro support if you require it.

The documentation is relatively straight forward and can be found at http://wiremock.org/docs/.

STEPS

1. Ensure JAVA is installed and you have permissions to execute a JAR on that server.

2. Copy the standalone JAR in this case wiremock-standalone-2.18.0.jar to the server.

3. To start the mock server simply run java -jar wiremock-standalone-2.18.0.jar

4. You can then either manually create JSON files which contain the request and response details or can browse to the swaggerui interface (http://localhost:8080/__admin/swagger-ui/) and use the interface to create them.

5. Below are a handful of example JSON files.

EXAMPLES

Example 1

This is showing a more complex response. Wiremock can transform elements of the request with it’s built in engine. Parameters are typically rendered in { } braces. In this case the delimiters have been altered to use <* and *> to avoid a conflict with { values used within the call. 

Every match in Wiremock is based on matching the request url. Once Wiremock finds a matching incoming request it will respond with the assigned response. 

Typically, there will always be a delay in the server responding to a request. Wiremock can simulate that delay shown here under delay distribution.

{         "request": {                 "url": "/api/mytest",                 "method": "POST"         },         "response": {                 "status": 200,                 "body": "{{#assign 'GUID'}}{{randomValue type='UUID'}}{{=<* *>=}}Hello World from  <*GUID*>",                 "delayDistribution": {                         "type": "lognormal",                         "median": 1000,                         "sigma": 2                 }         }         "headers": {                 "Content-Type": "text/plain",                 "Cache-Control": "no-cache"         } }

Example 2

A more basic example which returns a simple body with the current date/time embedded. Again a delay is introduced with a lower and upper limit set.

{         "request": {                 "url": "/api/mytest2",                 "method": "POST"         },         "response": {                 "status": 200,                 "body": "Today is  bye bye World",                 "delayDistribution": {                         "type": "uniform",                         "lower": 100,                         "upper": 300                 }         } }

As you can see by simply downloading and copying wiremock standalone and creating two JSON files we can rapidly simulate a number of end points.

The good news is Wiremock is very fast and light weight. Depending on your hardware you should be able to achieve 1000s of requests per second on a single machine.

Previous
Previous

Never give in

Next
Next

Blurring the lines