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)));
}
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());
}
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();
}
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);
}
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);
}
Aggregations