2.4 Using the Lab
Starting the Lab
Open a shell and change your directory to the /code/monolith/docker folder.
Start the microservices with
| |
Now your environment is up and running.
Using the Lab
Available Endpoints
| Endpoint | Container | Purpose |
|---|---|---|
| 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 |
Sample Requests
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
1 - 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?
ChaosMonkey
There is a basic implementation of a ChaosMonkey. It will let you inject errors to methods annotated with @ChaosMonkey.
You may configure the ChaosMonkey using the provided RESTful API /chaos-monkey.
The following error types are available:
| Error Type | Executed | Description |
|---|---|---|
| RateLimit | Before method | Rate limit in calls/sec. Default: Long.MAX_VALUE |
| 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: false |
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 ArticleStockService.
| |
This will throw an InternalServerErrorException after execution of the method orderArticles.
- 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?
Task Hint
Since the application throws an InternalServerErrorException the order is not created and the stock count remains the
same.
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.