public AggregateCrudSaveOptions withEventContext(EventContext ectx) { return new AggregateCrudSaveOptions(Optional.of(ectx), this.entityId); }
public AggregateCrudSaveOptions withId(String entityId) { return new AggregateCrudSaveOptions(this.triggeringEvent, Optional.of(entityId)); }
public AggregateCrudSaveOptions withId(String entityId) { return new AggregateCrudSaveOptions(this.triggeringEvent, Optional.of(entityId)); }
public AggregateCrudSaveOptions withEventContext(EventContext ectx) { return new AggregateCrudSaveOptions(Optional.of(ectx), this.entityId); }
public static Optional<AggregateCrudSaveOptions> toAggregateCrudSaveOptions(Optional<SaveOptions> saveOptions) { return saveOptions.map(so -> new AggregateCrudSaveOptions(so.getTriggeringEvent(), so.getEntityId())); }
public static Optional<AggregateCrudSaveOptions> toAggregateCrudSaveOptions(Optional<SaveOptions> saveOptions) { return saveOptions.map(so -> new AggregateCrudSaveOptions(so.getTriggeringEvent(), so.getEntityId())); }
private CompletableFuture<EntityIdVersionAndEventIds> saveWithId() { return client.save(RequestResponseJsonObjects.aggregateType, Collections.singletonList(new EventTypeAndData(RequestResponseJsonObjects.createdEvent, RequestResponseJsonObjects.eventData, Optional.empty())), Optional.of(new AggregateCrudSaveOptions().withId(RequestResponseJsonObjects.createId))); }
@Test public void updateShouldCompleteWithOptimisticLockingException() throws ExecutionException, InterruptedException { EntityIdVersionAndEventIds eidv = eventStore.save(aggregateType, singletonList(new EventTypeAndData("MyEventType", "{}", Optional.empty())), Optional.of(new AggregateCrudSaveOptions().withEventContext(ectx))); shouldCompletedExceptionally(OptimisticLockingException.class, () -> eventStore.update(new EntityIdAndType(eidv.getEntityId(), aggregateType), new Int128(0,0), singletonList(new EventTypeAndData("MyEventType", "{}", Optional.empty())), Optional.of(new AggregateCrudUpdateOptions()))); }
@Test public void findShouldCompleteWithDuplicateTriggeringEventException() throws ExecutionException, InterruptedException { EntityIdVersionAndEventIds eidv = eventStore.save(aggregateType, singletonList(new EventTypeAndData("MyEventType", "{}", Optional.empty())), Optional.of(new AggregateCrudSaveOptions().withEventContext(ectx))); shouldCompletedExceptionally(DuplicateTriggeringEventException.class, () -> eventStore.find(aggregateType, eidv.getEntityId(), Optional.of(new AggregateCrudFindOptions().withTriggeringEvent(ectx)))); }
@Test public void shouldSaveAndLoadSnapshot() { EntityIdVersionAndEventIds eidv = eventStore.save(aggregateType, singletonList(new EventTypeAndData("MyEventType", "{}", Optional.empty())), Optional.of(new AggregateCrudSaveOptions().withEventContext(ectx))); EntityIdVersionAndEventIds updateResult = eventStore.update( new EntityIdAndType(eidv.getEntityId(), aggregateType), eidv.getEntityVersion(), singletonList(new EventTypeAndData("MyEventType", "{}", Optional.empty())), Optional.of(new AggregateCrudUpdateOptions().withSnapshot(new SerializedSnapshot("X", "Y")))); LoadedEvents findResult = eventStore.find(aggregateType, eidv.getEntityId(), Optional.of(new AggregateCrudFindOptions())); assertTrue(findResult.getSnapshot().isPresent()); assertTrue(findResult.getEvents().isEmpty()); }