Search in sources :

Example 1 with StreamStatus

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));
}
Also used : StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 2 with StreamStatus

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));
}
Also used : StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with StreamStatus

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));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 4 with StreamStatus

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);
}
Also used : StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 5 with StreamStatus

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);
}
Also used : StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)15 StreamStatus (uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus)15 UUID.randomUUID (java.util.UUID.randomUUID)14 Test (org.junit.Test)14 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)7 StreamBufferEvent (uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent)6