Search in sources :

Example 6 with Partition

use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.

the class SubscriptionRebalancerTest method onlyDirectSessionsWorkFine.

@Test
public void onlyDirectSessionsWorkFine() {
    final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("s1", 1, ImmutableList.of(new EventTypePartition("et1", "p3"))), new Session("s2", 1, ImmutableList.of(new EventTypePartition("et1", "p2")))), new Partition[] { new Partition("et1", "p1", null, null, UNASSIGNED), new Partition("et1", "p2", null, null, UNASSIGNED), new Partition("et1", "p3", null, null, UNASSIGNED), new Partition("et1", "p4", null, null, UNASSIGNED) });
    assertEquals(newHashSet(changeset), newHashSet(new Partition("et1", "p3", "s1", null, ASSIGNED), new Partition("et1", "p2", "s2", null, ASSIGNED)));
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 7 with Partition

use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.

the class StreamingStateTest method ensureTopologyEventListenerRegisteredRefreshedClosed.

@Test
public void ensureTopologyEventListenerRegisteredRefreshedClosed() {
    final ZkSubscription topologySubscription = mock(ZkSubscription.class);
    Mockito.when(topologySubscription.getData()).thenReturn(new ZkSubscriptionClient.Topology(new Partition[] {}, null, 1));
    Mockito.when(zkMock.subscribeForTopologyChanges(Mockito.anyObject())).thenReturn(topologySubscription);
    state.onEnter();
    Mockito.verify(zkMock, Mockito.times(1)).subscribeForTopologyChanges(Mockito.any());
    Mockito.verify(topologySubscription, Mockito.times(1)).getData();
    state.reactOnTopologyChange();
    Mockito.verify(topologySubscription, Mockito.times(2)).getData();
    Mockito.verify(topologySubscription, Mockito.times(0)).close();
    state.onExit();
    Mockito.verify(topologySubscription, Mockito.times(1)).close();
    // verify that no new locks created.
    Mockito.verify(zkMock, Mockito.times(1)).subscribeForTopologyChanges(Mockito.any());
}
Also used : ZkSubscription(org.zalando.nakadi.service.subscription.zk.ZkSubscription) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) Test(org.junit.Test)

Example 8 with Partition

use of org.zalando.nakadi.service.subscription.model.Partition 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();
}
Also used : SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) EventConsumer(org.zalando.nakadi.repository.EventConsumer) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) TopicRepository(org.zalando.nakadi.repository.TopicRepository) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Partition

use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.

the class ZkSubscriptionNodeTest method before.

@Before
public void before() {
    final List<Partition> partitions = ImmutableList.of(new Partition("et1", "0", "stream1", null, Partition.State.ASSIGNED), new Partition("et1", "1", "stream2", "stream4", Partition.State.REASSIGNING), new Partition("et2", "0", "stream3", null, Partition.State.UNASSIGNED), new Partition("et2", "1", null, null, null));
    final List<Session> sessions = ImmutableList.of(new Session("stream1", 1, ImmutableList.of(new EventTypePartition("et1", "0"))), new Session("stream2", 1), new Session("stream3", 1), new Session("stream4", 1));
    zkSubscriptionNode = new ZkSubscriptionNode(partitions, sessions);
}
Also used : Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Before(org.junit.Before)

Example 10 with Partition

use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.

the class ZkSubscriptionClientTest method testSerializationDeserialization.

@Test
public void testSerializationDeserialization() throws IOException {
    final ZkSubscriptionClient.Topology first = new ZkSubscriptionClient.Topology(new Partition[] { new Partition("1", "2", "3", "4", Partition.State.ASSIGNED) }, "123", 456);
    final String serialized = TestUtils.OBJECT_MAPPER.writer().writeValueAsString(first);
    final ZkSubscriptionClient.Topology second = TestUtils.OBJECT_MAPPER.readValue(serialized, ZkSubscriptionClient.Topology.class);
    Assert.assertEquals(first, second);
}
Also used : Partition(org.zalando.nakadi.service.subscription.model.Partition) Test(org.junit.Test)

Aggregations

Partition (org.zalando.nakadi.service.subscription.model.Partition)25 Test (org.junit.Test)18 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)18 Session (org.zalando.nakadi.service.subscription.model.Session)13 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)6 Stream (java.util.stream.Stream)5 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 BiFunction (java.util.function.BiFunction)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Subscription (org.zalando.nakadi.domain.Subscription)2 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)2