Search in sources :

Example 1 with EventTypeCache

use of org.zalando.nakadi.repository.db.EventTypeCache in project nakadi by zalando.

the class EventStreamTest method setupMocks.

@BeforeClass
public static void setupMocks() {
    final TimelineService timelineService = mock(TimelineService.class);
    final EventTypeCache eventTypeCache = mock(EventTypeCache.class);
    cursorConverter = new CursorConverterImpl(eventTypeCache, timelineService);
    writerProvider = mock(EventStreamWriterProvider.class);
}
Also used : TimelineService(org.zalando.nakadi.service.timeline.TimelineService) CursorConverterImpl(org.zalando.nakadi.service.converter.CursorConverterImpl) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) BeforeClass(org.junit.BeforeClass)

Example 2 with EventTypeCache

use of org.zalando.nakadi.repository.db.EventTypeCache in project nakadi by zalando.

the class EventTypeChangeListenerTest method setUp.

@Before
public void setUp() {
    final EventTypeCache cache = mock(EventTypeCache.class);
    final ArgumentCaptor<Consumer> changeCall = ArgumentCaptor.forClass(Consumer.class);
    listener = new EventTypeChangeListener(cache);
    verify(cache, times(1)).addInvalidationListener(changeCall.capture());
    notificationTrigger = changeCall.getValue();
}
Also used : Consumer(java.util.function.Consumer) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) Before(org.junit.Before)

Example 3 with EventTypeCache

use of org.zalando.nakadi.repository.db.EventTypeCache in project nakadi by zalando.

the class CursorConverterImplTest method testBeginConvertedVersionZero.

@Test
public void testBeginConvertedVersionZero() throws Exception {
    final String eventType = "test-et";
    final String partition = "2";
    final Storage storage = new Storage("", Storage.Type.KAFKA);
    final Timeline timeline = mock(Timeline.class);
    when(timeline.getStorage()).thenReturn(storage);
    final EventTypeCache eventTypeCache = mock(EventTypeCache.class);
    final TopicRepository topicRepository = mock(TopicRepository.class);
    final TimelineService timelineService = mock(TimelineService.class);
    final PartitionStatistics stats = mock(PartitionStatistics.class);
    when(timelineService.getActiveTimelinesOrdered(eq(eventType))).thenReturn(Collections.singletonList(timeline));
    when(timelineService.getTopicRepository(eq(timeline))).thenReturn(topicRepository);
    when(topicRepository.loadPartitionStatistics(eq(timeline), eq(partition))).thenReturn(Optional.of(stats));
    final NakadiCursor beforeFirstCursor = NakadiCursor.of(timeline, partition, "000001");
    when(stats.getBeforeFirst()).thenReturn(beforeFirstCursor);
    final CursorConverter converter = new CursorConverterImpl(eventTypeCache, timelineService);
    final NakadiCursor nakadiCursor = converter.convert(eventType, new Cursor(partition, "BEGIN"));
    Assert.assertEquals(timeline, nakadiCursor.getTimeline());
    Assert.assertEquals(partition, nakadiCursor.getPartition());
    Assert.assertEquals("000001", nakadiCursor.getOffset());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Cursor(org.zalando.nakadi.view.Cursor) CursorConverter(org.zalando.nakadi.service.CursorConverter) Test(org.junit.Test)

Example 4 with EventTypeCache

use of org.zalando.nakadi.repository.db.EventTypeCache in project nakadi by zalando.

the class RepositoriesConfig method eventTypeCache.

@Bean
public EventTypeCache eventTypeCache(final ZooKeeperHolder zooKeeperHolder, @DB final EventTypeRepository eventTypeRepository, @DB final TimelineDbRepository timelineRepository, final TimelineSync timelineSync) {
    ValidationStrategy.register(EventBodyMustRespectSchema.NAME, new EventBodyMustRespectSchema(new JsonSchemaEnrichment()));
    ValidationStrategy.register(EventMetadataValidationStrategy.NAME, new EventMetadataValidationStrategy());
    try {
        return new EventTypeCache(eventTypeRepository, timelineRepository, zooKeeperHolder, timelineSync);
    } catch (final Exception e) {
        throw new IllegalStateException("failed to create event type cache", e);
    }
}
Also used : JsonSchemaEnrichment(org.zalando.nakadi.validation.JsonSchemaEnrichment) EventBodyMustRespectSchema(org.zalando.nakadi.validation.EventBodyMustRespectSchema) EventMetadataValidationStrategy(org.zalando.nakadi.validation.EventMetadataValidationStrategy) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) Bean(org.springframework.context.annotation.Bean)

Example 5 with EventTypeCache

use of org.zalando.nakadi.repository.db.EventTypeCache in project nakadi by zalando.

the class PartitionsControllerTest method before.

@Before
public void before() throws InternalNakadiException, NoSuchEventTypeException {
    eventTypeRepositoryMock = mock(EventTypeRepository.class);
    topicRepositoryMock = mock(TopicRepository.class);
    eventTypeCache = mock(EventTypeCache.class);
    timelineService = Mockito.mock(TimelineService.class);
    cursorOperationsService = Mockito.mock(CursorOperationsService.class);
    when(timelineService.getActiveTimelinesOrdered(eq(UNKNOWN_EVENT_TYPE))).thenThrow(NoSuchEventTypeException.class);
    when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenReturn(Collections.singletonList(TIMELINE));
    when(timelineService.getAllTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenReturn(Collections.singletonList(TIMELINE));
    when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepositoryMock);
    final CursorConverter cursorConverter = new CursorConverterImpl(eventTypeCache, timelineService);
    final PartitionsController controller = new PartitionsController(timelineService, cursorConverter, cursorOperationsService, eventTypeRepositoryMock, authorizationValidator);
    settings = mock(SecuritySettings.class);
    final FeatureToggleService featureToggleService = Mockito.mock(FeatureToggleService.class);
    mockMvc = standaloneSetup(controller).setMessageConverters(new StringHttpMessageConverter(), TestUtils.JACKSON_2_HTTP_MESSAGE_CONVERTER).setCustomArgumentResolvers(new ClientResolver(settings, featureToggleService)).setControllerAdvice(new ExceptionHandling()).build();
}
Also used : CursorConverterImpl(org.zalando.nakadi.service.converter.CursorConverterImpl) SecuritySettings(org.zalando.nakadi.config.SecuritySettings) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) CursorConverter(org.zalando.nakadi.service.CursorConverter) ClientResolver(org.zalando.nakadi.security.ClientResolver) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) CursorOperationsService(org.zalando.nakadi.service.CursorOperationsService) FeatureToggleService(org.zalando.nakadi.service.FeatureToggleService) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Before(org.junit.Before)

Aggregations

EventTypeCache (org.zalando.nakadi.repository.db.EventTypeCache)7 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)4 Before (org.junit.Before)3 TopicRepository (org.zalando.nakadi.repository.TopicRepository)3 CursorConverterImpl (org.zalando.nakadi.service.converter.CursorConverterImpl)3 BeforeClass (org.junit.BeforeClass)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 SecuritySettings (org.zalando.nakadi.config.SecuritySettings)2 Timeline (org.zalando.nakadi.domain.Timeline)2 EventTypeRepository (org.zalando.nakadi.repository.EventTypeRepository)2 ClientResolver (org.zalando.nakadi.security.ClientResolver)2 CursorConverter (org.zalando.nakadi.service.CursorConverter)2 FeatureToggleService (org.zalando.nakadi.service.FeatureToggleService)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Closeable (java.io.Closeable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1