Search in sources :

Example 1 with InternalNakadiException

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");
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeDeletionException(org.zalando.nakadi.exceptions.runtime.EventTypeDeletionException) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 2 with InternalNakadiException

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)));
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with InternalNakadiException

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);
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) Test(org.junit.Test)

Example 4 with InternalNakadiException

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);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) EventType(org.zalando.nakadi.domain.EventType) InconsistentStateException(org.zalando.nakadi.exceptions.runtime.InconsistentStateException) Date(java.util.Date) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException)

Example 5 with InternalNakadiException

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);
    }
}
Also used : StartingState(org.zalando.nakadi.service.subscription.state.StartingState) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiSettings(org.zalando.nakadi.config.NakadiSettings) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Subscription(org.zalando.nakadi.domain.Subscription) NakadiException(org.zalando.nakadi.exceptions.NakadiException) SubscriptionNotInitializedException(org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Partition(org.zalando.nakadi.service.subscription.model.Partition) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) ImmutableList(com.google.common.collect.ImmutableList) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Map(java.util.Map) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) SubscriptionClientFactory(org.zalando.nakadi.service.subscription.zk.SubscriptionClientFactory) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) OperationTimeoutException(org.zalando.nakadi.exceptions.runtime.OperationTimeoutException) ZookeeperException(org.zalando.nakadi.exceptions.runtime.ZookeeperException) Collectors(java.util.stream.Collectors) TimeLogger(org.zalando.nakadi.util.TimeLogger) TimeUnit(java.util.concurrent.TimeUnit) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) Component(org.springframework.stereotype.Component) List(java.util.List) Stream(java.util.stream.Stream) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) SubscriptionDbRepository(org.zalando.nakadi.repository.db.SubscriptionDbRepository) InvalidStreamIdException(org.zalando.nakadi.exceptions.InvalidStreamIdException) NoSuchSubscriptionException(org.zalando.nakadi.exceptions.NoSuchSubscriptionException) CursorError(org.zalando.nakadi.domain.CursorError) Comparator(java.util.Comparator) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Subscription(org.zalando.nakadi.domain.Subscription) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)19 EventType (org.zalando.nakadi.domain.EventType)11 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)11 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)7 Test (org.junit.Test)6 TopicRepository (org.zalando.nakadi.repository.TopicRepository)5 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)4 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)4 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 CursorError (org.zalando.nakadi.domain.CursorError)3 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)3 Subscription (org.zalando.nakadi.domain.Subscription)3 Timeline (org.zalando.nakadi.domain.Timeline)3 DuplicatedEventTypeNameException (org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException)3 ServiceTemporarilyUnavailableException (org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException)3 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableList (com.google.common.collect.ImmutableList)2