Search in sources :

Example 6 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition 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 7 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition 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 8 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class PartitionTest method moveAssignedShouldPutToAssignedStateIfOwnerSessionIsInvalid.

@Test
public void moveAssignedShouldPutToAssignedStateIfOwnerSessionIsInvalid() {
    final Collection<String> valid = Arrays.asList("T", "T1");
    final String eventType = "et";
    final String partition = "partition";
    final Partition test = new Partition(eventType, partition, "x", null, Partition.State.ASSIGNED).moveToSessionId("T", valid);
    assertEquals(new EventTypePartition(eventType, partition), test.getKey());
    Assert.assertEquals(Partition.State.ASSIGNED, test.getState());
    assertEquals("T", test.getSession());
    assertNull(test.getNextSession());
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Test(org.junit.Test)

Example 9 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class PartitionTest method moveReassigningPartitionShouldPutToAssignedState.

@Test
public void moveReassigningPartitionShouldPutToAssignedState() {
    final Collection<String> validSessions = Arrays.asList("T", "T1", "T2");
    final String eventType = "et";
    final String partition = "partition";
    ImmutableList.of(new Partition(eventType, partition, "x", "x1", Partition.State.REASSIGNING), new Partition(eventType, partition, "x", "T", Partition.State.REASSIGNING), new Partition(eventType, partition, "T", "x", Partition.State.REASSIGNING), new Partition(eventType, partition, "T", "T1", Partition.State.REASSIGNING)).forEach(testPartition -> {
        final Partition movedPartition = testPartition.moveToSessionId("T", validSessions);
        assertEquals(new EventTypePartition(eventType, partition), movedPartition.getKey());
        Assert.assertEquals(Partition.State.ASSIGNED, movedPartition.getState());
        assertEquals("T", movedPartition.getSession());
        assertNull(movedPartition.getNextSession());
    });
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Test(org.junit.Test)

Example 10 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class PartitionTest method moveAssignedShouldPutToAssignedStateIfMoveToSelf.

@Test
public void moveAssignedShouldPutToAssignedStateIfMoveToSelf() {
    final Collection<String> valid = Arrays.asList("T", "T1");
    final String eventType = "et";
    final String partition = "partition";
    final Partition test = new Partition(eventType, partition, "T", null, Partition.State.ASSIGNED).moveToSessionId("T", valid);
    assertEquals(new EventTypePartition(eventType, partition), test.getKey());
    Assert.assertEquals(Partition.State.ASSIGNED, test.getState());
    assertEquals("T", test.getSession());
    assertNull(test.getNextSession());
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Test(org.junit.Test)

Aggregations

EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)27 Test (org.junit.Test)16 Partition (org.zalando.nakadi.service.subscription.model.Partition)15 Session (org.zalando.nakadi.service.subscription.model.Session)11 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)9 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)6 Map (java.util.Map)5 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Subscription (org.zalando.nakadi.domain.Subscription)3 NakadiException (org.zalando.nakadi.exceptions.NakadiException)3 ZkSubscriptionClient (org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient)3