use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class EventTypeControllerTest method whenCreateSuccessfullyThen201.
@Test
public void whenCreateSuccessfullyThen201() throws Exception {
final EventType et = buildDefaultEventType();
final Timeline timeline = buildTimelineWithTopic("topic1");
when(timelineService.createDefaultTimeline(anyString(), anyInt(), anyLong())).thenReturn(timeline);
doReturn(et).when(eventTypeRepository).saveEventType(any(EventType.class));
postEventType(et).andExpect(status().isCreated()).andExpect(content().string(""));
verify(eventTypeRepository, times(1)).saveEventType(any(EventType.class));
verify(timelineService, times(1)).createDefaultTimeline(anyString(), anyInt(), anyLong());
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class StreamingStateTest method ensureOffsetsSubscriptionsAreRefreshedAndClosed.
@Test
public void ensureOffsetsSubscriptionsAreRefreshedAndClosed() throws InternalNakadiException, NoSuchEventTypeException, ServiceUnavailableException, InvalidCursorException {
final ZkSubscription<SubscriptionCursorWithoutToken> offsetSubscription = mock(ZkSubscription.class);
final EventTypePartition pk = new EventTypePartition("t", "0");
Mockito.when(zkMock.subscribeForOffsetChanges(Mockito.eq(pk), Mockito.any())).thenReturn(offsetSubscription);
final EventConsumer.ReassignableEventConsumer consumer = mock(EventConsumer.ReassignableEventConsumer.class);
when(consumer.getAssignment()).thenReturn(Collections.emptySet());
when(timelineService.createEventConsumer(any())).thenReturn(consumer);
when(subscription.getEventTypes()).thenReturn(Collections.singleton("t"));
final Storage storage = mock(Storage.class);
when(storage.getType()).thenReturn(Storage.Type.KAFKA);
final Timeline timeline = new Timeline("t", 0, storage, "t", new Date());
when(timelineService.getActiveTimelinesOrdered(eq("t"))).thenReturn(Collections.singletonList(timeline));
final TopicRepository topicRepository = mock(TopicRepository.class);
when(timelineService.getTopicRepository(eq(timeline))).thenReturn(topicRepository);
final PartitionStatistics stats = mock(PartitionStatistics.class);
final NakadiCursor beforeFirstCursor = NakadiCursor.of(timeline, "0", "0");
when(stats.getBeforeFirst()).thenReturn(beforeFirstCursor);
when(topicRepository.loadTopicStatistics(any())).thenReturn(Lists.newArrayList(stats));
state.onEnter();
final NakadiCursor anyCursor = NakadiCursor.of(timeline, "0", "0");
when(cursorConverter.convert(any(SubscriptionCursorWithoutToken.class))).thenReturn(anyCursor);
state.refreshTopologyUnlocked(new Partition[] { new Partition(pk.getEventType(), pk.getPartition(), SESSION_ID, null, Partition.State.ASSIGNED) });
Mockito.verify(zkMock, Mockito.times(1)).subscribeForOffsetChanges(Mockito.eq(pk), Mockito.any());
Mockito.verify(offsetSubscription, Mockito.times(0)).close();
Mockito.verify(offsetSubscription, Mockito.times(0)).getData();
state.offsetChanged(pk);
Mockito.verify(zkMock, Mockito.times(1)).subscribeForOffsetChanges(Mockito.eq(pk), Mockito.any());
Mockito.verify(offsetSubscription, Mockito.times(0)).close();
Mockito.verify(offsetSubscription, Mockito.times(1)).getData();
// Verify that offset change listener is removed
state.refreshTopologyUnlocked(new Partition[0]);
Mockito.verify(zkMock, Mockito.times(1)).subscribeForOffsetChanges(Mockito.eq(pk), Mockito.any());
Mockito.verify(offsetSubscription, Mockito.times(1)).close();
Mockito.verify(offsetSubscription, Mockito.times(1)).getData();
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class SubscriptionValidationServiceTest method setUp.
@Before
public void setUp() throws InternalNakadiException {
final NakadiSettings nakadiSettings = mock(NakadiSettings.class);
when(nakadiSettings.getMaxSubscriptionPartitions()).thenReturn(MAX_SUBSCRIPTION_PARTITIONS);
topicRepository = mock(TopicRepository.class);
when(topicRepository.listPartitionNames(argThat(isOneOf(topicForET(ET1), topicForET(ET2), topicForET(ET3))))).thenReturn(ImmutableList.of(P0));
etRepo = mock(EventTypeRepository.class);
final Map<String, EventType> eventTypes = new HashMap<>();
for (final String etName : new String[] { ET1, ET2, ET3 }) {
final EventType eventType = new EventType();
eventType.setName(etName);
eventTypes.put(etName, eventType);
}
when(etRepo.findByNameO(any())).thenAnswer(invocation -> Optional.ofNullable(eventTypes.get(invocation.getArguments()[0])));
final TimelineService timelineService = mock(TimelineService.class);
for (final EventType et : eventTypes.values()) {
final Timeline timeline = mock(Timeline.class);
when(timeline.getTopic()).thenReturn(topicForET(et.getName()));
when(timeline.getEventType()).thenReturn(et.getName());
when(timelineService.getActiveTimeline(eq(et.getName()))).thenReturn(timeline);
}
when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
when(timelineService.getTopicRepository((EventType) any())).thenReturn(topicRepository);
cursorConverter = mock(CursorConverter.class);
subscriptionValidationService = new SubscriptionValidationService(timelineService, etRepo, nakadiSettings, cursorConverter);
subscriptionBase = new SubscriptionBase();
subscriptionBase.setEventTypes(ImmutableSet.of(ET1, ET2, ET3));
subscriptionBase.setReadFrom(SubscriptionBase.InitialPosition.CURSORS);
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class VersionOneConverterTest method testCorrectParse.
@Test
public void testCorrectParse() throws Exception {
final Cursor cursor = new Cursor("1", "001-0010-012345");
final String eventTypeName = "my_et";
final Timeline firstTimeline = mock(Timeline.class);
when(firstTimeline.getStorage()).thenReturn(new Storage("default", Storage.Type.KAFKA));
when(firstTimeline.getOrder()).thenReturn(16);
when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(Collections.singletonList(firstTimeline));
final NakadiCursor nakadiCursor = converter.convert(eventTypeName, cursor);
Assert.assertEquals(firstTimeline, nakadiCursor.getTimeline());
Assert.assertEquals("1", nakadiCursor.getPartition());
Assert.assertEquals("012345", nakadiCursor.getOffset());
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class VersionOneConverterTest method testInvalidCursorExceptionOnNotExistentTimeline.
@Test
public void testInvalidCursorExceptionOnNotExistentTimeline() throws Exception {
final Cursor cursor = new Cursor("1", "001-0002-012345");
final String eventTypeName = "my_et";
final Timeline firstTimeline = mock(Timeline.class);
when(firstTimeline.getOrder()).thenReturn(1);
final EventType eventType = mock(EventType.class);
when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(Collections.singletonList(firstTimeline));
try {
converter.convert(eventTypeName, cursor);
Assert.fail("Convert should throw exception on invalid cursor");
} catch (final InvalidCursorException ex) {
Assert.assertEquals(CursorError.UNAVAILABLE, ex.getError());
}
}
Aggregations