@Test public void testDomainEventEntry_WrapEventsCorrectly() { Serializer serializer = new XStreamSerializer(); String payload = "Payload"; MetaData metaData = new MetaData(Collections.singletonMap("Key", "Value")); DomainEventMessage<String> event = new GenericDomainEventMessage<>( "type", randomUUID().toString(), 2L, payload, metaData, randomUUID().toString(), Instant.now()); DomainEventEntry eventEntry = new DomainEventEntry(event, serializer); assertEquals(event.getAggregateIdentifier(), eventEntry.getAggregateIdentifier()); assertEquals(event.getSequenceNumber(), eventEntry.getSequenceNumber()); assertEquals(event.getTimestamp(), eventEntry.getTimestamp()); assertEquals(payload, serializer.deserialize(eventEntry.getPayload())); assertEquals(metaData, serializer.deserialize(eventEntry.getMetaData())); assertEquals(byte[].class, eventEntry.getPayload().getContentType()); }
/** * Constructor used to create a new event entry to store in Mongo. * * @param eventSerializer Serializer to use for the event to store * @param events The events contained in this commit */ private CommitEntry(Serializer eventSerializer, List<DomainEventMessage<?>> events) { this.aggregateIdentifier = events.get(0).getAggregateIdentifier(); this.firstSequenceNumber = events.get(0).getSequenceNumber(); this.firstTimestamp = events.get(0).getTimestamp().toEpochMilli(); final DomainEventMessage lastEvent = events.get(events.size() - 1); this.lastTimestamp = lastEvent.getTimestamp().toEpochMilli(); this.lastSequenceNumber = lastEvent.getSequenceNumber(); eventEntries = new EventEntry[events.size()]; for (int i = 0, eventsLength = events.size(); i < eventsLength; i++) { DomainEventMessage event = events.get(i); eventEntries[i] = new EventEntry(eventSerializer, event); } }
private EventEntry(Serializer serializer, DomainEventMessage event) { this.eventIdentifier = event.getIdentifier(); Class<?> serializationTarget = String.class; if (serializer.canSerializeTo(DBObject.class)) { serializationTarget = DBObject.class; } SerializedObject serializedPayloadObject = serializePayload(event, serializer, serializationTarget); SerializedObject serializedMetaDataObject = serializeMetaData(event, serializer, serializationTarget); this.serializedPayload = serializedPayloadObject.getData(); this.payloadType = serializedPayloadObject.getType().getName(); this.payloadRevision = serializedPayloadObject.getType().getRevision(); this.serializedMetaData = serializedMetaDataObject.getData(); this.sequenceNumber = event.getSequenceNumber(); this.timestamp = event.getTimestamp().toEpochMilli(); }