Search in sources :

Example 11 with BatchItem

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

the class MetadataEnrichmentStrategyTest method whenFlowIdIsPresentDoNotOverride.

@Test
public void whenFlowIdIsPresentDoNotOverride() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    event.getJSONObject("metadata").put("flow_id", "something");
    final BatchItem batch = createBatchItem(event);
    FlowIdUtils.push("something-else");
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("flow_id"), equalTo("something"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Example 12 with BatchItem

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

the class MetadataEnrichmentStrategyTest method setFlowId.

@Test
public void setFlowId() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batch = createBatchItem(event);
    assertThat(event.getJSONObject("metadata").optString("flow_id"), isEmptyString());
    final String flowId = randomString();
    FlowIdUtils.push(flowId);
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("flow_id"), equalTo(flowId));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) TestUtils.randomString(org.zalando.nakadi.utils.TestUtils.randomString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 13 with BatchItem

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

the class MetadataEnrichmentStrategyTest method setEventTypeName.

@Test
public void setEventTypeName() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batch = TestUtils.createBatchItem(event);
    assertThat(event.getJSONObject("metadata").optString("event_type"), isEmptyString());
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("event_type"), equalTo(eventType.getName()));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Example 14 with BatchItem

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

the class MetadataEnrichmentStrategyTest method setPartition.

@Test
public void setPartition() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final String partition = randomString();
    final BatchItem batch = createBatchItem(event);
    batch.setPartition(partition);
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("partition"), equalTo(partition));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) TestUtils.randomString(org.zalando.nakadi.utils.TestUtils.randomString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 15 with BatchItem

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

the class MetadataEnrichmentStrategyTest method whenFlowIsNullOverrideIt.

@Test
public void whenFlowIsNullOverrideIt() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    event.getJSONObject("metadata").put("flow_id", (Object) null);
    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));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) TestUtils.randomString(org.zalando.nakadi.utils.TestUtils.randomString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Aggregations

BatchItem (org.zalando.nakadi.domain.BatchItem)23 Test (org.junit.Test)16 EventType (org.zalando.nakadi.domain.EventType)12 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)12 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)11 JSONObject (org.json.JSONObject)10 ArrayList (java.util.ArrayList)8 EventPublishingException (org.zalando.nakadi.exceptions.EventPublishingException)7 PartitionInfo (org.apache.kafka.common.PartitionInfo)6 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 TimeoutException (java.util.concurrent.TimeoutException)3 Collectors (java.util.stream.Collectors)3 Collectors.toList (java.util.stream.Collectors.toList)3 Consumer (org.apache.kafka.clients.consumer.Consumer)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3 Node (org.apache.kafka.common.Node)3 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)3 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)3