Search in sources :

Example 6 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class EventStreamServiceTest method shouldReturnPreviousEvents.

@Test
public void shouldReturnPreviousEvents() throws Exception {
    final long pageSize = 2L;
    final UUID streamId2 = randomUUID();
    final UUID streamId3 = randomUUID();
    final Stream.Builder<EventStream> eventStreamBuilder = Stream.builder();
    final EventStream eventStream2 = buildEventStreamOf(streamId2, 2L);
    final EventStream eventStream3 = buildEventStreamOf(streamId3, 3L);
    eventStreamBuilder.add(eventStream2);
    eventStreamBuilder.add(eventStream3);
    final long position = 3L;
    when(eventSource.getStreamsFrom(2L)).thenReturn(eventStreamBuilder.build());
    when(eventStreamManager.getStreamPosition(streamId3)).thenReturn(3L);
    when(eventStreamManager.getStreamPosition(streamId2)).thenReturn(2L);
    final List<EventStreamEntry> eventEntries = service.eventStreams(position(position), BACKWARD, pageSize);
    assertThat(eventEntries, hasSize(2));
    assertThat(eventEntries.get(0).getStreamId(), is(streamId3.toString()));
    assertThat(eventEntries.get(0).getSequenceNumber(), is(3L));
    assertThat(eventEntries.get(1).getStreamId(), is(streamId2.toString()));
    assertThat(eventEntries.get(1).getSequenceNumber(), is(2L));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Stream(java.util.stream.Stream) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 7 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class EventStreamServiceTest method shouldReturnRecordExists.

@Test
public void shouldReturnRecordExists() throws Exception {
    final UUID streamId1 = randomUUID();
    final UUID streamId2 = randomUUID();
    final UUID streamId3 = randomUUID();
    final UUID streamId4 = randomUUID();
    final Stream.Builder<EventStream> eventStreamBuilder = Stream.builder();
    final EventStream eventStream1 = buildEventStreamOf(streamId1, 1L);
    final EventStream eventStream2 = buildEventStreamOf(streamId2, 2L);
    final EventStream eventStream3 = buildEventStreamOf(streamId3, 3L);
    final EventStream eventStream4 = buildEventStreamOf(streamId4, 4L);
    eventStreamBuilder.add(eventStream1);
    eventStreamBuilder.add(eventStream2);
    eventStreamBuilder.add(eventStream3);
    eventStreamBuilder.add(eventStream4);
    when(eventSource.getStreamsFrom(1)).thenReturn(eventStreamBuilder.build());
// assertThat(service.eventStreamExists(1), is(true));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Stream(java.util.stream.Stream) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 8 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class EventStreamServiceTest method shouldReturnFirstEvents.

@Test
public void shouldReturnFirstEvents() throws Exception {
    final long pageSize = 2L;
    final Stream.Builder<EventStream> eventStreamBuilder = Stream.builder();
    final UUID streamId1 = randomUUID();
    final UUID streamId2 = randomUUID();
    final EventStream eventStream1 = buildEventStreamOf(streamId1, 1L);
    final EventStream eventStream2 = buildEventStreamOf(streamId2, 2L);
    eventStreamBuilder.add(eventStream1);
    eventStreamBuilder.add(eventStream2);
    final Stream.Builder<EventStream> eventStreamBuilderFrom1 = Stream.builder();
    eventStreamBuilderFrom1.add(eventStream1);
    eventStreamBuilderFrom1.add(eventStream2);
    when(eventSource.getStreamsFrom(1)).thenReturn(eventStreamBuilder.build());
    when(eventStreamManager.getStreamPosition(streamId1)).thenReturn(1L);
    when(eventStreamManager.getStreamPosition(streamId2)).thenReturn(2L);
    final List<EventStreamEntry> eventStreamEntries = service.eventStreams(first(), FORWARD, pageSize);
    assertThat(eventStreamEntries, hasSize(2));
    assertThat(eventStreamEntries.get(0).getStreamId(), is(streamId2.toString()));
    assertThat(eventStreamEntries.get(0).getSequenceNumber(), is(2L));
    assertThat(eventStreamEntries.get(1).getStreamId(), is(streamId1.toString()));
    assertThat(eventStreamEntries.get(1).getSequenceNumber(), is(1L));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Stream(java.util.stream.Stream) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 9 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class EventStreamServiceTest method shouldReturnHeadEvents.

@Test
public void shouldReturnHeadEvents() throws Exception {
    final long pageSize = 2L;
    final UUID streamId1 = randomUUID();
    final UUID streamId2 = randomUUID();
    final UUID streamId3 = randomUUID();
    final UUID streamId4 = randomUUID();
    final EventStream eventStream1 = buildEventStreamOf(streamId1, 1L);
    final EventStream eventStream2 = buildEventStreamOf(streamId2, 2L);
    final EventStream eventStream3 = buildEventStreamOf(streamId3, 3L);
    final EventStream eventStream4 = buildEventStreamOf(streamId4, 4L);
    final Stream.Builder<EventStream> eventStreamBuilder = Stream.builder();
    eventStreamBuilder.add(eventStream1);
    eventStreamBuilder.add(eventStream2);
    eventStreamBuilder.add(eventStream3);
    eventStreamBuilder.add(eventStream4);
    final Stream.Builder<EventStream> eventStreamBuilderFrom3 = Stream.builder();
    eventStreamBuilderFrom3.add(eventStream3);
    eventStreamBuilderFrom3.add(eventStream4);
    when(eventSource.getStreamsFrom(1)).thenReturn(eventStreamBuilder.build());
    when(eventSource.getStreamsFrom(3)).thenReturn(eventStreamBuilderFrom3.build());
    when(eventStreamManager.getStreamPosition(streamId3)).thenReturn(3L);
    when(eventStreamManager.getStreamPosition(streamId4)).thenReturn(4L);
    final List<EventStreamEntry> entries = service.eventStreams(head(), BACKWARD, pageSize);
    assertThat(entries, hasSize(2));
    assertThat(entries.get(0).getStreamId(), is(streamId4.toString()));
    assertThat(entries.get(0).getSequenceNumber(), is(4L));
    assertThat(entries.get(1).getStreamId(), is(streamId3.toString()));
    assertThat(entries.get(1).getSequenceNumber(), is(3L));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Stream(java.util.stream.Stream) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 10 with EventStream

use of uk.gov.justice.services.eventsourcing.source.core.EventStream in project microservice_framework by CJSCommonPlatform.

the class EventStreamServiceTest method shouldReturnNextEvents.

@Test
public void shouldReturnNextEvents() throws Exception {
    final long pageSize = 2L;
    final UUID streamId5 = randomUUID();
    final UUID streamId4 = randomUUID();
    final Stream.Builder<EventStream> eventStreamBuilder = Stream.builder();
    final EventStream eventStream5 = buildEventStreamOf(streamId5, 5L);
    final EventStream eventStream4 = buildEventStreamOf(streamId4, 4L);
    eventStreamBuilder.add(eventStream4);
    eventStreamBuilder.add(eventStream5);
    final long position = 3L;
    when(eventSource.getStreamsFrom(position)).thenReturn(eventStreamBuilder.build());
    when(eventStreamManager.getStreamPosition(streamId5)).thenReturn(5L);
    when(eventStreamManager.getStreamPosition(streamId4)).thenReturn(4L);
    final List<EventStreamEntry> eventEntries = service.eventStreams(position(position), FORWARD, pageSize);
    assertThat(eventEntries, hasSize(2));
    assertThat(eventEntries.get(0).getStreamId(), is(streamId5.toString()));
    assertThat(eventEntries.get(0).getSequenceNumber(), is(5L));
    assertThat(eventEntries.get(1).getStreamId(), is(streamId4.toString()));
    assertThat(eventEntries.get(1).getSequenceNumber(), is(4L));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) Stream(java.util.stream.Stream) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)28 Test (org.junit.Test)19 UUID (java.util.UUID)18 UUID.randomUUID (java.util.UUID.randomUUID)13 EnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream)10 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)9 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)7 ZonedDateTime (java.time.ZonedDateTime)5 Stream (java.util.stream.Stream)5 Handles (uk.gov.justice.services.core.annotation.Handles)5 SnapshotAwareEnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.SnapshotAwareEnvelopeEventStream)5 Recipe (uk.gov.justice.services.example.cakeshop.domain.aggregate.Recipe)5 JsonObjects.getUUID (uk.gov.justice.services.messaging.JsonObjects.getUUID)5 JsonObject (javax.json.JsonObject)4 AggregateSnapshot (uk.gov.justice.domain.snapshot.AggregateSnapshot)3 EventA (uk.gov.justice.services.core.aggregate.event.EventA)3 EventFoundEvent (uk.gov.justice.services.core.extension.EventFoundEvent)3 MetadataBuilderFactory.metadataWithRandomUUID (uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID)3 DefaultObjectInputStreamStrategy (uk.gov.justice.domain.snapshot.DefaultObjectInputStreamStrategy)2 JsonObjects.getString (uk.gov.justice.services.messaging.JsonObjects.getString)2