Search in sources :

Example 6 with DefaultObjectInputStreamStrategy

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

the class SnapshotAwareAggregateServiceIT method shouldStoreANewSnapshotOnTopOfExistingSnapshot.

@Test
public void shouldStoreANewSnapshotOnTopOfExistingSnapshot() throws Exception {
    final UUID streamId = randomUUID();
    appendEventsViaAggregate(streamId, SNAPSHOT_THRESHOLD);
    appendEventsViaAggregate(streamId, SNAPSHOT_THRESHOLD);
    final Optional<AggregateSnapshot<TestAggregate>> snapshot = snapshotRepository.getLatestSnapshot(streamId, TestAggregate.class);
    assertThat(snapshot, not(nullValue()));
    assertThat(snapshot.isPresent(), equalTo(true));
    assertThat(snapshot.get().getType(), equalTo(TYPE));
    assertThat(snapshot.get().getStreamId(), equalTo(streamId));
    assertThat(snapshot.get().getVersionId(), equalTo(50L));
    assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, streamId), is(50));
    TestAggregate aggregateFromSnapshot = snapshot.get().getAggregate(new DefaultObjectInputStreamStrategy());
    assertThat(aggregateFromSnapshot.numberOfAppliedEvents(), is(50));
    assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, streamId), is(1));
}
Also used : 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)6 DefaultObjectInputStreamStrategy (uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy)6 UUID (java.util.UUID)5 UUID.randomUUID (java.util.UUID.randomUUID)5 Test (org.junit.Test)5 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)5 MetadataBuilderFactory.metadataWithRandomUUID (uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID)5 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)2 SnapshotAwareEnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream)2 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)1