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());
}
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());
}
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);
}
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));
}
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()));
}
Aggregations