Assessment, benchmarking and stress-testing resilience of ...
Resilience testing with Wiremock and Spock
-
Upload
david-schmitz -
Category
Technology
-
view
718 -
download
5
Transcript of Resilience testing with Wiremock and Spock
![Page 1: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/1.jpg)
Resilient Services with Wiremock Effective REST tests using Wiremock and Spock
https://flic.kr/p/orejhX
![Page 3: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/3.jpg)
Everybody tests the happy path…
https://flic.kr/p/9MHEme
![Page 4: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/4.jpg)
Happy Path Tests
HTTP/1.1 200 OK
{“publicId":"42634558","data":"foo"}
GET http://service/resource/12
Client Service
![Page 5: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/5.jpg)
But what about the not-so-happy path?
https://flic.kr/p/CSnr1
![Page 6: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/6.jpg)
Enter Wiremock• Stub and Mock framework
for testing HTTP(s) traffic
• Features include
• Request verification,
• record, playback,
• fault injection,
• unit test and stand alone
Client Unit Test
EmbeddedWiremock
Client Standalone Wiremock
![Page 7: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/7.jpg)
How does it work?
Client Wiremock
Request Mapping
Response Data
$ curl -H ‘Accept: application/json’ http://localhost:8080/sample/
![Page 8: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/8.jpg)
How does it work?
Client Wiremock
Request Mapping
Response Data
• Starts embedded Jetty Server
• Acts as a proxy to the actual service
• Is used by the client transparently
![Page 9: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/9.jpg)
How does it work?
Client Wiremock
Request Mapping
Response Data
"request" : { "url" : "/sample/", "method" : "GET", } } }, "response" : { "status" : 200, "bodyFileName" : "body.json", "headers" : { "Content-Type" : “application/json" … } }
![Page 10: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/10.jpg)
How does it work?
Client Wiremock
Request Mapping
Response Data
body.json: [{"publicId":"...","data":"..."}, {"publicId":"...","data":"..."}]
![Page 11: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/11.jpg)
Creating a Wiremock Unittest
Prepare Stub
Configure Wiremock
Consume REST service
![Page 12: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/12.jpg)
Creating a Wiremock Unittest
Prepare Stub
Configure Wiremock
Consume REST service
![Page 13: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/13.jpg)
Creating a Wiremock Unittest
Prepare Stub
Configure Wiremock
Consume REST service
![Page 14: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/14.jpg)
Creating a Wiremock Unittest
Prepare Stub
Configure Wiremock
Consume REST service
![Page 15: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/15.jpg)
Creating a Wiremock Unittest
Prepare Stub
Configure Wiremock
Consume REST service
![Page 16: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/16.jpg)
…but what about failures?
HTTP/1.1 503 Service Unavailable
Client Service
GET http://service/resource/12
![Page 18: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/18.jpg)
…but what about bad responses?
Client Service
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8
[300 MB of random garbage]
GET http://service/resource/12
![Page 20: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/20.jpg)
…but what about timeouts?
java.net.SocketTimeoutException: Read timed out
Client Service
GET http://service/resource/12
![Page 22: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/22.jpg)
Record and Playback
https://flic.kr/p/nRXLqh
![Page 23: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/23.jpg)
Record and Playback
Run requests
Start Wiremock in record mode
Start Wiremock in playback mode
![Page 25: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/25.jpg)
Summary• Resilience can be tested
• Do not rely on happy paths and mocks only
• Use stubs and verify in unit tests
• Use record and playback for external services
• Make sure not to be the developer responsible for a downtime during the busy-business-time :D
![Page 26: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/26.jpg)
Links
http://wiremock.org/
https://github.com/koenighotze/wiremock-tryout/
![Page 27: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/27.jpg)
THANK YOU!<[email protected]>
![Page 29: Resilience testing with Wiremock and Spock](https://reader036.fdocuments.us/reader036/viewer/2022082204/5871ae6c1a28abda6a8b61a3/html5/thumbnails/29.jpg)
Testing a ClientClient Unit Test
EmbeddedWiremock