Search in sources :

Example 56 with Timeline

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

the class CursorOperationsServiceTest method whenTimelinesAreAdjacent.

@Test
public void whenTimelinesAreAdjacent() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 10L);
    final Timeline finalTimeline = mockOpenTimeline(2);
    mockTimelines(initialTimeline, finalTimeline);
    final NakadiCursor initialCursor = NakadiCursor.of(initialTimeline, "0", "0000000000000003");
    final NakadiCursor finalCursor = NakadiCursor.of(finalTimeline, "0", "0000000000000001");
    final Long distance = service.calculateDistance(initialCursor, finalCursor);
    assertThat(distance, equalTo(9L));
}
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 57 with Timeline

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

the class CursorOperationsServiceTest method whenTimelinesAreNotAdjacent.

@Test
public void whenTimelinesAreNotAdjacent() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 10L);
    final Timeline intermediaryTimeline = mockTimeline(2, 9L);
    final Timeline finalTimeline = mockTimeline(3, 0L);
    mockTimelines(initialTimeline, intermediaryTimeline, finalTimeline);
    final NakadiCursor initialCursor = NakadiCursor.of(initialTimeline, "0", "0000000000000003");
    final NakadiCursor finalCursor = NakadiCursor.of(finalTimeline, "0", "0000000000000001");
    assertThat(service.calculateDistance(initialCursor, finalCursor), equalTo(7L + 10L + 2L));
}
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 58 with Timeline

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

the class CursorOperationsServiceTest method shiftCursorToTheRightSameClosedTimeline.

@Test
public void shiftCursorToTheRightSameClosedTimeline() throws Exception {
    final Timeline initialTimeline = mockTimeline(0, 10L);
    final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", 2L);
    mockTimelines(initialTimeline);
    final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
    assertThat(cursor.getOffset(), equalTo("000000000000000005"));
}
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 59 with Timeline

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

the class CursorOperationsServiceTest method whenTimelineExpired.

@Test(expected = InvalidCursorOperation.class)
public void whenTimelineExpired() throws Exception {
    // order is zero
    final Timeline expiredTimeline = timeline;
    final Timeline initialTimeline = mockTimeline(1, 10L);
    final Timeline finalTimeline = mockTimeline(2, 0L);
    mockTimelines(initialTimeline, finalTimeline);
    final NakadiCursor initialCursor = NakadiCursor.of(expiredTimeline, "0", "0000000000000001");
    final NakadiCursor finalCursor = NakadiCursor.of(expiredTimeline, "2", "0000000000000002");
    service.calculateDistance(initialCursor, finalCursor);
}
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 60 with Timeline

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

the class CursorOperationsServiceTest method testShiftToInitialBegin.

@Test
public void testShiftToInitialBegin() throws Exception {
    final Timeline first = mockTimeline(1, 1L);
    final Timeline last = mockOpenTimeline(2);
    mockTimelines(first, last);
    final ShiftedNakadiCursor moveBack = new ShiftedNakadiCursor(last, "0", "000000000000000001", -4);
    assertEquals(NakadiCursor.of(first, "0", "-1"), service.unshiftCursor(moveBack));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) 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