use of org.zalando.nakadi.service.CursorConverter in project nakadi by zalando.
the class StreamingStateTest method prepareMocks.
@Before
public void prepareMocks() throws Exception {
state = new StreamingState();
final StreamingContext contextMock = mock(StreamingContext.class);
when(contextMock.getCursorComparator()).thenReturn(Comparator.comparing(NakadiCursor::getOffset));
when(contextMock.getSessionId()).thenReturn(SESSION_ID);
when(contextMock.isInState(Mockito.same(state))).thenReturn(true);
subscription = mock(Subscription.class);
when(contextMock.getSubscription()).thenReturn(subscription);
timelineService = mock(TimelineService.class);
when(contextMock.getTimelineService()).thenReturn(timelineService);
final MetricRegistry metricRegistry = mock(MetricRegistry.class);
when(metricRegistry.register(any(), any())).thenReturn(null);
when(contextMock.getMetricRegistry()).thenReturn(metricRegistry);
zkMock = mock(ZkSubscriptionClient.class);
when(contextMock.getZkClient()).thenReturn(zkMock);
cursorConverter = mock(CursorConverter.class);
when(contextMock.getCursorConverter()).thenReturn(cursorConverter);
final Client client = mock(Client.class);
when(client.getClientId()).thenReturn("consumingAppId");
final StreamParameters spMock = createStreamParameters(1000, 100L, 100, 100L, 100, 100, 100, client);
when(contextMock.getParameters()).thenReturn(spMock);
state.setContext(contextMock, "test");
}
use of org.zalando.nakadi.service.CursorConverter 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());
}
use of org.zalando.nakadi.service.CursorConverter in project nakadi by zalando.
the class CursorsServiceAT method before.
@Before
public void before() throws Exception {
sid = randomUUID();
streamId = randomUUID();
etName = randomValidEventTypeName();
topic = randomUUID();
cursorConverter = mock(CursorConverter.class);
testCursors = ImmutableList.of(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
final EventType eventType = mock(EventType.class);
when(eventType.getName()).thenReturn(etName);
final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
when(zkHolder.get()).thenReturn(CURATOR);
final TopicRepository topicRepository = mock(TopicRepository.class);
final TimelineService timelineService = mock(TimelineService.class);
when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
timeline = buildTimeline(etName, topic, CREATED_AT);
when(timelineService.getActiveTimeline(any(EventType.class))).thenReturn(timeline);
final Subscription subscription = mock(Subscription.class);
when(subscription.getId()).thenReturn(sid);
when(subscription.getEventTypes()).thenReturn(ImmutableSet.of(etName));
final SubscriptionDbRepository subscriptionRepo = mock(SubscriptionDbRepository.class);
when(subscriptionRepo.getSubscription(sid)).thenReturn(subscription);
final SubscriptionClientFactory zkSubscriptionFactory = new SubscriptionClientFactory(zkHolder, MAPPER);
uuidGenerator = mock(UUIDGenerator.class);
when(uuidGenerator.isUUID(any())).thenReturn(true);
cursorsService = new CursorsService(subscriptionRepo, null, mock(NakadiSettings.class), zkSubscriptionFactory, cursorConverter, uuidGenerator, null);
// Register cursors in converter
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, OLD_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, NEW_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, OLD_OFFSET));
// bootstrap data in ZK
CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P1), OLD_OFFSET.getBytes(UTF_8));
CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P2), OLD_OFFSET.getBytes(UTF_8));
CURATOR.create().creatingParentsIfNeeded().forPath(sessionPath(streamId));
}
use of org.zalando.nakadi.service.CursorConverter 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();
}
Aggregations