Search in sources :

Example 11 with EventPublishResult

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

the class EventPublishingControllerTest method whenResultIsSubmittedThen200.

@Test
public void whenResultIsSubmittedThen200() throws Exception {
    final EventPublishResult result = new EventPublishResult(SUBMITTED, null, submittedResponses(1));
    Mockito.doReturn(result).when(publisher).publish(any(String.class), eq(TOPIC));
    postBatch(TOPIC, EVENT_BATCH).andExpect(status().isOk()).andExpect(content().string(""));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) Test(org.junit.Test)

Example 12 with EventPublishResult

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

the class EventPublishingControllerTest method whenResultIsAbortedThen422.

@Test
public void whenResultIsAbortedThen422() throws Exception {
    final EventPublishResult result = new EventPublishResult(ABORTED, PARTITIONING, responses());
    Mockito.doReturn(result).when(publisher).publish(any(String.class), eq(TOPIC));
    postBatch(TOPIC, EVENT_BATCH).andExpect(status().isUnprocessableEntity()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(responses())));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) Test(org.junit.Test)

Example 13 with EventPublishResult

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

the class EventPublishingController method postEventInternal.

private ResponseEntity postEventInternal(final String eventTypeName, final String eventsAsString, final NativeWebRequest nativeWebRequest, final EventTypeMetrics eventTypeMetrics, final Client client) throws AccessDeniedException, ServiceTemporarilyUnavailableException {
    final long startingNanos = System.nanoTime();
    try {
        final EventPublishResult result = publisher.publish(eventsAsString, eventTypeName);
        final int eventCount = result.getResponses().size();
        final int totalSizeBytes = eventsAsString.getBytes(Charsets.UTF_8).length;
        reportMetrics(eventTypeMetrics, result, totalSizeBytes, eventCount);
        reportSLOs(startingNanos, totalSizeBytes, eventCount, result, eventTypeName, client);
        return response(result);
    } catch (final JSONException e) {
        LOG.debug("Problem parsing event", e);
        return processJSONException(e, nativeWebRequest);
    } catch (final NoSuchEventTypeException e) {
        LOG.debug("Event type not found.", e);
        return create(e.asProblem(), nativeWebRequest);
    } catch (final NakadiException e) {
        LOG.debug("Failed to publish batch", e);
        return create(e.asProblem(), nativeWebRequest);
    } finally {
        eventTypeMetrics.updateTiming(startingNanos, System.nanoTime());
    }
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONException(org.json.JSONException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) NakadiException(org.zalando.nakadi.exceptions.NakadiException)

Example 14 with EventPublishResult

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

the class EventPublishingControllerTest method whenResultIsAbortedThen207.

@Test
public void whenResultIsAbortedThen207() throws Exception {
    final EventPublishResult result = new EventPublishResult(FAILED, PUBLISHING, responses());
    Mockito.doReturn(result).when(publisher).publish(any(String.class), eq(TOPIC));
    postBatch(TOPIC, EVENT_BATCH).andExpect(status().isMultiStatus()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(responses())));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) Test(org.junit.Test)

Example 15 with EventPublishResult

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

the class EventPublisherTest method whenEventIsOneByteOverMaxSizeThenResultIsAborted.

@Test
public void whenEventIsOneByteOverMaxSizeThenResultIsAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray batch = buildOneByteTooLargeBatch(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)

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