Search in sources :

Example 16 with EventPublishResult

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

the class EventPublisherTest method whenEnrichmentMakesEventTooLargeThenAllItemsAreAborted.

@Test
public void whenEnrichmentMakesEventTooLargeThenAllItemsAreAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(1);
    final JSONObject largeEvent = new JSONObject();
    largeEvent.put("foo", randomStringOfLength(880));
    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 17 with EventPublishResult

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

the class EventPublisherTest method whenEventIsTooLargeThenResultIsAborted.

@Test
public void whenEventIsTooLargeThenResultIsAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildLargeBatch(1);
    mockSuccessfulValidation(eventType);
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    verify(enrichment, times(0)).enrich(any(), any());
    verify(partitionResolver, times(0)).resolvePartition(any(), any());
    verify(topicRepository, times(0)).syncPostBatch(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) Test(org.junit.Test)

Example 18 with EventPublishResult

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

the class EventPublisherTest method whenEventIsExactlyMaxSizeThenResultIsSuccess.

@Test
public void whenEventIsExactlyMaxSizeThenResultIsSuccess() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildMaxSizeBatch(1);
    mockSuccessfulValidation(eventType);
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.SUBMITTED));
    verify(enrichment, times(1)).enrich(any(), any());
    verify(partitionResolver, times(1)).resolvePartition(any(), any());
    verify(topicRepository, times(1)).syncPostBatch(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) Test(org.junit.Test)

Example 19 with EventPublishResult

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

the class EventPublisherTest method whenValidationFailsThenResultIsAborted.

@Test
public void whenValidationFailsThenResultIsAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(1);
    final JSONObject event = batch.getJSONObject(0);
    mockFaultValidation(eventType, "error");
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
    verify(enrichment, times(0)).enrich(createBatchItem(event), eventType);
    verify(partitionResolver, times(0)).resolvePartition(eventType, event);
    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 20 with EventPublishResult

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

the class EventPublisherTest method whenPublishingFailsThenResultIsFailed.

@Test
public void whenPublishingFailsThenResultIsFailed() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildDefaultBatch(1);
    mockSuccessfulValidation(eventType);
    mockFailedPublishing();
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getStatus(), equalTo(EventPublishingStatus.FAILED));
    verify(topicRepository, times(1)).syncPostBatch(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) Test(org.junit.Test)

Aggregations

EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)23 Test (org.junit.Test)22 EventType (org.zalando.nakadi.domain.EventType)17 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)17 JSONArray (org.json.JSONArray)15 JSONObject (org.json.JSONObject)8 BatchItemResponse (org.zalando.nakadi.domain.BatchItemResponse)5 ArrayList (java.util.ArrayList)2 BatchItem (org.zalando.nakadi.domain.BatchItem)2 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)2 Supplier (java.util.function.Supplier)1 JSONException (org.json.JSONException)1 NakadiException (org.zalando.nakadi.exceptions.NakadiException)1 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)1 EventTypeMetrics (org.zalando.nakadi.metrics.EventTypeMetrics)1