@Test void testSnapshotReadFromActive() { DomainEventMessage<String> event1 = new GenericDomainEventMessage<>("type", "aggregate", 0, "test1"); DomainEventMessage<String> event2 = new GenericDomainEventMessage<>("type", "aggregate", 1, "test2"); when(historicStorage.readSnapshot("aggregate")).thenReturn(Optional.of(event2)); when(activeStorage.readSnapshot("aggregate")).thenReturn(Optional.of(event1)); Optional<DomainEventMessage<?>> actual = testSubject.readSnapshot("aggregate"); assertTrue(actual.isPresent()); assertSame(event1, actual.get()); InOrder inOrder = inOrder(historicStorage, activeStorage); inOrder.verify(activeStorage).readSnapshot("aggregate"); inOrder.verifyNoMoreInteractions(); }
@Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { Optional<DomainEventMessage<?>> optionalDomainEventMessage = activeStorage.readSnapshot(aggregateIdentifier); return optionalDomainEventMessage.isPresent() ? optionalDomainEventMessage : historicStorage.readSnapshot(aggregateIdentifier); }
SequenceEventStorageEngine implements EventStorageEngine { @Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { Optional<DomainEventMessage<?>> optionalDomainEventMessage = activeStorage.readSnapshot(aggregateIdentifier); return optionalDomainEventMessage.isPresent() ? optionalDomainEventMessage : historicStorage.readSnapshot(aggregateIdentifier); } }
SequenceEventStorageEngine implements EventStorageEngine { @Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { Optional<DomainEventMessage<?>> optionalDomainEventMessage = activeStorage.readSnapshot(aggregateIdentifier); return optionalDomainEventMessage.isPresent() ? optionalDomainEventMessage : historicStorage.readSnapshot(aggregateIdentifier); } SequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage); }
SequenceEventStorageEngine implements EventStorageEngine { @Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { Optional<DomainEventMessage<?>> optionalDomainEventMessage = activeStorage.readSnapshot(aggregateIdentifier); return optionalDomainEventMessage.isPresent() ? optionalDomainEventMessage : historicStorage.readSnapshot(aggregateIdentifier); } SequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage); @Override void appendEvents(List<? extends EventMessage<?>> events); @Override void storeSnapshot(DomainEventMessage<?> snapshot); @Override Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock); @Override DomainEventStream readEvents(String aggregateIdentifier, long firstSequenceNumber); @Override Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier); @Override Optional<Long> lastSequenceNumberFor(String aggregateIdentifier); @Override TrackingToken createTailToken(); @Override TrackingToken createHeadToken(); @Override TrackingToken createTokenAt(Instant dateTime); }
SequenceEventStorageEngine implements EventStorageEngine { @Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { Optional<DomainEventMessage<?>> optionalDomainEventMessage = activeStorage.readSnapshot(aggregateIdentifier); return optionalDomainEventMessage.isPresent() ? optionalDomainEventMessage : historicStorage.readSnapshot(aggregateIdentifier); } SequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage); @Override void appendEvents(List<? extends EventMessage<?>> events); @Override void storeSnapshot(DomainEventMessage<?> snapshot); @Override Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock); @Override DomainEventStream readEvents(String aggregateIdentifier, long firstSequenceNumber); @Override Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier); @Override Optional<Long> lastSequenceNumberFor(String aggregateIdentifier); @Override TrackingToken createTailToken(); @Override TrackingToken createHeadToken(); @Override TrackingToken createTokenAt(Instant dateTime);  }