2.4 Using the Lab
Starting the Lab
Open a shell and change your directory to the
docker folder withing the monolith lab folder.
Start the microservices with
Now your environment is up and running.
Using the Lab
|http://localhost:8080/shop-orders||application||Return and create new orders|
|http://localhost:8080/article-stocks||application||List article stock count|
|http://localhost:8080/chaos-monkey||application||Lets you add a ChaosMonkey|
In the folder
requests within the monolith lab folder there is an IntelliJ IDEA compatible
HTTP Request file named
api.http. You may run the requests directly from this file or build your own requests.
Get the article stock information
Get order information
Create new order
Task 2.4.1 - Testing scenario
Run the following queries:
- Check the article-stock count
- Create an order for one item of article
- Check the orders and article-stock again
Answer the questions:
- Is the article-stock count correct?
- What happens if you are running out of stock?
There is a basic implementation of a ChaosMonkey. It will let you inject errors to methods annotated with
You may configure the ChaosMonkey using the provided RESTful API
The following error types are available:
|RateLimit||Before method||Rate limit in calls/sec. Default:
|Latency||After method||Issues a Thread.sleep() in ms. Default: 0|
|ErrorRate||After method||Lets you specify a percentage of Errors thrown (0 to 1). Default: 0|
|Exception||After method||Always triggers an exception if enabled. Default:
Sample request for configuring the ChaosMonkey which will throw an exception:
Task 2.4.2 - Injecting an error
Enable a ChaosMonkey for the method
orderArticles in the
This will throw an
InternalServerErrorException after execution of the method
- Ask yourself what to expect if an exception is thrown?
Issue the request from the Task 2.4.1.
- What did you observe? Is there any difference?
- Is the data still consistent?
- What’s the role of a transaction in this case?
Since the application throws an
InternalServerErrorException the order is not created and the stock count remains the
This is due to the fact that the code runs in a single transaction. Throwing a
RuntimeException from an active
transaction triggers a rollback of the transaction.