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);
}
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());
}
}
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);
}
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);
}
}
}
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);
}
});
}
Aggregations