use of uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent in project microservice_framework by CJSCommonPlatform.
the class EventBufferIT method shouldIgnoreEventWithSupersededVersion.
@Test
public void shouldIgnoreEventWithSupersededVersion() throws SQLException, NamingException {
final UUID metadataId = randomUUID();
final UUID streamId = randomUUID();
final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(1L)).build();
final StreamBufferEvent streamBufferEvent2 = new StreamBufferEvent(streamId, 4L, "payload", SOURCE);
final StreamBufferEvent streamBufferEvent3 = new StreamBufferEvent(streamId, 5L, "payload", SOURCE);
statusRepository.insert(new StreamStatus(streamId, 2L, SOURCE));
jdbcStreamBufferRepository.insert(streamBufferEvent2);
jdbcStreamBufferRepository.insert(streamBufferEvent3);
interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
assertThat(streamBufferEvents, hasSize(2));
assertThat(streamStatus.isPresent(), is(true));
assertThat(streamStatus.get().getVersion(), is(2L));
assertThat(abcEventHandler.recordedEnvelopes(), empty());
}
use of uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent in project microservice_framework by CJSCommonPlatform.
the class EventBufferIT method shouldIncrementVersionWhenEventInOrder.
@Test
public void shouldIncrementVersionWhenEventInOrder() throws SQLException, NamingException {
final UUID metadataId = randomUUID();
final UUID streamId = randomUUID();
statusRepository.insert(new StreamStatus(streamId, 1L, SOURCE));
final JsonEnvelope envelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(2L)).build();
interceptorChainProcessor.process(interceptorContextWithInput(envelope));
final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
assertThat(streamBufferEvents, empty());
assertThat(streamStatus.isPresent(), is(true));
assertThat(streamStatus.get().getVersion(), is(2L));
}
use of uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent in project microservice_framework by CJSCommonPlatform.
the class EventBufferIT method shouldAddStatusVersionForNewStreamIdAndProcessIncomingEvent.
@Test
public void shouldAddStatusVersionForNewStreamIdAndProcessIncomingEvent() {
final UUID metadataId = randomUUID();
final UUID streamId = randomUUID();
final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(1L)).build();
interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
assertThat(streamBufferEvents, empty());
assertThat(streamStatus.isPresent(), is(true));
assertThat(streamStatus.get().getVersion(), is(1L));
final List<JsonEnvelope> handledEnvelopes = abcEventHandler.recordedEnvelopes();
assertThat(handledEnvelopes, hasSize(1));
assertThat(handledEnvelopes.get(0).metadata().id(), is(metadataId));
assertThat(handledEnvelopes.get(0).metadata().version(), contains(1L));
}
use of uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent in project microservice_framework by CJSCommonPlatform.
the class EventBufferIT method shouldNotIncrementVersionWhenEventNotInOrder.
@Test
public void shouldNotIncrementVersionWhenEventNotInOrder() throws SQLException, NamingException {
final UUID metadataId = randomUUID();
final UUID streamId = randomUUID();
statusRepository.insert(new StreamStatus(streamId, 2L, SOURCE));
final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId, EVENT_ABC).withStreamId(streamId).withVersion(4L)).build();
interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
assertThat(streamBufferEvents, hasSize(1));
assertThat(streamBufferEvents.get(0).getStreamId(), is(streamId));
assertThat(streamBufferEvents.get(0).getVersion(), is(4L));
assertThat(streamStatus.isPresent(), is(true));
assertThat(streamStatus.get().getVersion(), is(2L));
}
use of uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent in project microservice_framework by CJSCommonPlatform.
the class ConsecutiveEventBufferServiceTest method shouldStoreEventIncomingNotInOrderAndReturnEmpty.
@Test
public void shouldStoreEventIncomingNotInOrderAndReturnEmpty() {
final String eventName = "source.events.something.happened";
final String source = "source";
final UUID streamId = randomUUID();
final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(eventName).withStreamId(streamId).withVersion(6L)).build();
when(bufferInitialisationStrategy.initialiseBuffer(streamId, source)).thenReturn(4L);
when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(Optional.of(new StreamStatus(streamId, 4L, source)));
when(jsonObjectEnvelopeConverter.asJsonString(incomingEvent)).thenReturn("someStringRepresentation");
final Stream<JsonEnvelope> returnedEvents = bufferService.currentOrderedEventsWith(incomingEvent);
verify(streamBufferRepository).insert(new StreamBufferEvent(streamId, 6L, "someStringRepresentation", source));
assertThat(returnedEvents, empty());
}
Aggregations