Skip to content

socialsoftware/business-logic-consistency-models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Simulator

The artifact supports the test of business logic of a microservices application designed on the concept of Domain-Driven Design Aggregate and using several transactional models. The current implementations are:

  • Transactional Causal Consistency
  • Eventual Consistency
    • Sagas applying the Orchestration variant (under development)

The system allows testing the interleaving of functionalities execution in a deterministic context, such that it is possible to evaluate the resulting behavior.

Run Using Docker

Technology Requirements

Usage

  • Build the application
docker compose build
  • Running the application
docker compose up backend
  • Running Spock Tests
docker compose up unit-tests

Run Using Maven

Technology Requirements

Setting up the database

  • Start db
sudo service postgresql start
sudo su -l postgres
dropdb blcmdb
createdb blcmdb
  • Create user to access db
psql blcmdb
CREATE USER your-username WITH SUPERUSER LOGIN PASSWORD 'yourpassword';
\q
exit
  • Copy backend/src/main/resources/application-dev.properties.example to application-dev.properties and fill the placeholder fields.

Running the application

cd backend
mvn clean spring-boot:run

Running Spock tests

cd backend
mvn clean -Ptest test

Running JMeter tests

  • After starting application, either using Docker or Maven, and installing JMeter
cd backend/jmeter/tournament/thesis-cases/
jmeter -n -t TEST.jmx

Viewing JMeter tests structure

cd backend/jmeter/tournament/thesis-cases/
jmeter
  • The command launches JMeter GUI. By clicking File > Open and selecting a test file it is possible to observe the test structure.
  • Tests can also be run using the GUI, by clicking on the Start button.

How to implement and test your own business logic

The code follows the structure in the figure, where the packages in blue and orange contain, respectively, the microservices domain specific code and the transactional causal consistency domain specific code.

Code Structure

The figure shows the main classes to be extended in the steps described next.

Code Structure

Apply the following steps:

  1. Define Aggregate: Each microservice is modeled as an aggregate. The first step is to define the aggregates. The simulator uses Spring-Boot and JPA, so the domain entities definition uses the JPA notation. In Tournament aggregate we can see the aggregate root entity and the reference to its internal entities.
  2. Specify Invariants: The aggregate invariants are defined by overriding method verifyInvariants().
  3. Define Causal Aggregates: Extend aggregates with the information required to process merges, like CausalTournament.
  4. Define Events: Define the events published by upstream aggregates and subscribed by downstream aggregates, like UpdateStudentNameEvent.
  5. Subscribe Events: The events published by upstream aggregates can be subscribed by overriding method getEventSubscriptions().
  6. Define Event Subscriptions: Events can be subscribed depending on its data. Therefore, define subscription classes like TournamentSubscribesUpdateStudentName.
  7. Define Event Handlers: For each subscribed event define an event handler that delegates the handling in a handling functionality, like UpdateStudentNameEventHandler and its handling functionality processUpdateStudentNameEvent(...).
  8. Define Functionalities: Functionalities coordinate the execution of aggregate services using TCC, like functionality updateStudentName(...), where each service interacts with the unit of work to register changes and publish events, like service updateExecutionStudentName(...).
  9. Define Test Cases: Define deterministic tests cases for the concurrent execution of functionalities using services to decrement the system version number, which defines functionalities execution order, and to force the deterministic processing of events, like in the Concurrent Execution of Update Name and Add Participant.

Spock Tests in DAIS2023 paper - 23nd International Conference on Distributed Applications and Interoperable Systems

To reproduce the paper results follow the steps:

  • Analyze a figure in the paper, fig3a-d and fig4;
  • Read the test case code for the figure, including the final assertions that define the expected behavior (see below);
  • Run the test case (see below);
  • Read the logger INFO messages, they use UPPERCASE. They identify when a functionality and event processing starts and ends and what its version number is.
    • For instance, in test-fig4 both functionalities start with the same version number (they are concurrent), but addParticipant finishes with a higher number, because it finishes after updateName. It can be observed in the log that an exception was thrown, due to the invariant break.

Figure 3(a)

docker-compose up test-fig3a

Figure 3(b)

docker-compose up test-fig3b

Figure 3(c)

docker-compose up test-fig3c

Figure 3(d)

docker-compose up test-fig3d

Figure 4

docker-compose up test-fig4