Search in sources :

Example 61 with EventType

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

the class CompatibilityModeChangeConstraintTest method passWhenNoChanges.

@Test
public void passWhenNoChanges() throws Exception {
    final EventTypeTestBuilder builder = new EventTypeTestBuilder();
    final EventType oldET = builder.compatibilityMode(CompatibilityMode.NONE).build();
    final EventType newET = builder.compatibilityMode(CompatibilityMode.NONE).build();
    final CompatibilityModeChangeConstraint constraint = new CompatibilityModeChangeConstraint();
    assertThat(constraint.validate(oldET, newET), isAbsent());
}
Also used : EventType(org.zalando.nakadi.domain.EventType) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 62 with EventType

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

the class CompatibilityModeChangeConstraintTest method canPromoteFromNoneToForward.

@Test
public void canPromoteFromNoneToForward() throws Exception {
    final EventTypeTestBuilder builder = new EventTypeTestBuilder();
    final EventType oldET = builder.compatibilityMode(CompatibilityMode.NONE).build();
    final EventType newET = builder.compatibilityMode(CompatibilityMode.FORWARD).build();
    final CompatibilityModeChangeConstraint constraint = new CompatibilityModeChangeConstraint();
    assertThat(constraint.validate(oldET, newET), isAbsent());
}
Also used : EventType(org.zalando.nakadi.domain.EventType) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 63 with EventType

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

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

the class MetadataEnrichmentStrategyTest method throwsExceptionIfPathNotPresent.

@Test(expected = EnrichmentException.class)
public void throwsExceptionIfPathNotPresent() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    event.remove("metadata");
    strategy.enrich(TestUtils.createBatchItem(event), eventType);
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 65 with EventType

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

the class MetadataEnrichmentStrategyTest method whenFlowIsEmptyStringOverrideIt.

@Test
public void whenFlowIsEmptyStringOverrideIt() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    event.getJSONObject("metadata").put("flow_id", "");
    final BatchItem batch = createBatchItem(event);
    final String flowId = randomString();
    FlowIdUtils.push(flowId);
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("flow_id"), equalTo(flowId));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) TestUtils.randomString(org.zalando.nakadi.utils.TestUtils.randomString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) 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