Search in sources :

Example 1 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class SubscriptionValidationServiceTest method whenInvalidCursorThenException.

@Test(expected = WrongInitialCursorsException.class)
public void whenInvalidCursorThenException() throws Exception {
    subscriptionBase.setInitialCursors(ImmutableList.of(new SubscriptionCursorWithoutToken(ET1, P0, ""), new SubscriptionCursorWithoutToken(ET2, P0, ""), new SubscriptionCursorWithoutToken(ET3, P0, "")));
    final NakadiCursor cursor = mockCursorWithTimeline();
    when(cursorConverter.convert((SubscriptionCursorWithoutToken) any())).thenReturn(cursor);
    doThrow(new InvalidCursorException(CursorError.INVALID_FORMAT)).when(topicRepository).validateReadCursors(any());
    subscriptionValidationService.validateSubscription(subscriptionBase);
}
Also used : SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Test(org.junit.Test)

Example 2 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class VersionOneConverterTest method testInvalidCursorExceptionOnNotExistentTimeline.

@Test
public void testInvalidCursorExceptionOnNotExistentTimeline() throws Exception {
    final Cursor cursor = new Cursor("1", "001-0002-012345");
    final String eventTypeName = "my_et";
    final Timeline firstTimeline = mock(Timeline.class);
    when(firstTimeline.getOrder()).thenReturn(1);
    final EventType eventType = mock(EventType.class);
    when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(Collections.singletonList(firstTimeline));
    try {
        converter.convert(eventTypeName, cursor);
        Assert.fail("Convert should throw exception on invalid cursor");
    } catch (final InvalidCursorException ex) {
        Assert.assertEquals(CursorError.UNAVAILABLE, ex.getError());
    }
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) EventType(org.zalando.nakadi.domain.EventType) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) Cursor(org.zalando.nakadi.view.Cursor) Test(org.junit.Test)

Example 3 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class CursorsControllerTest method whenInvalidCursorExceptionThenUnprocessableEntity.

@Test
public void whenInvalidCursorExceptionThenUnprocessableEntity() throws Exception {
    when(cursorsService.commitCursors(any(), any(), any())).thenThrow((new InvalidCursorException(CursorError.NULL_PARTITION, new SubscriptionCursor(null, null, null, null))));
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "partition must not be null");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 4 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class StreamingState method reconfigureKafkaConsumer.

private void reconfigureKafkaConsumer(final boolean forceSeek) {
    if (eventConsumer == null) {
        throw new IllegalStateException("kafkaConsumer should not be null when calling reconfigureKafkaConsumer method");
    }
    final Set<EventTypePartition> newAssignment = offsets.keySet().stream().filter(o -> !this.releasingPartitions.containsKey(o)).collect(Collectors.toSet());
    if (forceSeek) {
        // removing all the current assignments for real consumer.
        try {
            eventConsumer.reassign(Collections.emptyList());
        } catch (final NakadiException | InvalidCursorException ex) {
            throw new NakadiRuntimeException(ex);
        }
    }
    final Set<EventTypePartition> currentAssignment = eventConsumer.getAssignment();
    getLog().info("Changing kafka assignment from {} to {}", Arrays.deepToString(currentAssignment.toArray()), Arrays.deepToString(newAssignment.toArray()));
    if (!currentAssignment.equals(newAssignment)) {
        try {
            final Map<EventTypePartition, NakadiCursor> beforeFirst = getBeforeFirstCursors(newAssignment);
            final List<NakadiCursor> cursors = newAssignment.stream().map(pk -> {
                final NakadiCursor beforeFirstAvailable = beforeFirst.get(pk);
                // Checks that current cursor is still available in storage
                offsets.get(pk).ensureDataAvailable(beforeFirstAvailable);
                return offsets.get(pk).getSentOffset();
            }).collect(Collectors.toList());
            eventConsumer.reassign(cursors);
        } catch (NakadiException | InvalidCursorException ex) {
            throw new NakadiRuntimeException(ex);
        }
    }
}
Also used : ConsumedEvent(org.zalando.nakadi.domain.ConsumedEvent) Arrays(java.util.Arrays) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) IdleStreamWatcher(org.zalando.nakadi.service.subscription.IdleStreamWatcher) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) NakadiException(org.zalando.nakadi.exceptions.NakadiException) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) Partition(org.zalando.nakadi.service.subscription.model.Partition) HashSet(java.util.HashSet) Meter(com.codahale.metrics.Meter) OptionalLong(java.util.OptionalLong) JSONObject(org.json.JSONObject) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Map(java.util.Map) NakadiKpiPublisher(org.zalando.nakadi.service.NakadiKpiPublisher) ZkSubscription(org.zalando.nakadi.service.subscription.zk.ZkSubscription) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) StreamKpiData(org.zalando.nakadi.metrics.StreamKpiData) Set(java.util.Set) IOException(java.io.IOException) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) EventConsumer(org.zalando.nakadi.repository.EventConsumer) List(java.util.List) Stream(java.util.stream.Stream) Timeline(org.zalando.nakadi.domain.Timeline) Closeable(java.io.Closeable) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) MetricUtils(org.zalando.nakadi.metrics.MetricUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) Client(org.zalando.nakadi.security.Client) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) NakadiException(org.zalando.nakadi.exceptions.NakadiException)

Example 5 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class CursorsService method validateSubscriptionCommitCursors.

private void validateSubscriptionCommitCursors(final Subscription subscription, final List<NakadiCursor> cursors) throws UnableProcessException {
    validateCursorsBelongToSubscription(subscription, cursors);
    cursors.forEach(cursor -> {
        try {
            cursor.checkStorageAvailability();
        } catch (final InvalidCursorException e) {
            throw new UnableProcessException(e.getMessage(), e);
        }
    });
}
Also used : InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException)

Aggregations

InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)21 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)15 Timeline (org.zalando.nakadi.domain.Timeline)9 Map (java.util.Map)8 NakadiException (org.zalando.nakadi.exceptions.NakadiException)8 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)8 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)7 Optional (java.util.Optional)6 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)6 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 LoggerFactory (org.slf4j.LoggerFactory)5 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)5 IOException (java.io.IOException)4 CursorError (org.zalando.nakadi.domain.CursorError)4