use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class EventTypeServiceTest method testFailToDeleteEventType.
@Test
public void testFailToDeleteEventType() throws Exception {
final EventType eventType = buildDefaultEventType();
doThrow(new InternalNakadiException("Can't delete event tye")).when(eventTypeRepository).removeEventType(eventType.getName());
doReturn(Optional.of(eventType)).when(eventTypeRepository).findByNameO(eventType.getName());
final Multimap<TopicRepository, String> topicsToDelete = mock(Multimap.class);
doReturn(new ArrayList<Subscription>()).when(subscriptionDbRepository).listSubscriptions(ImmutableSet.of(eventType.getName()), Optional.empty(), 0, 1);
doReturn(topicsToDelete).when(timelineService).deleteAllTimelinesForEventType(eventType.getName());
try {
eventTypeService.delete(eventType.getName());
} catch (final EventTypeDeletionException e) {
// check that topics are not deleted in Kafka
verifyZeroInteractions(topicsToDelete);
return;
}
fail("Should have thrown an EventTypeDeletionException");
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class EventTypeControllerTest method whenDeleteEventTypeAndNakadiExceptionThen500.
@Test
public void whenDeleteEventTypeAndNakadiExceptionThen500() throws Exception {
final String eventTypeName = randomValidEventTypeName();
final Problem expectedProblem = Problem.valueOf(Response.Status.INTERNAL_SERVER_ERROR, "Failed to delete event type " + eventTypeName);
doThrow(new InternalNakadiException("dummy message")).when(eventTypeRepository).removeEventType(eventTypeName);
doReturn(Optional.of(EventTypeTestBuilder.builder().name(eventTypeName).build())).when(eventTypeRepository).findByNameO(eventTypeName);
deleteEventType(eventTypeName).andExpect(status().isInternalServerError()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class SubscriptionValidationServiceTest method whenFindEventTypeThrowsInternalExceptionThenIncosistentState.
@Test(expected = InconsistentStateException.class)
public void whenFindEventTypeThrowsInternalExceptionThenIncosistentState() throws Exception {
when(etRepo.findByNameO(argThat(isOneOf(ET1, ET2, ET3)))).thenThrow(new InternalNakadiException(""));
subscriptionValidationService.validateSubscription(subscriptionBase);
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class TimelineService method scheduleTimelineCleanup.
private void scheduleTimelineCleanup(final Timeline timeline) throws InconsistentStateException {
try {
final EventType eventType = eventTypeCache.getEventType(timeline.getEventType());
final Long retentionTime = eventType.getOptions().getRetentionTime();
if (retentionTime == null) {
throw new InconsistentStateException("Event type should has information about its retention time");
}
final Date cleanupDate = new Date(System.currentTimeMillis() + retentionTime);
timeline.setCleanedUpAt(cleanupDate);
} catch (final InternalNakadiException | NoSuchEventTypeException e) {
throw new InconsistentStateException("Unexpected error occurred when scheduling timeline cleanup", e);
}
}
use of org.zalando.nakadi.exceptions.InternalNakadiException in project nakadi by zalando.
the class CursorsService method resetCursors.
public void resetCursors(final String subscriptionId, final List<NakadiCursor> cursors) throws ServiceUnavailableException, NoSuchSubscriptionException, UnableProcessException, OperationTimeoutException, ZookeeperException, InternalNakadiException, NoSuchEventTypeException, InvalidCursorException {
final Subscription subscription = subscriptionRepository.getSubscription(subscriptionId);
validateCursorsBelongToSubscription(subscription, cursors);
for (final NakadiCursor cursor : cursors) {
cursor.checkStorageAvailability();
}
final Map<TopicRepository, List<NakadiCursor>> topicRepositories = cursors.stream().collect(Collectors.groupingBy(c -> timelineService.getTopicRepository(c.getTimeline())));
for (final Map.Entry<TopicRepository, List<NakadiCursor>> entry : topicRepositories.entrySet()) {
entry.getKey().validateReadCursors(entry.getValue());
}
final ZkSubscriptionClient zkClient = zkSubscriptionFactory.createClient(subscription, "subscription." + subscriptionId + ".reset_cursors");
// In case if subscription was never initialized - initialize it
zkClient.runLocked(() -> StartingState.initializeSubscriptionLocked(zkClient, subscription, timelineService, cursorConverter));
// add 1 second to commit timeout in order to give time to finish reset if there is uncommitted events
if (!cursors.isEmpty()) {
final long timeout = TimeUnit.SECONDS.toMillis(nakadiSettings.getDefaultCommitTimeoutSeconds()) + TimeUnit.SECONDS.toMillis(1);
zkClient.resetCursors(cursors.stream().map(cursorConverter::convertToNoToken).collect(Collectors.toList()), timeout);
}
}
Aggregations