Search in sources :

Example 6 with StreamStatus

use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.

the class PostgreSQLBasedBufferInitialisationStrategyTest method shouldReturnCurrentVersion.

@Test
public void shouldReturnCurrentVersion() {
    final UUID streamId = randomUUID();
    final String source = "a source";
    when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(of(new StreamStatus(streamId, 3, source)));
    final long currentVersion = bufferInitialisationStrategy.initialiseBuffer(streamId, source);
    assertThat(currentVersion, is(3L));
}
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 7 with StreamStatus

use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.

the class PostgreSQLBasedBufferInitialisationStrategyTest method shouldTryInsertingZeroBufferStatus.

@Test
public void shouldTryInsertingZeroBufferStatus() throws Exception {
    final UUID streamId = randomUUID();
    final String source = "a source";
    when(streamStatusRepository.findByStreamIdAndSource(streamId, source)).thenReturn(of(new StreamStatus(streamId, 3, source)));
    bufferInitialisationStrategy.initialiseBuffer(streamId, source);
    verify(streamStatusRepository).insertOrDoNothing(new StreamStatus(streamId, 0, 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 8 with StreamStatus

use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus in project microservice_framework by CJSCommonPlatform.

the class EventBufferIT method shouldReleaseBufferWhenMissingEventArrives.

@Test
public void shouldReleaseBufferWhenMissingEventArrives() throws SQLException, NamingException {
    final UUID metadataId2 = randomUUID();
    final UUID streamId = randomUUID();
    final JsonEnvelope jsonEnvelope = envelope().with(metadataOf(metadataId2, EVENT_ABC).withStreamId(streamId).withVersion(2L)).build();
    statusRepository.insert(new StreamStatus(streamId, 1L, SOURCE));
    final UUID metadataId3 = randomUUID();
    final UUID metadataId4 = randomUUID();
    final UUID metadataId5 = randomUUID();
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 3L, envelope().with(metadataOf(metadataId3, EVENT_ABC).withStreamId(streamId).withVersion(3L)).toJsonString(), SOURCE));
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 4L, envelope().with(metadataOf(metadataId4, EVENT_ABC).withStreamId(streamId).withVersion(4L)).toJsonString(), SOURCE));
    jdbcStreamBufferRepository.insert(new StreamBufferEvent(streamId, 5L, envelope().with(metadataOf(metadataId5, EVENT_ABC).withStreamId(streamId).withVersion(5L)).toJsonString(), SOURCE));
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
    final List<StreamBufferEvent> streamBufferEvents = jdbcStreamBufferRepository.findStreamByIdAndSource(streamId, SOURCE).collect(toList());
    final Optional<StreamStatus> streamStatus = statusRepository.findByStreamIdAndSource(streamId, SOURCE);
    assertThat(streamStatus.isPresent(), is(true));
    assertThat(streamStatus.get().getVersion(), is(5L));
    final List<JsonEnvelope> handledEnvelopes = abcEventHandler.recordedEnvelopes();
    assertThat(handledEnvelopes, hasSize(4));
    assertThat(handledEnvelopes.get(0).metadata().id(), is(metadataId2));
    assertThat(handledEnvelopes.get(0).metadata().version(), contains(2L));
    assertThat(handledEnvelopes.get(1).metadata().id(), is(metadataId3));
    assertThat(handledEnvelopes.get(1).metadata().version(), contains(3L));
    assertThat(handledEnvelopes.get(2).metadata().id(), is(metadataId4));
    assertThat(handledEnvelopes.get(2).metadata().version(), contains(4L));
    assertThat(handledEnvelopes.get(3).metadata().id(), is(metadataId5));
    assertThat(handledEnvelopes.get(3).metadata().version(), contains(5L));
    assertThat(streamBufferEvents, hasSize(0));
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) 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 9 with StreamStatus

use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus 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());
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) 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 10 with StreamStatus

use of uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus 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));
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) 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)

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