|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Test\Ecotone\EventSourcing\Integration; |
| 6 | + |
| 7 | +use Ecotone\Dbal\Configuration\DbalConfiguration; |
| 8 | +use Ecotone\Dbal\DbalBackedMessageChannelBuilder; |
| 9 | +use Ecotone\EventSourcing\EventSourcingConfiguration; |
| 10 | +use Ecotone\Lite\EcotoneLite; |
| 11 | +use Ecotone\Messaging\Config\ModulePackageList; |
| 12 | +use Ecotone\Messaging\Config\ServiceConfiguration; |
| 13 | +use Ecotone\Messaging\Endpoint\ExecutionPollingMetadata; |
| 14 | +use Enqueue\Dbal\DbalConnectionFactory; |
| 15 | +use Test\Ecotone\EventSourcing\EventSourcingMessagingTestCase; |
| 16 | +use Test\Ecotone\EventSourcing\Fixture\MultipleAsyncHandlersForOneMessage\ActionCommand; |
| 17 | +use Test\Ecotone\EventSourcing\Fixture\MultipleAsyncHandlersForOneMessage\EventConverter; |
| 18 | +use Test\Ecotone\EventSourcing\Fixture\MultipleAsyncHandlersForOneMessage\TestAggregate; |
| 19 | + |
| 20 | +final class MultipleAsyncHandlersForOneMessageTest extends EventSourcingMessagingTestCase |
| 21 | +{ |
| 22 | + public function test_handling_multiple_same_messages(): void |
| 23 | + { |
| 24 | + $ecotone = EcotoneLite::bootstrapFlowTestingWithEventStore( |
| 25 | + classesToResolve: [TestAggregate::class, EventConverter::class], |
| 26 | + containerOrAvailableServices: [ |
| 27 | + new EventConverter(), |
| 28 | + DbalConnectionFactory::class => self::getConnectionFactory(), |
| 29 | + ], |
| 30 | + configuration: ServiceConfiguration::createWithDefaults() |
| 31 | + ->withSkippedModulePackageNames(ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE, ModulePackageList::ASYNCHRONOUS_PACKAGE])) |
| 32 | + ->withNamespaces(['Test\Ecotone\Modelling\Fixture\MultipleAsyncHandlersForOneMessage']) |
| 33 | + ->withExtensionObjects([ |
| 34 | + DbalConfiguration::createWithDefaults(), |
| 35 | + EventSourcingConfiguration::createWithDefaults(), |
| 36 | + DbalBackedMessageChannelBuilder::create("testAggregate"), |
| 37 | + ]), |
| 38 | + runForProductionEventStore: true |
| 39 | + ); |
| 40 | + |
| 41 | + $ecotone->sendCommand(new ActionCommand('123')); |
| 42 | + $ecotone->sendCommand(new ActionCommand('123')); |
| 43 | + |
| 44 | + $ecotone->run('testAggregate', ExecutionPollingMetadata::createWithTestingSetup()); |
| 45 | + self::assertEquals(1, $ecotone->getAggregate(TestAggregate::class, '123')->counter()); |
| 46 | + |
| 47 | + $ecotone->run('testAggregate', ExecutionPollingMetadata::createWithTestingSetup()); |
| 48 | + self::assertEquals(2, $ecotone->getAggregate(TestAggregate::class, '123')->counter()); |
| 49 | + } |
| 50 | +} |
0 commit comments