Skip to content

Commit

Permalink
Merge pull request #98 from proophsoftware/fix/listeners_not_invoked
Browse files Browse the repository at this point in the history
Throw exception if TransactionalActionEventEmitter is used
  • Loading branch information
codeliner authored Jul 19, 2018
2 parents b4cc3a1 + 5615c84 commit 6fd195d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/EventMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,13 @@ private function attachEventPublisherToEventStore(): void

$eventPublisher->attachToEventStore($eventStore);

if ($eventStore instanceof TransactionalActionEventEmitterEventStore
&& ! $this->immediateConsistency
) {
if ($eventStore instanceof TransactionalActionEventEmitterEventStore) {
if ($this->immediateConsistency) {
throw new RuntimeException(
'You cannot use a ' . TransactionalActionEventEmitterEventStore::class
. ' together with immediate consistency. Wrap your event store with a ' . ActionEventEmitterEventStore::class . ' instead!');
}

$transactionManager = new TransactionManager($eventStore);
$commandBus = $this->container->get(self::SERVICE_ID_COMMAND_BUS);
$transactionManager->attachToMessageBus($commandBus);
Expand Down
34 changes: 34 additions & 0 deletions tests/EventMachineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Prooph\EventMachine\Container\ContainerChain;
use Prooph\EventMachine\Container\EventMachineContainer;
use Prooph\EventMachine\EventMachine;
use Prooph\EventMachine\Exception\RuntimeException;
use Prooph\EventMachine\Exception\TransactionCommitFailed;
use Prooph\EventMachine\JsonSchema\JsonSchema;
use Prooph\EventMachine\JsonSchema\Type\EmailType;
Expand Down Expand Up @@ -931,6 +932,39 @@ public function it_rolls_back_events_and_projection_with_immediate_consistency()
$this->assertEmpty(iterator_to_array($eventStore->load($streamName)));
}

/**
* @test
*/
public function it_switches_action_event_emitter_with_immediate_consistency(): void
{
$documentStore = new InMemoryDocumentStore($this->inMemoryConnection);

$inMemoryEventStore = new InMemoryEventStore($this->inMemoryConnection);

//A TransactionalActionEventEmitterEventStore conflicts with the immediate consistency mode
//because the EventPublisher listens on commit event, but it never happens due to transaction managed
//outside of the event store
//Event Machine needs to take care of it
$eventStore = new TransactionalActionEventEmitterEventStore(
$inMemoryEventStore,
new ProophActionEventEmitter(TransactionalActionEventEmitterEventStore::ALL_EVENTS)
);

$streamName = new StreamName('event_stream');

$this->setUpAggregateProjector($documentStore, $eventStore, $streamName);

$this->transactionManager = new TransactionManager($this->inMemoryConnection);
$publishedEvents = [];

$this->eventMachine->setImmediateConsistency(true);
$this->eventMachine->initialize($this->containerChain);

$this->expectException(RuntimeException::class);

$this->eventMachine->bootstrap();
}

private function assertUserWasRegistered(
GenericJsonSchemaEvent $event,
GenericJsonSchemaCommand $registerUser,
Expand Down

0 comments on commit 6fd195d

Please sign in to comment.