refactoring infrastructure

This commit is contained in:
2025-10-14 12:47:16 +02:00
parent 689458e9b1
commit e8f33e465c
2 changed files with 8 additions and 5 deletions
@@ -3,6 +3,7 @@ package at.mocode.infrastructure.cache.redis
import at.mocode.infrastructure.cache.api.CacheConfiguration import at.mocode.infrastructure.cache.api.CacheConfiguration
import at.mocode.infrastructure.cache.api.CacheSerializer import at.mocode.infrastructure.cache.api.CacheSerializer
import at.mocode.infrastructure.cache.api.DefaultCacheConfiguration import at.mocode.infrastructure.cache.api.DefaultCacheConfiguration
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.context.properties.EnableConfigurationProperties
@@ -66,7 +67,9 @@ class RedisConfiguration {
* @return Redis template * @return Redis template
*/ */
@Bean @Bean
fun redisTemplate(connectionFactory: RedisConnectionFactory): RedisTemplate<String, ByteArray> { fun redisTemplate(
@Qualifier("redisConnectionFactory") connectionFactory: RedisConnectionFactory
): RedisTemplate<String, ByteArray> {
return RedisTemplate<String, ByteArray>().apply { return RedisTemplate<String, ByteArray>().apply {
setConnectionFactory(connectionFactory) setConnectionFactory(connectionFactory)
keySerializer = StringRedisSerializer() keySerializer = StringRedisSerializer()
@@ -96,7 +96,7 @@ class RedisCacheAndEventStoreIntegrationTest {
class TestConfig { class TestConfig {
@Bean @Bean
fun distributedCache( fun distributedCache(
redisTemplate: RedisTemplate<String, ByteArray>, @Qualifier("redisTemplate") redisTemplate: RedisTemplate<String, ByteArray>,
cacheConfiguration: CacheConfiguration cacheConfiguration: CacheConfiguration
): DistributedCache { ): DistributedCache {
return RedisDistributedCache( return RedisDistributedCache(
@@ -148,7 +148,7 @@ class RedisCacheAndEventStoreIntegrationTest {
) )
println("[DEBUG_LOG] EventStore: Appending event for aggregateId=$aggregateId") println("[DEBUG_LOG] EventStore: Appending event for aggregateId=$aggregateId")
eventStore.appendToStream(event, aggregateId, -1L) eventStore.appendToStream(event, aggregateId, 0L)
val loadedEvents = eventStore.readFromStream(aggregateId) val loadedEvents = eventStore.readFromStream(aggregateId)
println("[DEBUG_LOG] EventStore: Loaded ${loadedEvents.size} events") println("[DEBUG_LOG] EventStore: Loaded ${loadedEvents.size} events")
@@ -216,7 +216,7 @@ class RedisCacheAndEventStoreIntegrationTest {
eventType = EventType("TestEvent"), eventType = EventType("TestEvent"),
data = mapOf("key" to sharedKey) data = mapOf("key" to sharedKey)
) )
eventStore.appendToStream(event, aggregateId, -1L) eventStore.appendToStream(event, aggregateId, 0L)
println("[DEBUG_LOG] Stored event in event store with aggregateId=$aggregateId") println("[DEBUG_LOG] Stored event in event store with aggregateId=$aggregateId")
// Both should be retrievable independently // Both should be retrievable independently
@@ -244,7 +244,7 @@ class RedisCacheAndEventStoreIntegrationTest {
val data: Map<String, String>, val data: Map<String, String>,
override val eventId: EventId = EventId(Uuid.random()), override val eventId: EventId = EventId(Uuid.random()),
override val timestamp: kotlin.time.Instant = kotlin.time.Clock.System.now(), override val timestamp: kotlin.time.Instant = kotlin.time.Clock.System.now(),
override val version: EventVersion = EventVersion(0), override val version: EventVersion = EventVersion(1),
override val correlationId: CorrelationId? = null, override val correlationId: CorrelationId? = null,
override val causationId: CausationId? = null override val causationId: CausationId? = null
) : DomainEvent ) : DomainEvent