public AggregateCrudUpdateOptions withTriggeringEvent(EventContext eventContext) { return new AggregateCrudUpdateOptions(Optional.of(eventContext), this.snapshot); }
private CompletableFuture<EntityIdVersionAndEventIds> updateWithEventContext() { return client.update(new EntityIdAndType(RequestResponseJsonObjects.ENTITY_ID, RequestResponseJsonObjects.aggregateType), new Int128(5, 6), Collections.singletonList(new EventTypeAndData(RequestResponseJsonObjects.debitedEvent, RequestResponseJsonObjects.eventData, Optional.empty())), Optional.of(new AggregateCrudUpdateOptions().withTriggeringEvent(RequestResponseJsonObjects.makeEventContext()))); }
@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()); }
public AggregateCrudUpdateOptions withSnapshot(SerializedSnapshot serializedSnapshot) { return new AggregateCrudUpdateOptions(this.triggeringEvent, Optional.of(serializedSnapshot)); }
public AggregateCrudUpdateOptions withSnapshot(SerializedSnapshot serializedSnapshot) { return new AggregateCrudUpdateOptions(this.triggeringEvent, Optional.of(serializedSnapshot)); }
public AggregateCrudUpdateOptions withTriggeringEvent(EventContext eventContext) { return new AggregateCrudUpdateOptions(Optional.of(eventContext), this.snapshot); }
public static Optional<AggregateCrudUpdateOptions> toAggregateCrudUpdateOptions(Optional<UpdateOptions> updateOptions) { return updateOptions.map(uo -> new AggregateCrudUpdateOptions(uo.getTriggeringEvent(), uo.getSnapshot().map(AggregateCrudMapping::toSerializedSnapshot))); }
public static Optional<AggregateCrudUpdateOptions> toAggregateCrudUpdateOptions(Optional<UpdateOptions> updateOptions) { return updateOptions.map(uo -> new AggregateCrudUpdateOptions(uo.getTriggeringEvent(), uo.getSnapshot().map(AggregateCrudMapping::toSerializedSnapshot))); }
@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 testUpdate() { EventTypeAndData eventTypeAndData = new EventTypeAndData(testEventType, testEventData, Optional.empty()); SaveUpdateResult saveUpdateResult = eventuateJdbcAccess.save(testAggregate, Collections.singletonList(eventTypeAndData), Optional.empty()); EntityIdAndType entityIdAndType = new EntityIdAndType(saveUpdateResult.getEntityIdVersionAndEventIds().getEntityId(), testAggregate); eventTypeAndData = new EventTypeAndData("testEventType2", "testEventData2", Optional.empty()); eventuateJdbcAccess.update(entityIdAndType, saveUpdateResult.getEntityIdVersionAndEventIds().getEntityVersion(), Collections.singletonList(eventTypeAndData), Optional.of(new AggregateCrudUpdateOptions(Optional.empty(), Optional.of(new SerializedSnapshot("", ""))))); List<Map<String, Object>> events = jdbcTemplate.queryForList(readAllEventsSql()); Assert.assertEquals(2, events.size()); List<Map<String, Object>> entities = jdbcTemplate.queryForList(readAllEntitiesSql()); Assert.assertEquals(1, entities.size()); List<Map<String, Object>> snapshots = jdbcTemplate.queryForList(readAllSnapshots()); Assert.assertEquals(1, snapshots.size()); LoadedEvents loadedEvents = eventuateJdbcAccess.find(testAggregate, saveUpdateResult.getEntityIdVersionAndEventIds().getEntityId(), Optional.empty()); Assert.assertTrue(loadedEvents.getSnapshot().isPresent()); }