Search in sources :

Example 6 with AggregateSnapshot

use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.

the class DefaultSnapshotServiceTest method shouldCreateSnapshotIfStrategyMandatesCreation.

@Test
public void shouldCreateSnapshotIfStrategyMandatesCreation() throws AggregateChangeDetectedException {
    final TestAggregate aggregate = new TestAggregate();
    final Optional<AggregateSnapshot<TestAggregate>> aggregateSnapshot = Optional.empty();
    final Long currentSnapshotVersion = 0l;
    final Long currentAggregateVersionId = 26l;
    when(snapshotRepository.getLatestSnapshot(STREAM_ID, TestAggregate.class)).thenReturn(aggregateSnapshot);
    when(snapshotRepository.getLatestSnapshotVersion(STREAM_ID, TestAggregate.class)).thenReturn(currentSnapshotVersion);
    when(snapshotStrategy.shouldCreateSnapshot(currentAggregateVersionId, currentSnapshotVersion)).thenReturn(true);
    snapshotService.attemptAggregateStore(STREAM_ID, currentAggregateVersionId, aggregate);
    verify(snapshotRepository, times(1)).storeSnapshot(snapshotArgumentCaptor.capture());
    assertThat(snapshotArgumentCaptor.getValue(), notNullValue());
    assertThat(snapshotArgumentCaptor.getValue().getVersionId(), is(currentAggregateVersionId));
}
Also used : TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) NoSerializableTestAggregate(uk.gov.justice.domain.aggregate.NoSerializableTestAggregate) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 7 with AggregateSnapshot

use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.

the class SnapshotRepositoryJdbcIT method shouldRemoveAllSnapshots.

@Test
public void shouldRemoveAllSnapshots() {
    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, TYPE, AGGREGATE);
    final AggregateSnapshot aggregateSnapshot4 = createSnapshot(streamId, VERSION_ID + 4, TYPE, AGGREGATE);
    final AggregateSnapshot aggregateSnapshot5 = createSnapshot(streamId, VERSION_ID + 6, TYPE, AGGREGATE);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot2);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot3);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot4);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot5);
    snapshotJdbcRepository.removeAllSnapshots(streamId, TYPE);
    final Optional<AggregateSnapshot<RecordingAggregate>> snapshots = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
    assertThat(snapshots, notNullValue());
    assertThat(snapshots.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 8 with AggregateSnapshot

use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.

the class SnapshotRepositoryJdbcIT method shouldRetrieveLatestSnapshot.

@Test
public void shouldRetrieveLatestSnapshot() {
    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, TYPE, AGGREGATE);
    final AggregateSnapshot aggregateSnapshot4 = createSnapshot(streamId, VERSION_ID + 4, TYPE, AGGREGATE);
    final AggregateSnapshot aggregateSnapshot5 = createSnapshot(streamId, VERSION_ID + 5, TYPE, AGGREGATE);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot2);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot3);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot4);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot5);
    final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
    assertThat(snapshot, notNullValue());
    assertThat(snapshot, is(Optional.of(aggregateSnapshot5)));
}
Also used : UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 9 with AggregateSnapshot

use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.

the class SnapshotRepositoryJdbcIT method shouldStoreAndRetrieveSnapshot.

@Test
public void shouldStoreAndRetrieveSnapshot() {
    final UUID streamId = randomUUID();
    final AggregateSnapshot aggregateSnapshot = createSnapshot(streamId, VERSION_ID, TYPE, AGGREGATE);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot);
    final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
    assertThat(snapshot, notNullValue());
    assertThat(snapshot, is(Optional.of(aggregateSnapshot)));
}
Also used : UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) AggregateSnapshot(uk.gov.justice.domain.snapshot.AggregateSnapshot) Test(org.junit.Test)

Example 10 with AggregateSnapshot

use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.

the class SnapshotRepositoryJdbcIT method shouldRetrieveOptionalNullIfOnlySnapshotsOfDifferentTypesAvailable.

@Test
public void shouldRetrieveOptionalNullIfOnlySnapshotsOfDifferentTypesAvailable() {
    final UUID streamId = randomUUID();
    final AggregateSnapshot aggregateSnapshot1 = createSnapshot(streamId, VERSION_ID, OTHER_TYPE, AGGREGATE);
    snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
    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)

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