@Test @DisplayName("strip all events which occurred before snapshot") void trimBeforeSnapshot() { fillEvents(3); fillEventsWithSnapshot(5); int expectedEventCount = 7; fillEvents(expectedEventCount); AggregateReadRequest<String> request = new AggregateReadRequest<>(ID, 100); ReadOperation<String> operation = new ReadOperation<>(storage, request); Optional<AggregateHistory> record = operation.perform(); assertTrue(record.isPresent()); AggregateHistory stateRecord = record.get(); assertTrue(stateRecord.hasSnapshot()); assertThat(stateRecord.getEventList()).hasSize(expectedEventCount); }
Optional<AggregateHistory> perform() { Iterator<AggregateEventRecord> historyBackward = storage.historyBackward(request); if (!historyBackward.hasNext()) { return Optional.empty(); } while (historyBackward.hasNext() && snapshot == null) { AggregateEventRecord record = historyBackward.next(); handleRecord(record); } AggregateHistory result = buildRecord(); return Optional.of(result); }
ReadOperation { Optional<AggregateHistory> perform() { Iterator<AggregateEventRecord> historyBackward = storage.historyBackward(request); if (!historyBackward.hasNext()) { return Optional.empty(); } while (historyBackward.hasNext() && snapshot == null) { AggregateEventRecord record = historyBackward.next(); handleRecord(record); } AggregateHistory result = buildRecord(); return Optional.of(result); } }
ReadOperation { Optional<AggregateHistory> perform() { Iterator<AggregateEventRecord> historyBackward = storage.historyBackward(request); if (!historyBackward.hasNext()) { return Optional.empty(); } while (historyBackward.hasNext() && snapshot == null) { AggregateEventRecord record = historyBackward.next(); handleRecord(record); } AggregateHistory result = buildRecord(); return Optional.of(result); } ReadOperation(AggregateStorage<I> storage, AggregateReadRequest<I> request); }
ReadOperation { Optional<AggregateHistory> perform() { Iterator<AggregateEventRecord> historyBackward = storage.historyBackward(request); if (!historyBackward.hasNext()) { return Optional.empty(); } while (historyBackward.hasNext() && snapshot == null) { AggregateEventRecord record = historyBackward.next(); handleRecord(record); } AggregateHistory result = buildRecord(); return Optional.of(result); } ReadOperation(AggregateStorage<I> storage, AggregateReadRequest<I> request);  }
ReadOperation { Optional<AggregateHistory> perform() { Iterator<AggregateEventRecord> historyBackward = storage.historyBackward(request); if (!historyBackward.hasNext()) { return Optional.empty(); } while (historyBackward.hasNext() && snapshot == null) { AggregateEventRecord record = historyBackward.next(); handleRecord(record); } AggregateHistory result = buildRecord(); return Optional.of(result); } ReadOperation(AggregateStorage<I> storage, AggregateReadRequest<I> request);   }