From aed100e55ae9f1e225ca5078f4fb93f366ff10d8 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Mon, 11 Nov 2024 21:07:17 +0800 Subject: [PATCH] feat(es): Support AggregateIdScanner to SnapshotRepository --- .../state/ResendStateEventHandlerTest.kt | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/wow-webflux/src/test/kotlin/me/ahoo/wow/webflux/route/event/state/ResendStateEventHandlerTest.kt b/wow-webflux/src/test/kotlin/me/ahoo/wow/webflux/route/event/state/ResendStateEventHandlerTest.kt index cbcde966a1..eed94f2d5b 100644 --- a/wow-webflux/src/test/kotlin/me/ahoo/wow/webflux/route/event/state/ResendStateEventHandlerTest.kt +++ b/wow-webflux/src/test/kotlin/me/ahoo/wow/webflux/route/event/state/ResendStateEventHandlerTest.kt @@ -4,30 +4,48 @@ import me.ahoo.wow.command.toCommandMessage import me.ahoo.wow.event.compensation.StateEventCompensator import me.ahoo.wow.event.toDomainEventStream import me.ahoo.wow.eventsourcing.InMemoryEventStore -import me.ahoo.wow.eventsourcing.snapshot.NoOpSnapshotRepository +import me.ahoo.wow.eventsourcing.snapshot.InMemorySnapshotRepository +import me.ahoo.wow.eventsourcing.snapshot.SimpleSnapshot +import me.ahoo.wow.eventsourcing.snapshot.Snapshot import me.ahoo.wow.eventsourcing.state.InMemoryStateEventBus import me.ahoo.wow.id.generateGlobalId +import me.ahoo.wow.modeling.aggregateId import me.ahoo.wow.modeling.state.ConstructorStateAggregateFactory import me.ahoo.wow.tck.mock.MOCK_AGGREGATE_METADATA import me.ahoo.wow.tck.mock.MockAggregateCreated import me.ahoo.wow.tck.mock.MockCreateAggregate +import me.ahoo.wow.tck.mock.MockStateAggregate import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* import org.junit.jupiter.api.Test import reactor.kotlin.test.test +import java.time.Clock class ResendStateEventHandlerTest { @Test fun handle() { + val snapshotRepository = InMemorySnapshotRepository() + val aggregateId = MOCK_AGGREGATE_METADATA.aggregateId(generateGlobalId()) + val stateAggregate = + ConstructorStateAggregateFactory.create(MOCK_AGGREGATE_METADATA.state, aggregateId).block()!! + val snapshot: Snapshot = + SimpleSnapshot(stateAggregate, Clock.systemUTC().millis()) + snapshotRepository.save(snapshot) + .test() + .verifyComplete() + val eventStore = InMemoryEventStore() - val commandMessage = MockCreateAggregate("1", "data").toCommandMessage() + val commandMessage = MockCreateAggregate("1", "data").toCommandMessage( + aggregateId = aggregateId.id, + tenantId = aggregateId.tenantId + ) val eventStream = MockAggregateCreated(generateGlobalId()) .toDomainEventStream(commandMessage, 0) eventStore.appendStream(eventStream).test().verifyComplete() val handlerFunction = ResendStateEventHandler( aggregateMetadata = MOCK_AGGREGATE_METADATA, - snapshotRepository = NoOpSnapshotRepository, + snapshotRepository = snapshotRepository, stateEventCompensator = StateEventCompensator( stateAggregateFactory = ConstructorStateAggregateFactory, eventStore = eventStore,