@Test void testScheduleSnapshot_ConcurrencyExceptionIsSilenced() { final String aggregateIdentifier = "aggregateIdentifier"; doNothing() .doThrow(new ConcurrencyException("Mock")) .when(mockEventStore).storeSnapshot(isA(DomainEventMessage.class)); when(mockEventStore.readEvents(aggregateIdentifier)) .thenAnswer(invocationOnMock -> DomainEventStream.of(createEvents(2))); testSubject.scheduleSnapshot(Object.class, aggregateIdentifier); testSubject.scheduleSnapshot(Object.class, aggregateIdentifier); verify(mockEventStore, times(2)).storeSnapshot(argThat(event(aggregateIdentifier, 1))); verify(logger, never()).warn(anyString()); verify(logger, never()).error(anyString()); }
@Override public void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier) { if (CurrentUnitOfWork.isStarted() && CurrentUnitOfWork.get().phase().isBefore(UnitOfWork.Phase.COMMIT)) { CurrentUnitOfWork.get().afterCommit(u -> doScheduleSnapshot(aggregateType, aggregateIdentifier)); } else { doScheduleSnapshot(aggregateType, aggregateIdentifier); } }
AbstractSnapshotter implements Snapshotter { @Override public void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier) { if (CurrentUnitOfWork.isStarted() && CurrentUnitOfWork.get().phase().isBefore(UnitOfWork.Phase.COMMIT)) { CurrentUnitOfWork.get().afterCommit(u -> doScheduleSnapshot(aggregateType, aggregateIdentifier)); } else { doScheduleSnapshot(aggregateType, aggregateIdentifier); } } }
AbstractSnapshotter implements Snapshotter { @Override public void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier) { if (CurrentUnitOfWork.isStarted() && CurrentUnitOfWork.get().phase().isBefore(UnitOfWork.Phase.COMMIT)) { CurrentUnitOfWork.get().afterCommit(u -> doScheduleSnapshot(aggregateType, aggregateIdentifier)); } else { doScheduleSnapshot(aggregateType, aggregateIdentifier); } } protected  AbstractSnapshotter(Builder builder); }
AbstractSnapshotter implements Snapshotter { @Override public void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier) { if (CurrentUnitOfWork.isStarted() && CurrentUnitOfWork.get().phase().isBefore(UnitOfWork.Phase.COMMIT)) { CurrentUnitOfWork.get().afterCommit(u -> doScheduleSnapshot(aggregateType, aggregateIdentifier)); } else { doScheduleSnapshot(aggregateType, aggregateIdentifier); } } protected  AbstractSnapshotter(Builder builder); @Override void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier); }
AbstractSnapshotter implements Snapshotter { @Override public void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier) { if (CurrentUnitOfWork.isStarted() && CurrentUnitOfWork.get().phase().isBefore(UnitOfWork.Phase.COMMIT)) { CurrentUnitOfWork.get().afterCommit(u -> doScheduleSnapshot(aggregateType, aggregateIdentifier)); } else { doScheduleSnapshot(aggregateType, aggregateIdentifier); } } protected  AbstractSnapshotter(Builder builder); @Override void scheduleSnapshot(Class<?> aggregateType, String aggregateIdentifier);  }