Search in sources :

Example 1 with EventTypeBase

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

the class EventTypeControllerTest method whenPostOptionsRetentionTimeExist.

@Test
public void whenPostOptionsRetentionTimeExist() throws Exception {
    final EventType defaultEventType = buildDefaultEventType();
    defaultEventType.getOptions().setRetentionTime(TOPIC_RETENTION_TIME_MS);
    postEventType(defaultEventType).andExpect(status().is2xxSuccessful());
    final ArgumentCaptor<EventTypeBase> eventTypeCaptor = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository, times(1)).saveEventType(eventTypeCaptor.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, eventTypeCaptor.getValue().getOptions().getRetentionTime().longValue());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Test(org.junit.Test)

Example 2 with EventTypeBase

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

the class EventTypeControllerTest method whenPostNullOptions201.

@Test
public void whenPostNullOptions201() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.setOptions(null);
    postEventType(eventType).andExpect(status().isCreated());
    final ArgumentCaptor<EventTypeBase> argument = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository).saveEventType(argument.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, argument.getValue().getOptions().getRetentionTime().longValue());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Test(org.junit.Test)

Example 3 with EventTypeBase

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

the class SchemaEvolutionService method checkEvolutionIncompatibilities.

private void checkEvolutionIncompatibilities(final EventType from, final EventTypeBase to) throws InvalidEventTypeException {
    final List<SchemaEvolutionIncompatibility> incompatibilities = schemaEvolutionConstraints.stream().map(c -> c.validate(from, to)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    if (incompatibilities.isEmpty()) {
        return;
    }
    // There is a special case of incompatibility - change of category from NONE to BUSINESS, with adding metadata.
    // Let's check that it is the case.
    // This solution is not scalable, but without huge refactoring it is the simplest one.
    final boolean categoryChanged = incompatibilities.stream().anyMatch(v -> v instanceof SchemaEvolutionIncompatibility.CategoryIncompatibility);
    if (categoryChanged) {
        final boolean metadataChanged = incompatibilities.stream().anyMatch(v -> v instanceof SchemaEvolutionIncompatibility.MetadataIncompatibility);
        final int expectedIncompatibilities = 1 + (metadataChanged ? 1 : 0);
        if (incompatibilities.size() == expectedIncompatibilities) {
            // Now let's check, that it is really change from NONE to BUSINESS and some other conditions.
            if (from.getCategory() == EventCategory.UNDEFINED && to.getCategory() == EventCategory.BUSINESS) {
                if (to.getEnrichmentStrategies().contains(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT) && to.getCompatibilityMode() != CompatibilityMode.COMPATIBLE) {
                    // Finally, we are allowing this step.
                    return;
                }
            }
        }
        throw new InvalidEventTypeException("Category change is allowed only from 'undefined' to 'business'. " + "'enrichment_strategies' should be properly set as well");
    }
    throw new InvalidEventTypeException(incompatibilities.stream().map(SchemaEvolutionIncompatibility::getReason).collect(Collectors.joining("; ")));
}
Also used : EventCategory(org.zalando.nakadi.domain.EventCategory) DateTimeZone(org.joda.time.DateTimeZone) PATCH(org.zalando.nakadi.domain.Version.Level.PATCH) SchemaEvolutionIncompatibility(org.zalando.nakadi.validation.schema.SchemaEvolutionIncompatibility) EnrichmentStrategyDescriptor(org.zalando.nakadi.domain.EnrichmentStrategyDescriptor) ForbiddenAttributeIncompatibility(org.zalando.nakadi.validation.schema.ForbiddenAttributeIncompatibility) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) JSONObject(org.json.JSONObject) SchemaDiff(org.zalando.nakadi.validation.schema.diff.SchemaDiff) Map(java.util.Map) SchemaLoader(org.everit.json.schema.loader.SchemaLoader) ADDITIONAL_ITEMS_CHANGED(org.zalando.nakadi.domain.SchemaChange.Type.ADDITIONAL_ITEMS_CHANGED) ADDITIONAL_PROPERTIES_CHANGED(org.zalando.nakadi.domain.SchemaChange.Type.ADDITIONAL_PROPERTIES_CHANGED) EventType(org.zalando.nakadi.domain.EventType) ValidationException(org.everit.json.schema.ValidationException) REQUIRED_ARRAY_EXTENDED(org.zalando.nakadi.domain.SchemaChange.Type.REQUIRED_ARRAY_EXTENDED) DateTime(org.joda.time.DateTime) MAJOR(org.zalando.nakadi.domain.Version.Level.MAJOR) NO_CHANGES(org.zalando.nakadi.domain.Version.Level.NO_CHANGES) SchemaEvolutionConstraint(org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Version(org.zalando.nakadi.domain.Version) List(java.util.List) TITLE_CHANGED(org.zalando.nakadi.domain.SchemaChange.Type.TITLE_CHANGED) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) CompatibilityMode(org.zalando.nakadi.domain.CompatibilityMode) Schema(org.everit.json.schema.Schema) Optional(java.util.Optional) DESCRIPTION_CHANGED(org.zalando.nakadi.domain.SchemaChange.Type.DESCRIPTION_CHANGED) PROPERTIES_ADDED(org.zalando.nakadi.domain.SchemaChange.Type.PROPERTIES_ADDED) InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) Optional(java.util.Optional) SchemaEvolutionIncompatibility(org.zalando.nakadi.validation.schema.SchemaEvolutionIncompatibility) SchemaEvolutionConstraint(org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint)

Example 4 with EventTypeBase

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

the class EventTypeControllerTest method whenPostNullRetentionTime201.

@Test
public void whenPostNullRetentionTime201() throws Exception {
    final EventType eventType = buildDefaultEventType();
    eventType.getOptions().setRetentionTime(null);
    postEventType(eventType).andExpect(status().isCreated());
    final ArgumentCaptor<EventTypeBase> argument = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository).saveEventType(argument.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, argument.getValue().getOptions().getRetentionTime().longValue());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Test(org.junit.Test)

Example 5 with EventTypeBase

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

the class EventTypeControllerTest method whenPostOptionsRetentionTimeDoesNotExist.

@Test
public void whenPostOptionsRetentionTimeDoesNotExist() throws Exception {
    final EventType defaultEventType = buildDefaultEventType();
    postEventType(defaultEventType).andExpect(status().is2xxSuccessful());
    final ArgumentCaptor<EventTypeBase> eventTypeCaptor = ArgumentCaptor.forClass(EventTypeBase.class);
    verify(eventTypeRepository, times(1)).saveEventType(eventTypeCaptor.capture());
    assertEquals(TOPIC_RETENTION_TIME_MS, eventTypeCaptor.getValue().getOptions().getRetentionTime().longValue());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)7 EventTypeBase (org.zalando.nakadi.domain.EventTypeBase)7 Test (org.junit.Test)5 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)5 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Charsets (com.google.common.base.Charsets)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 RestAssured.get (com.jayway.restassured.RestAssured.get)1 RestAssured.given (com.jayway.restassured.RestAssured.given)1 RestAssured.when (com.jayway.restassured.RestAssured.when)1 JSON (com.jayway.restassured.http.ContentType.JSON)1 Response (com.jayway.restassured.response.Response)1 IOException (java.io.IOException)1