refactor(infra-event-store): Improve consistency and test reliability

This commit introduces a comprehensive refactoring of the event-store module to guarantee data consistency and improve the quality and reliability of its test suite.

Data Consistency
Implemented Redis transactions (MULTI/EXEC) for the appendToStream operation in RedisEventStore.

This ensures that writing an event to the aggregate-specific stream and the global "all-events" stream is an atomic operation, preventing data inconsistencies in case of partial failures.

Improved error handling by invalidating the local stream version cache on transactional failures.

Testing Enhancements
Refactored Consumer Tests: Replaced the asynchronous, thread-based consumer test in RedisIntegrationTest with a synchronous, deterministic approach. The test now manually calls pollEvents() to verify event consumption, making it faster and 100% reliable by removing Thread.sleep and CountDownLatch.

Simplified Test Events: Reduced boilerplate code in test event data classes (TestCreatedEvent, TestUpdatedEvent) in both RedisEventStoreTest and RedisIntegrationTest by using the @Transient annotation on overridden properties from BaseDomainEvent.

Fixed Compilation Errors: Resolved various compilation errors in the test suite that arose from refactoring and incorrect mock definitions.
This commit is contained in:
2025-08-09 18:03:04 +02:00
parent 4f67379b42
commit e72e4bddaa
7 changed files with 105 additions and 210 deletions
@@ -17,15 +17,15 @@ interface EventSerializer {
fun serialize(event: DomainEvent): Map<String, String>
/**
* Deserializes a map of strings to strings to a domain event.
* Deserializes a map of strings to a domain event.
*
* @param data The map of strings to strings to deserialize
* @param data The map of strings to deserialize
* @return The deserialized domain event
*/
fun deserialize(data: Map<String, String>): DomainEvent
/**
* Gets the type of a domain event.
* Gets the type of domain event.
* This is used to determine the type of event when deserializing.
*
* @param event The event to get the type of
@@ -34,7 +34,7 @@ interface EventSerializer {
fun getEventType(event: DomainEvent): String
/**
* Gets the type of a domain event from a serialized map.
* Gets the type of domain event from a serialized map.
*
* @param data The serialized event data
* @return The type of the event as a string