use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionControllerTest method whenGetNoneExistingSubscriptionThenNotFound.
@Test
public void whenGetNoneExistingSubscriptionThenNotFound() throws Exception {
final Subscription subscription = builder().build();
when(subscriptionRepository.getSubscription(subscription.getId())).thenThrow(new NoSuchSubscriptionException("dummy-message"));
final ThrowableProblem expectedProblem = Problem.valueOf(Response.Status.NOT_FOUND, "dummy-message");
getSubscription(subscription.getId()).andExpect(status().isNotFound()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem)));
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionControllerTest method whenListSubscriptionsWithQueryParamsThenOk.
@Test
public void whenListSubscriptionsWithQueryParamsThenOk() throws Exception {
final List<Subscription> subscriptions = createRandomSubscriptions(10);
when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())).thenReturn(subscriptions);
final PaginationWrapper subscriptionList = new PaginationWrapper(subscriptions, new PaginationLinks());
getSubscriptions(ImmutableSet.of("et1", "et2"), "app", 0, 30).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(subscriptionList)));
verify(subscriptionRepository, times(1)).listSubscriptions(ImmutableSet.of("et1", "et2"), Optional.of("app"), 0, 30);
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionControllerTest method whenListSubscriptionsThenPaginationIsOk.
@Test
public void whenListSubscriptionsThenPaginationIsOk() throws Exception {
final List<Subscription> subscriptions = createRandomSubscriptions(10);
when(subscriptionRepository.listSubscriptions(any(), any(), anyInt(), anyInt())).thenReturn(subscriptions);
final PaginationLinks.Link prevLink = new PaginationLinks.Link("/subscriptions?event_type=et1&event_type=et2&owning_application=app&offset=0&limit=10");
final PaginationLinks.Link nextLink = new PaginationLinks.Link("/subscriptions?event_type=et1&event_type=et2&owning_application=app&offset=15&limit=10");
final PaginationLinks links = new PaginationLinks(Optional.of(prevLink), Optional.of(nextLink));
final PaginationWrapper expectedResult = new PaginationWrapper(subscriptions, links);
getSubscriptions(ImmutableSet.of("et1", "et2"), "app", 5, 10).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedResult)));
}
use of org.zalando.nakadi.domain.Subscription 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.domain.Subscription in project nakadi by zalando.
the class CursorsService method getSubscriptionCursors.
public List<SubscriptionCursorWithoutToken> getSubscriptionCursors(final String subscriptionId) throws NakadiException, ServiceTemporarilyUnavailableException {
final Subscription subscription = subscriptionRepository.getSubscription(subscriptionId);
final ZkSubscriptionClient zkSubscriptionClient = zkSubscriptionFactory.createClient(subscription, "subscription." + subscriptionId + ".get_cursors");
final ImmutableList.Builder<SubscriptionCursorWithoutToken> cursorsListBuilder = ImmutableList.builder();
Partition[] partitions;
try {
partitions = zkSubscriptionClient.getTopology().getPartitions();
} catch (final SubscriptionNotInitializedException ex) {
partitions = new Partition[] {};
}
final Map<EventTypePartition, SubscriptionCursorWithoutToken> positions = zkSubscriptionClient.getOffsets(Stream.of(partitions).map(Partition::getKey).collect(Collectors.toList()));
for (final Partition p : partitions) {
cursorsListBuilder.add(positions.get(p.getKey()));
}
return cursorsListBuilder.build();
}
Aggregations