use of org.zalando.nakadi.service.timeline.TimelineService 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.timeline.TimelineService 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();
}
use of org.zalando.nakadi.service.timeline.TimelineService in project nakadi by zalando.
the class EventStreamControllerTest method setup.
@Before
public void setup() throws NakadiException, UnknownHostException, InvalidCursorException {
EVENT_TYPE.setName(TEST_EVENT_TYPE_NAME);
timeline = buildTimelineWithTopic(TEST_TOPIC);
eventTypeRepository = mock(EventTypeRepository.class);
topicRepositoryMock = mock(TopicRepository.class);
adminService = mock(AdminService.class);
authorizationService = mock(AuthorizationService.class);
when(topicRepositoryMock.topicExists(TEST_TOPIC)).thenReturn(true);
eventStreamFactoryMock = mock(EventStreamFactory.class);
eventTypeCache = mock(EventTypeCache.class);
requestMock = mock(HttpServletRequest.class);
when(requestMock.getRemoteAddr()).thenReturn(InetAddress.getLoopbackAddress().getHostAddress());
when(requestMock.getRemotePort()).thenReturn(12345);
responseMock = mock(HttpServletResponse.class);
metricRegistry = new MetricRegistry();
streamMetrics = new MetricRegistry();
final EventConsumer.LowLevelConsumer eventConsumerMock = mock(EventConsumer.LowLevelConsumer.class);
when(topicRepositoryMock.createEventConsumer(eq(KAFKA_CLIENT_ID), any())).thenReturn(eventConsumerMock);
final ClosedConnectionsCrutch crutch = mock(ClosedConnectionsCrutch.class);
when(crutch.listenForConnectionClose(requestMock)).thenReturn(new AtomicBoolean(true));
blacklistService = Mockito.mock(BlacklistService.class);
Mockito.when(blacklistService.isConsumptionBlocked(any(), any())).thenReturn(false);
final ConsumerLimitingService consumerLimitingService = Mockito.mock(ConsumerLimitingService.class);
when(consumerLimitingService.acquireConnectionSlots(any(), any(), any())).thenReturn(ImmutableList.of());
featureToggleService = mock(FeatureToggleService.class);
timelineService = mock(TimelineService.class);
when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepositoryMock);
when(timelineService.getTopicRepository((EventTypeBase) any())).thenReturn(topicRepositoryMock);
when(timelineService.getTopicRepository((Storage) any())).thenReturn(topicRepositoryMock);
when(timelineService.getActiveTimelinesOrdered(any())).thenReturn(Collections.singletonList(timeline));
when(timelineService.getAllTimelinesOrdered(any())).thenReturn(Collections.singletonList(timeline));
authorizationValidator = mock(AuthorizationValidator.class);
eventTypeChangeListener = mock(EventTypeChangeListener.class);
when(eventTypeChangeListener.registerListener(any(), any())).thenReturn(mock(Closeable.class));
controller = new EventStreamController(eventTypeRepository, timelineService, TestUtils.OBJECT_MAPPER, eventStreamFactoryMock, metricRegistry, streamMetrics, crutch, blacklistService, consumerLimitingService, featureToggleService, new CursorConverterImpl(eventTypeCache, timelineService), authorizationValidator, eventTypeChangeListener, null);
settings = mock(SecuritySettings.class);
when(settings.getAuthMode()).thenReturn(OFF);
when(settings.getAdminClientId()).thenReturn("nakadi");
mockMvc = standaloneSetup(controller).setMessageConverters(new StringHttpMessageConverter(), TestUtils.JACKSON_2_HTTP_MESSAGE_CONVERTER).setCustomArgumentResolvers(new ClientResolver(settings, featureToggleService)).build();
}
use of org.zalando.nakadi.service.timeline.TimelineService in project nakadi by zalando.
the class PartitionResolverTest method before.
@Before
public void before() throws NakadiException {
final TopicRepository topicRepository = Mockito.mock(TopicRepository.class);
when(topicRepository.listPartitionNames(any(String.class))).thenReturn(ImmutableList.of("0"));
timelineService = Mockito.mock(TimelineService.class);
when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
when(timelineService.getTopicRepository((EventType) any())).thenReturn(topicRepository);
partitionResolver = new PartitionResolver(timelineService, mock(HashPartitionStrategy.class));
}
Aggregations