Search in sources :

Example 11 with AggregateSnapshot

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));
}
Also used : Recipe(uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe) DefaultObjectInputStreamStrategy(uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot)

Example 12 with AggregateSnapshot

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));
}
Also used : UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 13 with AggregateSnapshot

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)));
}
Also used : UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 14 with AggregateSnapshot

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));
}
Also used : SnapshotAwareEnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) UUID(java.util.UUID) MetadataBuilderFactory.metadataWithRandomUUID(uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID) UUID.randomUUID(java.util.UUID.randomUUID) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 15 with AggregateSnapshot

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));
}
Also used : SnapshotAwareEnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) UUID(java.util.UUID) MetadataBuilderFactory.metadataWithRandomUUID(uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID) UUID.randomUUID(java.util.UUID.randomUUID) DefaultObjectInputStreamStrategy(uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Aggregations

AggregateSnapshot (uk.gov.justice.domain.snapshot.AggregateSnapshot)16 Test (org.junit.Test)15 UUID (java.util.UUID)14 UUID.randomUUID (java.util.UUID.randomUUID)14 MetadataBuilderFactory.metadataWithRandomUUID (uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID)8 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)7 DefaultObjectInputStreamStrategy (uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy)6 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)3 SnapshotAwareEnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream)3 NoSerializableTestAggregate (uk.gov.justice.domain.aggregate.NoSerializableTestAggregate)1 CustomClassLoaderObjectInputStreamStrategy (uk.gov.justice.domain.aggregate.classloader.CustomClassLoaderObjectInputStreamStrategy)1 DynamicAggregateTestClassGenerator (uk.gov.justice.domain.aggregate.classloader.DynamicAggregateTestClassGenerator)1 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)1