use of org.zalando.nakadi.domain.BatchItem in project nakadi by zalando.
the class EventPublisherTest method whenPartitionFailsThenResultIsAborted.
@Test
public void whenPartitionFailsThenResultIsAborted() throws Exception {
final EventType eventType = buildDefaultEventType();
final List<BatchItem> batch = new ArrayList<>();
batch.add(createBatchItem(buildDefaultBatch(1).getJSONObject(0)));
final JSONObject event = batch.get(0).getEvent();
mockSuccessfulValidation(eventType);
mockFaultPartition();
final EventPublishResult result = publisher.publish(createStringFromBatchItems(batch), eventType.getName());
assertThat(result.getStatus(), equalTo(EventPublishingStatus.ABORTED));
}
use of org.zalando.nakadi.domain.BatchItem 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.BatchItem in project nakadi by zalando.
the class EnrichmentTest method enrichAppliesStrategies.
@Test
public void enrichAppliesStrategies() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.getEnrichmentStrategies().add(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT);
final JSONObject event = new JSONObject();
final BatchItem batchItem = createBatchItem(event);
final EnrichmentStrategy strategy = mock(EnrichmentStrategy.class);
Mockito.doReturn(strategy).when(registry).getStrategy(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT);
enrichment.enrich(batchItem, eventType);
verify(strategy, times(1)).enrich(batchItem, eventType);
}
use of org.zalando.nakadi.domain.BatchItem in project nakadi by zalando.
the class KafkaTopicRepositoryTest method whenPostEventTimesOutThenUpdateItemStatus.
@Test
public void whenPostEventTimesOutThenUpdateItemStatus() throws Exception {
final BatchItem item = new BatchItem("{}", BatchItem.EmptyInjectionConfiguration.build(1, true), new BatchItem.InjectionConfiguration[BatchItem.Injection.values().length], Collections.emptyList());
item.setPartition("1");
final List<BatchItem> batch = new ArrayList<>();
batch.add(item);
when(kafkaProducer.partitionsFor(EXPECTED_PRODUCER_RECORD.topic())).thenReturn(ImmutableList.of(new PartitionInfo(EXPECTED_PRODUCER_RECORD.topic(), 1, new Node(1, "host", 9091), null, null)));
when(nakadiSettings.getKafkaSendTimeoutMs()).thenReturn((long) 100);
Mockito.doReturn(mock(Future.class)).when(kafkaProducer).send(any(), any());
try {
kafkaTopicRepository.syncPostBatch(EXPECTED_PRODUCER_RECORD.topic(), batch);
fail();
} catch (final EventPublishingException e) {
assertThat(item.getResponse().getPublishingStatus(), equalTo(EventPublishingStatus.FAILED));
assertThat(item.getResponse().getDetail(), equalTo("timed out"));
}
}
use of org.zalando.nakadi.domain.BatchItem in project nakadi by zalando.
the class MetadataEnrichmentStrategyTest method whenFlowIsEmptyStringOverrideIt.
@Test
public void whenFlowIsEmptyStringOverrideIt() throws Exception {
final EventType eventType = buildDefaultEventType();
final JSONObject event = buildBusinessEvent();
event.getJSONObject("metadata").put("flow_id", "");
final BatchItem batch = createBatchItem(event);
final String flowId = randomString();
FlowIdUtils.push(flowId);
strategy.enrich(batch, eventType);
assertThat(batch.getEvent().getJSONObject("metadata").getString("flow_id"), equalTo(flowId));
}
Aggregations