public function testSaveStreamAndReadBackIn() { $eventStore = new FilesystemEventStore($this->fileResolver, $this->serializer); $event1 = new GenericDomainEventMessage($this->aggregateIdentifier, 0, new StubDomainEvent()); $event2 = new GenericDomainEventMessage($this->aggregateIdentifier, 1, new StubDomainEvent()); $event3 = new GenericDomainEventMessage($this->aggregateIdentifier, 2, new StubDomainEvent()); $stream = new SimpleDomainEventStream(array($event1, $event2, $event3)); $eventStore->appendEvents("test", $stream); $eventStream = $eventStore->readEvents("test", $this->aggregateIdentifier); $domainEvents = array(); while ($eventStream->hasNext()) { $domainEvents[] = $eventStream->next(); } $this->assertEquals($event1->getIdentifier(), $domainEvents[0]->getIdentifier()); $this->assertEquals($event2->getIdentifier(), $domainEvents[1]->getIdentifier()); $this->assertEquals($event3->getIdentifier(), $domainEvents[2]->getIdentifier()); }
public function readEvents($type, $identifier) { $snapshotScn = -1; $snapshotEvent = null; $lastSnapshotEvent = $this->entryStore->loadLastSnapshotEvent($type, $identifier, $this->entityManager); if (null !== $lastSnapshotEvent) { try { $snapshotEvent = new GenericDomainEventMessage($identifier, $lastSnapshotEvent->getScn(), $this->serializer->deserialize($lastSnapshotEvent->getPayload()), $this->serializer->deserialize($lastSnapshotEvent->getMetaData())); $snapshotScn = $snapshotEvent->getScn(); } catch (\RuntimeException $ex) { $this->logger->warn("Error while reading snapshot event entry. " . "Reconstructing aggregate on entire event stream. Caused by: {class} {message}", array('class' => get_class($ex), 'message' => $ex->getMessage())); } } $entries = $this->entryStore->fetchAggregateStream($type, $identifier, $snapshotScn, $this->batchSize, $this->entityManager); if ($snapshotEvent === null && !$entries->valid()) { throw new EventStreamNotFoundException($type, $identifier); } return new OrmDomainEventStream($this->serializer, $entries, $identifier, $snapshotEvent); }
/** * @covers Governor\Framework\Domain\GenericDomainEventMessage::andMetaData */ public function testAndMetaData() { $payload = new Payload(); $seqNo = 0; $id = Uuid::uuid1(); $metaData = new MetaData(['key' => 'value']); $message = new GenericDomainEventMessage($id, $seqNo, $payload, $metaData); $message1 = $message->andMetaData(); $message2 = $message->andMetaData(['key' => 'otherValue']); $this->assertEquals(1, $message1->getMetaData()->count()); $this->assertEquals('value', $message1->getMetaData()->get('key')); $this->assertEquals(1, $message2->getMetaData()->count()); $this->assertEquals('otherValue', $message2->getMetaData()->get('key')); $this->assertEquals($message->getTimestamp(), $message1->getTimestamp()); $this->assertEquals($message->getTimestamp(), $message2->getTimestamp()); $this->assertEquals($message->getIdentifier(), $message1->getIdentifier()); $this->assertEquals($message->getIdentifier(), $message2->getIdentifier()); $this->assertInstanceOf(GenericDomainEventMessage::class, $message1); $this->assertInstanceOf(GenericDomainEventMessage::class, $message2); }