Search in sources :

Example 11 with NakadiCursor

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

the class CursorOperationsServiceTest method calculateDistanceWhenTimelineInTheFutureAndDoesntExist.

@Test
public void calculateDistanceWhenTimelineInTheFutureAndDoesntExist() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 10L);
    final Timeline finalTimeline = mockTimeline(2, 0L);
    final Timeline futureTimeline = mockTimeline(4, 0L);
    mockTimelines(initialTimeline, finalTimeline);
    final NakadiCursor initialCursor = NakadiCursor.of(finalTimeline, "0", "0000000000000001");
    final NakadiCursor finalCursor = NakadiCursor.of(futureTimeline, "0", "0000000000000002");
    expectException(initialCursor, finalCursor, TIMELINE_NOT_FOUND);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 12 with NakadiCursor

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

the class CursorOperationsServiceTest method whenCursorTimelinesAreInvertedThenNegativeDistance.

@Test
public void whenCursorTimelinesAreInvertedThenNegativeDistance() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 7L);
    final Timeline intermediaryTimeline = mockTimeline(2, 9L);
    final Timeline finalTimeline = mockTimeline(3, 5L);
    final NakadiCursor initialCursor = NakadiCursor.of(initialTimeline, "0", "0000000000000001");
    final NakadiCursor finalCursor = NakadiCursor.of(finalTimeline, "0", "0000000000000003");
    mockTimelines(initialTimeline, intermediaryTimeline, finalTimeline);
    final Long distance = service.calculateDistance(finalCursor, initialCursor);
    // Carefully calculated value
    assertThat(distance, equalTo(-20L));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 13 with NakadiCursor

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

the class CursorOperationsServiceTest method missingPartitionInTimeline.

@Test
public void missingPartitionInTimeline() throws Exception {
    final Timeline initialTimeline = mockTimeline(0, 10L);
    final Timeline intermediaryTimeline = mockTimeline(1, 9L);
    final Timeline finalTimeline = mockTimeline(2, 0L);
    mockTimelines(initialTimeline, intermediaryTimeline, finalTimeline);
    final NakadiCursor initialCursor = NakadiCursor.of(initialTimeline, "1", "0000000000000003");
    final NakadiCursor finalCursor = NakadiCursor.of(finalTimeline, "1", "0000000000000001");
    expectException(initialCursor, finalCursor, PARTITION_NOT_FOUND);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 14 with NakadiCursor

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

the class CursorOperationsServiceTest method testDistanceWithEmptyTimelines.

@Test
public void testDistanceWithEmptyTimelines() throws Exception {
    final Timeline first = mockTimeline(1, 9L);
    final Timeline last = mockOpenTimeline(5);
    mockTimelines(first, mockTimeline(2, -1L), mockTimeline(3, -1L), mockTimeline(4, -1L), last);
    final NakadiCursor firstCursor = NakadiCursor.of(first, "0", "000000000000000001");
    final NakadiCursor lastCursor = NakadiCursor.of(last, "0", "000000000000000010");
    assertEquals(service.calculateDistance(firstCursor, lastCursor), 19L);
    assertEquals(service.calculateDistance(lastCursor, firstCursor), -19L);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 15 with NakadiCursor

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

the class CursorOperationsServiceTest method shiftCursorBackInTheSameTimelineClosed.

@Test
public void shiftCursorBackInTheSameTimelineClosed() {
    final Timeline initialTimeline = mockTimeline(0, 10L);
    final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", -3L);
    final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
    assertThat(cursor.getOffset(), equalTo("000000000000000000"));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Aggregations

NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)56 Timeline (org.zalando.nakadi.domain.Timeline)31 Test (org.junit.Test)27 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)21 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)14 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)12 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)12 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)11 List (java.util.List)10 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 Storage (org.zalando.nakadi.domain.Storage)10 TopicRepository (org.zalando.nakadi.repository.TopicRepository)10 Optional (java.util.Optional)8 LoggerFactory (org.slf4j.LoggerFactory)8 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)8 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)8 Collections (java.util.Collections)7 Logger (org.slf4j.Logger)7 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)7