Loading repository data…
Loading repository data…
Rapter1990 / repository
Case Study - Sample Book Delivery App (Spring Boot, Spring Security , Mysql, JUnit, Integration Test, Docker, Test Container, AOP, CI/CD, Prometheus, Grafana, Github Actions)
We implemented a pessimistic lock mechanism to avoid scenarios where multiple users attempt to order books simultaneously, ensuring that their actions are synchronized properly to prevent data conflicts. So with a pessimstic lock, if multiple users attempt to order one last stock of a book, only one of them will be able to order.
Installation
sudo apt-get install apache2
To test, you need to make requests to the create order endpoint. So you're going to need a valid payload json which is shown below. (Do not forget to change the bookId with a valid one)
{
"orderDetailSet": [
{
"bookId": "3a0e7efc-1e32-404c-9a70-d9fb63262c6e",
"amount": 1
}
]
}
Now we can test the create order endpoint, and see if the locking mechanism works
Here is the example shown below for testing
ab -n 100 -c 2 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX0NVU1RPTUVSIl0sInVzZXJGdWxsTmFtZSI6ImN1c3RvbWVyX2Z1bGxuYW1lIiwiaWQiOjIsImVtYWlsIjoiY3VzdG9tZXJAYm9va2RlbGl2ZXJ5LmNvbSIsInVzZXJuYW1lIjoiY3VzdG9tZXJfMSIsInN1YiI6ImN1c3RvbWVyXzEiLCJpYXQiOjE2OTQ4ODkyNTMsImV4cCI6MTY5NDg4OTg1M30.UokFWxgZnSnYZsbAlwbfhQj1F54QrEOU5_5KzHyRmtY" -T "application/json" -p post_data.json http://localhost:1221/api/v1/orders
http://localhost:1221/swagger-ui/index.html
DATABASE_USERNAME={DATABASE_USERNAME}
DATABASE_PASSWORD={DATABASE_PASSWORD}
The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
$ cd bookdelivery
$ docker-compose up -d
If you change anything in the project and run it on Docker, you can also use this command shown below
$ cd bookdelivery
$ docker-compose up --build
To build and run the application with Maven, please follow the directions shown below;
$ cd bookdelivery
$ mvn clean install
$ mvn spring-boot:run