use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.
the class AnsiSQLBasedBufferInitialisationStrategyTest method shouldReturnCurrentVersionIfItExists.
@Test
public void shouldReturnCurrentVersionIfItExists() throws Exception {
final UUID streamId = randomUUID();
final String source = "a source";
final long currentVersion = 3L;
when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(of(new StreamStatus(streamId, currentVersion, source)));
bufferInitialisationStrategy.initialiseBuffer(streamId, source);
assertThat(bufferInitialisationStrategy.initialiseBuffer(streamId, source), is(currentVersion));
}
use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.
the class AnsiSQLBasedBufferInitialisationStrategyTest method shouldAddZeroStatusIfItDoesNotExist.
@Test
public void shouldAddZeroStatusIfItDoesNotExist() throws Exception {
final UUID streamId = randomUUID();
final String source = "a source";
when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(Optional.empty());
bufferInitialisationStrategy.initialiseBuffer(streamId, source);
verify(streamStatusRepository).insert(new StreamStatus(streamId, 0L, source));
}
use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.
the class ConsecutiveEventBufferServiceTest method shouldIncrementVersionOnIncomingEventInCorrectOrder.
@Test
public void shouldIncrementVersionOnIncomingEventInCorrectOrder() {
final UUID streamId = randomUUID();
final String source = "source";
final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(source).withStreamId(streamId).withVersion(5L)).build();
when(bufferInitialisationStrategy.initialiseBuffer(streamId, source)).thenReturn(4L);
when(streamBufferRepository.findStreamByIdAndSource(streamId, source)).thenReturn(Stream.empty());
bufferService.currentOrderedEventsWith(incomingEvent);
verify(streamStatusRepository).update(new StreamStatus(streamId, 5L, source));
}
use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.
the class BufferInitialisationStrategyProducerTest method shouldPassRepositoryToPostgresStrategy.
@Test
public void shouldPassRepositoryToPostgresStrategy() throws Exception {
strategyProducer.strategyClass = "uk.gov.justice.services.event.buffer.core.service.PostgreSQLBasedBufferInitialisationStrategy";
final BufferInitialisationStrategy bufferInitialisationStrategy = strategyProducer.bufferInitialisationStrategy();
final UUID streamId = randomUUID();
final String source = "a source";
when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(Optional.of(new StreamStatus(streamId, 0L, source)));
bufferInitialisationStrategy.initialiseBuffer(streamId, source);
verify(streamStatusRepository).findByStreamIdAndSource(streamId, source);
}
use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.
the class BufferInitialisationStrategyProducerTest method shouldPassRepositoryToAnsiStrategy.
@Test
public void shouldPassRepositoryToAnsiStrategy() throws Exception {
strategyProducer.strategyClass = "uk.gov.justice.services.event.buffer.core.service.AnsiSQLBasedBufferInitialisationStrategy";
final BufferInitialisationStrategy bufferInitialisationStrategy = strategyProducer.bufferInitialisationStrategy();
final UUID streamId = randomUUID();
final String source = "a source";
when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(Optional.of(new StreamStatus(streamId, 0L, source)));
bufferInitialisationStrategy.initialiseBuffer(streamId, source);
verify(streamStatusRepository).findByStreamIdAndSource(streamId, source);
}
Aggregations