Search in sources :

Example 6 with Subscription

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)));
}
Also used : NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) ThrowableProblem(org.zalando.problem.ThrowableProblem) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 7 with Subscription

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);
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Subscription(org.zalando.nakadi.domain.Subscription) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 8 with Subscription

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)));
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Subscription(org.zalando.nakadi.domain.Subscription) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) Test(org.junit.Test)

Example 9 with Subscription

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");
}
Also used : StreamingContext(org.zalando.nakadi.service.subscription.StreamingContext) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) MetricRegistry(com.codahale.metrics.MetricRegistry) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) Subscription(org.zalando.nakadi.domain.Subscription) ZkSubscription(org.zalando.nakadi.service.subscription.zk.ZkSubscription) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) Client(org.zalando.nakadi.security.Client) CursorConverter(org.zalando.nakadi.service.CursorConverter) StreamParametersTest.createStreamParameters(org.zalando.nakadi.service.subscription.StreamParametersTest.createStreamParameters) StreamParameters(org.zalando.nakadi.service.subscription.StreamParameters) Before(org.junit.Before)

Example 10 with Subscription

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();
}
Also used : SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) ImmutableList(com.google.common.collect.ImmutableList) SubscriptionNotInitializedException(org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException) Subscription(org.zalando.nakadi.domain.Subscription) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition)

Aggregations

Subscription (org.zalando.nakadi.domain.Subscription)55 Test (org.junit.Test)40 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)21 EventType (org.zalando.nakadi.domain.EventType)15 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)12 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)11 List (java.util.List)10 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)9 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)9 ImmutableList (com.google.common.collect.ImmutableList)8 Collectors (java.util.stream.Collectors)8 SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)8 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)7 PaginationLinks (org.zalando.nakadi.domain.PaginationLinks)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 IOException (java.io.IOException)6 Optional (java.util.Optional)6 PaginationWrapper (org.zalando.nakadi.domain.PaginationWrapper)6 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)6 NakadiTestUtils.createEventType (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType)5