Search in sources :

Example 1 with EventType

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

the class EventPublisherTest method whenEventIsTooLargeThenAllItemsAreAborted.

@Test
public void whenEventIsTooLargeThenAllItemsAreAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(1);
    final JSONObject largeEvent = new JSONObject();
    largeEvent.put("foo", randomStringOfLength(10000));
    batch.put(largeEvent);
    final JSONObject smallEvent = new JSONObject();
    smallEvent.put("foo", randomString());
    batch.put(smallEvent);
    mockSuccessfulValidation(eventType);
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    final BatchItemResponse firstResponse = result.getResponses().get(0);
    assertThat(firstResponse.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
    assertThat(firstResponse.getStep(), equalTo(EventPublishingStep.VALIDATING));
    assertThat(firstResponse.getDetail(), is(isEmptyString()));
    final BatchItemResponse secondResponse = result.getResponses().get(1);
    assertThat(secondResponse.getPublishingStatus(), equalTo(EventPublishingStatus.FAILED));
    assertThat(secondResponse.getStep(), equalTo(EventPublishingStep.VALIDATING));
    assertThat(secondResponse.getDetail(), startsWith("Event too large"));
    final BatchItemResponse thirdResponse = result.getResponses().get(2);
    assertThat(thirdResponse.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
    assertThat(thirdResponse.getStep(), equalTo(EventPublishingStep.NONE));
    assertThat(thirdResponse.getDetail(), is(isEmptyString()));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse) Test(org.junit.Test)

Example 2 with EventType

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

the class EventPublisherTest method whenPartitionFailsThenResultIsAborted.

@Test
public void whenPartitionFailsThenResultIsAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final List<BatchItem> batch = new ArrayList<>();
    batch.add(createBatchItem(buildDefaultBatch(1).getJSONObject(0)));
    final JSONObject event = batch.get(0).getEvent();
    mockSuccessfulValidation(eventType);
    mockFaultPartition();
    final EventPublishResult result = publisher.publish(createStringFromBatchItems(batch), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with EventType

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

the class EventPublisherTest method whenEnrichmentFailsThenResultIsAborted.

@Test
public void whenEnrichmentFailsThenResultIsAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(1);
    final JSONObject event = batch.getJSONObject(0);
    mockSuccessfulValidation(eventType);
    mockFaultEnrichment();
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    verify(cache, times(1)).getValidator(eventType.getName());
    verify(partitionResolver, times(1)).resolvePartition(any(), any());
    verify(enrichment, times(1)).enrich(any(), any());
    verify(topicRepository, times(0)).syncPostBatch(any(), any());
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 4 with EventType

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

the class EventPublisherTest method whenEnrichmentFailsThenSubsequentItemsAreAborted.

@Test
public void whenEnrichmentFailsThenSubsequentItemsAreAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(2);
    mockSuccessfulValidation(eventType);
    mockFaultEnrichment();
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    final BatchItemResponse first = result.getResponses().get(0);
    assertThat(first.getPublishingStatus(), equalTo(EventPublishingStatus.FAILED));
    assertThat(first.getStep(), equalTo(EventPublishingStep.ENRICHING));
    assertThat(first.getDetail(), equalTo("enrichment error"));
    final BatchItemResponse second = result.getResponses().get(1);
    assertThat(second.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
    assertThat(second.getStep(), equalTo(EventPublishingStep.PARTITIONING));
    assertThat(second.getDetail(), is(isEmptyString()));
    verify(enrichment, times(1)).enrich(any(), any());
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse) Test(org.junit.Test)

Example 5 with EventType

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

the class EventPublisherTest method whenValidationFailsThenSubsequentItemsAreAborted.

@Test
public void whenValidationFailsThenSubsequentItemsAreAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(2);
    final JSONObject event = batch.getJSONObject(0);
    mockFaultValidation(eventType, "error");
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    final BatchItemResponse first = result.getResponses().get(0);
    assertThat(first.getPublishingStatus(), equalTo(EventPublishingStatus.FAILED));
    assertThat(first.getStep(), equalTo(EventPublishingStep.VALIDATING));
    assertThat(first.getDetail(), equalTo("error"));
    final BatchItemResponse second = result.getResponses().get(1);
    assertThat(second.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
    assertThat(second.getStep(), equalTo(EventPublishingStep.NONE));
    assertThat(second.getDetail(), is(isEmptyString()));
    verify(cache, times(1)).getValidator(any());
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) JSONArray(org.json.JSONArray) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse) 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