public static CommandResponse of(final CommandResult<?> result) { return new CommandResponse( result.getAggregateId(), result.getPreviousVersion(), result.getNewVersion(), result.getEvents() == null || result.getEvents().isEmpty()); }
org.hamcrest.Matchers.contains(newEvents.toArray())); Assert.assertEquals((long) newVersion, (long) commandResult.getNewVersion()); Assert.assertThat( (List<TestEvent>) commandResult.getEvents(), org.hamcrest.Matchers.contains(newEvents.toArray()));
@Test @SuppressWarnings("unchecked") public void idempotentCreateWorksIfConflictOnSave() { Operation operation = new OperationHandlerOperation( (x, y) -> ImmutableList.of("hello"), false, false, ExpectedVersion.notCreated()); when(repository.load(any())) .thenReturn(DefaultImmutableAggregate.fromExisting( mock(AggregateProjection.class), AGGREGATE_ID, 42, new TestState("test"))); DefaultCommand command = new DefaultCommand(repository, operation); command.setAggregateId(AGGREGATE_ID); command.setIdempotentCreate(true); command.setAtomic(false); when(repository.append(any(), any(), any(), any())) .thenThrow(new UnexpectedVersionException(42, ExpectedVersion.notCreated())); CommandResult commandResult = command.run(); Assert.assertTrue(commandResult.getEvents().isEmpty()); }
&& aggregate.sourceVersion() != Aggregate.VERSION_NOT_CREATED) { logger.debug("Bailing out early as already created (and idempotent create set)"); return new CommandResult<>( aggregateId, aggregate.sourceVersion(), return new CommandResult<>( aggregateId, aggregate != null ? aggregate.sourceVersion() : null, return new CommandResult<>(aggregateId, oldVersion, newVersion, events); } catch (UnexpectedVersionException ex) { return new CommandResult<>( aggregateId, ex.getCurrentVersion() != null ? ex.getCurrentVersion() : null,
org.hamcrest.Matchers.contains(newEvents.toArray())); Assert.assertEquals((long) newVersion, (long) commandResult.getNewVersion()); Assert.assertThat( (List<TestEvent>) commandResult.getEvents(), org.hamcrest.Matchers.contains(newEvents.toArray()));
@Test @SuppressWarnings("unchecked") public void idempotentCreateMeansNoOpIfExisting() { Operation operation = new OperationHandlerOperation( (x, y) -> ImmutableList.of(new TestEvent("xxx")), false, false, ExpectedVersion.notCreated()); when(repository.load(any())) .thenReturn(DefaultImmutableAggregate.fromExisting( mock(AggregateProjection.class), AGGREGATE_ID, 42, new TestState("test"))); DefaultCommand command = new DefaultCommand(repository, operation); command.setAggregateId(AGGREGATE_ID); command.setIdempotentCreate(true); CommandResult commandResult = command.run(); Assert.assertTrue(commandResult.getEvents().isEmpty()); }
&& aggregate.sourceVersion() != Aggregate.VERSION_NOT_CREATED) { logger.debug("Bailing out early as already created (and idempotent create set)"); return new CommandResult<>( aggregateId, aggregate.sourceVersion(), return new CommandResult<>( aggregateId, aggregate != null ? aggregate.sourceVersion() : null, return new CommandResult<>(aggregateId, oldVersion, newVersion, events); } catch (UnexpectedVersionException ex) { return new CommandResult<>( aggregateId, ex.getCurrentVersion() != null ? ex.getCurrentVersion() : null,
public static CommandResponse of(final CommandResult<?> result) { return new CommandResponse( result.getAggregateId(), result.getPreviousVersion(), result.getNewVersion(), result.getEvents() == null || result.getEvents().isEmpty()); }