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