Search in sources :

Example 6 with EventPublishResult

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

the class EventPublisherTest method whenEventHasEidThenSetItInTheResponse.

@Test
public void whenEventHasEidThenSetItInTheResponse() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final JSONArray batch = new JSONArray(Arrays.asList(event));
    mockSuccessfulValidation(eventType);
    final EventPublishResult result = publisher.publish(batch.toString(), eventType.getName());
    assertThat(result.getResponses().get(0).getEid(), equalTo(event.getJSONObject("metadata").optString("eid")));
    verify(topicRepository, times(1)).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 7 with EventPublishResult

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

the class EventPublisherTest method whenPartitionFailsThenSubsequentItemsAreAborted.

@Test
public void whenPartitionFailsThenSubsequentItemsAreAborted() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONArray array = buildDefaultBatch(2);
    final List<BatchItem> batch = new ArrayList<>();
    batch.add(createBatchItem(array.getJSONObject(0)));
    batch.add(createBatchItem(array.getJSONObject(1)));
    mockSuccessfulValidation(eventType);
    mockFaultPartition();
    final EventPublishResult result = publisher.publish(createStringFromBatchItems(batch), 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.PARTITIONING));
    assertThat(first.getDetail(), equalTo("partition error"));
    final BatchItemResponse second = result.getResponses().get(1);
    assertThat(second.getPublishingStatus(), equalTo(EventPublishingStatus.ABORTED));
    assertThat(second.getStep(), equalTo(EventPublishingStep.VALIDATING));
    assertThat(second.getDetail(), is(isEmptyString()));
    verify(cache, times(2)).getValidator(any());
    verify(partitionResolver, times(1)).resolvePartition(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) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) ArrayList(java.util.ArrayList) BatchItemResponse(org.zalando.nakadi.domain.BatchItemResponse) Test(org.junit.Test)

Example 8 with EventPublishResult

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

the class EventPublisherTest method testWrite.

@Test
public void testWrite() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().build();
    Mockito.when(cache.getEventType(eventType.getName())).thenReturn(eventType);
    mockSuccessfulValidation(eventType);
    final EventPublishResult result = publisher.publish(buildDefaultBatch(0).toString(), eventType.getName());
    Assert.assertEquals(result.getStatus(), EventPublishingStatus.SUBMITTED);
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 9 with EventPublishResult

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

the class EventPublishingControllerTest method publishedEventsAreReportedPerEventType.

@Test
public void publishedEventsAreReportedPerEventType() throws Exception {
    final EventPublishResult success = new EventPublishResult(SUBMITTED, null, submittedResponses(3));
    Mockito.doReturn(success).doReturn(success).doThrow(InternalNakadiException.class).when(publisher).publish(any(), any());
    postBatch(TOPIC, EVENT_BATCH);
    postBatch(TOPIC, EVENT_BATCH);
    postBatch(TOPIC, EVENT_BATCH);
    final EventTypeMetrics eventTypeMetrics = eventTypeMetricRegistry.metricsFor(TOPIC);
    assertThat(eventTypeMetrics.getResponseCount(200), equalTo(2L));
    assertThat(eventTypeMetrics.getResponseCount(500), equalTo(1L));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) EventTypeMetrics(org.zalando.nakadi.metrics.EventTypeMetrics) Test(org.junit.Test)

Example 10 with EventPublishResult

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

the class EventPublishingControllerTest method publishedEventsKPIReported.

@Test
public void publishedEventsKPIReported() throws Exception {
    final EventPublishResult success = new EventPublishResult(SUBMITTED, null, submittedResponses(3));
    Mockito.doReturn(success).doReturn(success).doThrow(InternalNakadiException.class).when(publisher).publish(any(), any());
    when(kpiPublisher.hash(any())).thenReturn("hashed-application-name");
    postBatch(TOPIC, EVENT_BATCH);
    final ArgumentCaptor<String> etNameCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Supplier> eventGeneratorCaptor = ArgumentCaptor.forClass(Supplier.class);
    verify(kpiPublisher, times(1)).publish(etNameCaptor.capture(), eventGeneratorCaptor.capture());
    assertThat(etNameCaptor.getValue(), equalTo("kpiEventTypeName"));
    final JSONObject kpi = (JSONObject) eventGeneratorCaptor.getValue().get();
    assertThat(kpi, is(sameJSONObjectAs(new JSONObject().put("app", "adminClientId").put("app_hashed", "hashed-application-name").put("event_type", "my-topic").put("batch_size", 33).put("number_of_events", 3)).allowingExtraUnexpectedFields()));
    assertThat(kpi.getInt("ms_spent"), is(notNullValue()));
}
Also used : EventPublishResult(org.zalando.nakadi.domain.EventPublishResult) JSONObject(org.json.JSONObject) Supplier(java.util.function.Supplier) 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