Search in sources :

Example 6 with BatchItemResponse

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

the class EventPublishingControllerTest method responses.

private List<BatchItemResponse> responses(final int number, final EventPublishingStatus status, final EventPublishingStep step) {
    final List<BatchItemResponse> responses = new ArrayList<>();
    for (int i = 0; i < number; i++) {
        final BatchItemResponse response = new BatchItemResponse();
        response.setPublishingStatus(status);
        response.setStep(step);
        responses.add(response);
    }
    return responses;
}
Also used : ArrayList(java.util.ArrayList) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse)

Example 7 with BatchItemResponse

use of org.zalando.nakadi.domain.BatchItemResponse 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)

Aggregations

BatchItemResponse (org.zalando.nakadi.domain.BatchItemResponse)7 JSONArray (org.json.JSONArray)5 Test (org.junit.Test)5 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)5 EventType (org.zalando.nakadi.domain.EventType)5 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)5 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 BatchItem (org.zalando.nakadi.domain.BatchItem)1 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)1