Search in sources :

Example 6 with Timeline

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

the class VersionOneConverterTest method testFormatOffset.

@Test
public void testFormatOffset() {
    final Timeline timeline = mock(Timeline.class);
    when(timeline.getOrder()).thenReturn(15);
    when(timeline.getStorage()).thenReturn(new Storage("", Storage.Type.KAFKA));
    final NakadiCursor cursor = NakadiCursor.of(timeline, "x", "012345");
    Assert.assertEquals("001-000f-012345", new VersionOneConverter(null).formatOffset(cursor));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Test(org.junit.Test)

Example 7 with Timeline

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

the class CursorOperationsServiceTest method shiftCursorRightToNextTimeline.

@Test
public void shiftCursorRightToNextTimeline() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 10L);
    final Timeline nextTimeline = mockTimeline(2, 3L);
    final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", 9L);
    mockTimelines(initialTimeline, nextTimeline);
    final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
    assertThat(cursor.getTimeline().getOrder(), equalTo(2));
    assertThat(cursor.getOffset(), equalTo("000000000000000001"));
}
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)

Example 8 with Timeline

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

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

use of org.zalando.nakadi.domain.Timeline 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)

Aggregations

Timeline (org.zalando.nakadi.domain.Timeline)74 Test (org.junit.Test)39 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)33 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)19 TopicRepository (org.zalando.nakadi.repository.TopicRepository)17 Date (java.util.Date)14 EventType (org.zalando.nakadi.domain.EventType)14 List (java.util.List)13 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)13 Storage (org.zalando.nakadi.domain.Storage)13 Collectors (java.util.stream.Collectors)12 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)12 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)9 NakadiSettings (org.zalando.nakadi.config.NakadiSettings)9 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)9 Optional (java.util.Optional)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 NakadiException (org.zalando.nakadi.exceptions.NakadiException)8