Search in sources :

Example 11 with EventType

use of org.zalando.nakadi.domain.EventType 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 12 with EventType

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

the class EventTypeServiceTest method shouldRemoveEventTypeWhenTimelineCreationFails.

@Test
public void shouldRemoveEventTypeWhenTimelineCreationFails() throws Exception {
    final EventType eventType = buildDefaultEventType();
    when(timelineService.createDefaultTimeline(anyString(), anyInt(), anyLong())).thenThrow(new TopicCreationException("Failed to create topic"));
    try {
        eventTypeService.create(eventType);
    } catch (final TopicCreationException e) {
    }
    verify(eventTypeRepository, times(1)).removeEventType(eventType.getName());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) TopicCreationException(org.zalando.nakadi.exceptions.TopicCreationException) Test(org.junit.Test)

Example 13 with EventType

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

the class EventTypeServiceTest method whenEventTypeDeletedThenKPIEventSubmitted.

@Test
public void whenEventTypeDeletedThenKPIEventSubmitted() throws Exception {
    final EventType et = buildDefaultEventType();
    when(eventTypeRepository.findByNameO(et.getName())).thenReturn(Optional.of(et));
    eventTypeService.delete(et.getName());
    checkKPIEventSubmitted(nakadiKpiPublisher, KPI_ET_LOG_EVENT_TYPE, new JSONObject().put("event_type", et.getName()).put("status", "deleted").put("category", et.getCategory()).put("authz", "disabled").put("compatibility_mode", et.getCompatibilityMode()));
}
Also used : JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 14 with EventType

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

the class EventTypeControllerTest method eventTypeWithoutSchemaReturns422.

@Test
public void eventTypeWithoutSchemaReturns422() throws Exception {
    final EventType invalidEventType = buildDefaultEventType();
    invalidEventType.setSchema(null);
    final Problem expectedProblem = invalidProblem("schema", "may not be null");
    postETAndExpect422WithProblem(invalidEventType, expectedProblem);
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 15 with EventType

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

the class EventTypeControllerTest method whenUpdateRetentionTimeAndKafkaFails.

@Test
public void whenUpdateRetentionTimeAndKafkaFails() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().build();
    final EventTypeOptions eventTypeOptions = new EventTypeOptions();
    eventTypeOptions.setRetentionTime(172800000L);
    eventType.setOptions(eventTypeOptions);
    doReturn(eventType).when(eventTypeRepository).findByName(eventType.getName());
    doThrow(TopicConfigException.class).when(topicRepository).setRetentionTime(anyString(), anyLong());
    when(timelineService.getActiveTimelinesOrdered(any())).thenReturn(Collections.singletonList(Timeline.createTimeline(eventType.getName(), 0, null, "topic", new Date())));
    final EventType eventType2 = EventTypeTestBuilder.builder().name(eventType.getName()).build();
    final EventTypeOptions eventTypeOptions2 = new EventTypeOptions();
    eventTypeOptions2.setRetentionTime(172800001L);
    eventType2.setOptions(eventTypeOptions2);
    putEventType(eventType2, eventType2.getName(), "nakadi").andExpect(status().isInternalServerError());
    verify(topicRepository, times(2)).setRetentionTime(anyString(), anyLong());
    verify(eventTypeRepository, times(0)).update(any());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeOptions(org.zalando.nakadi.domain.EventTypeOptions) Date(java.util.Date) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)216 Test (org.junit.Test)183 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)138 JSONObject (org.json.JSONObject)40 Problem (org.zalando.problem.Problem)21 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JSONArray (org.json.JSONArray)17 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)17 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)17 ThrowableProblem (org.zalando.problem.ThrowableProblem)17 Timeline (org.zalando.nakadi.domain.Timeline)16 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)14 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)14 BatchItem (org.zalando.nakadi.domain.BatchItem)12 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)12 List (java.util.List)11 Subscription (org.zalando.nakadi.domain.Subscription)11 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)11 Collectors (java.util.stream.Collectors)9