Search in sources :

Example 6 with NakadiCursor

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

the class VersionOneConverterTest method testCorrectParse.

@Test
public void testCorrectParse() throws Exception {
    final Cursor cursor = new Cursor("1", "001-0010-012345");
    final String eventTypeName = "my_et";
    final Timeline firstTimeline = mock(Timeline.class);
    when(firstTimeline.getStorage()).thenReturn(new Storage("default", Storage.Type.KAFKA));
    when(firstTimeline.getOrder()).thenReturn(16);
    when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(Collections.singletonList(firstTimeline));
    final NakadiCursor nakadiCursor = converter.convert(eventTypeName, cursor);
    Assert.assertEquals(firstTimeline, nakadiCursor.getTimeline());
    Assert.assertEquals("1", nakadiCursor.getPartition());
    Assert.assertEquals("012345", nakadiCursor.getOffset());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Cursor(org.zalando.nakadi.view.Cursor) Test(org.junit.Test)

Example 7 with NakadiCursor

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

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

the class CursorOperationsServiceTest method whenCursorsAreInTheSameTimeline.

@Test
public void whenCursorsAreInTheSameTimeline() throws Exception {
    final NakadiCursor initialCursor = NakadiCursor.of(timeline, "0", "0000000000000001");
    final NakadiCursor finalCursor = NakadiCursor.of(timeline, "0", "0000000000000002");
    final Long distance = service.calculateDistance(initialCursor, finalCursor);
    assertThat(distance, equalTo(1L));
}
Also used : NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 9 with NakadiCursor

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

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

the class CursorOperationsServiceTest method whenPartitionsDontMatch.

@Test
public void whenPartitionsDontMatch() throws Exception {
    final NakadiCursor initialCursor = NakadiCursor.of(timeline, "1", "0000000000000001");
    final NakadiCursor finalCursor = NakadiCursor.of(timeline, "0", "0000000000000002");
    expectException(initialCursor, finalCursor, CURSORS_WITH_DIFFERENT_PARTITION);
}
Also used : NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) 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