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