use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method tweakRecipeSnapshotName.
private void tweakRecipeSnapshotName(final String recipeId, final String newRecipeName) throws AggregateChangeDetectedException {
final AggregateSnapshot<Recipe> recipeAggregateSnapshot = recipeAggregateSnapshotOf(recipeId).get();
final Recipe recipe = recipeAggregateSnapshot.getAggregate(new DefaultObjectInputStreamStrategy());
setField(recipe, "name", newRecipeName);
SNAPSHOT_REPOSITORY.removeAllSnapshots(recipeAggregateSnapshot.getStreamId(), Recipe.class);
SNAPSHOT_REPOSITORY.storeSnapshot(new AggregateSnapshot(recipeAggregateSnapshot.getStreamId(), recipeAggregateSnapshot.getVersionId(), recipe));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldReturnOptionalNullIfNoSnapshotAvailable.
@Test
public void shouldReturnOptionalNullIfNoSnapshotAvailable() {
final UUID streamId = randomUUID();
final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshot.isPresent(), is(false));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldRetrieveLatestSnapshotWithCorrectType.
@Test
public void shouldRetrieveLatestSnapshotWithCorrectType() {
final UUID streamId = randomUUID();
final AggregateSnapshot aggregateSnapshot1 = createSnapshot(streamId, VERSION_ID + 1, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot2 = createSnapshot(streamId, VERSION_ID + 2, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot3 = createSnapshot(streamId, VERSION_ID + 3, OTHER_TYPE, AGGREGATE);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot2);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot3);
final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshot, notNullValue());
assertThat(snapshot, is(Optional.of(aggregateSnapshot2)));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotAwareAggregateServiceIT method shouldNotStoreABrandNewSnapshotWhenStrategyDoesNotMandateSavingSnapshot.
@Test
public void shouldNotStoreABrandNewSnapshotWhenStrategyDoesNotMandateSavingSnapshot() throws Exception {
final UUID streamId = randomUUID();
final EventStream stream = eventSource.getStreamById(streamId);
final TestAggregate aggregate = aggregateService.get(stream, TestAggregate.class);
stream.append(createEventAndApply(streamId, 24, aggregate));
final Optional<AggregateSnapshot<TestAggregate>> snapshot = snapshotRepository.getLatestSnapshot(streamId, TestAggregate.class);
assertThat(snapshot, not(nullValue()));
assertThat(snapshot.isPresent(), equalTo(false));
assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, streamId), is(24));
assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, streamId), is(1));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotAwareAggregateServiceIT method shouldNotStoreANewSnapshotOnTopOfExistingSnapshotsWhenThresholdNotMet.
@Test
public void shouldNotStoreANewSnapshotOnTopOfExistingSnapshotsWhenThresholdNotMet() throws Exception {
final UUID streamId = randomUUID();
appendEventsViaAggregate(streamId, SNAPSHOT_THRESHOLD);
final EventStream stream = eventSource.getStreamById(streamId);
final TestAggregate aggregate = aggregateService.get(stream, TestAggregate.class);
stream.append(createEventAndApply(streamId, SNAPSHOT_THRESHOLD - 2, aggregate));
final Optional<AggregateSnapshot<TestAggregate>> snapshot = snapshotRepository.getLatestSnapshot(streamId, TestAggregate.class);
assertThat(snapshot, notNullValue());
assertThat(snapshot.isPresent(), equalTo(true));
assertThat(snapshot.get().getType(), equalTo(TYPE));
assertThat(snapshot.get().getStreamId(), equalTo(streamId));
assertThat(snapshot.get().getVersionId(), equalTo(25L));
assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, streamId), is(48));
TestAggregate aggregateFromSnapshot = snapshot.get().getAggregate(new DefaultObjectInputStreamStrategy());
assertThat(aggregateFromSnapshot.numberOfAppliedEvents(), is(25));
assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, streamId), is(1));
}
Aggregations