This is an automated email from the ASF dual-hosted git repository.
pvillard31 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new ffa7504314c NIFI-16605 Add per-event end attributes to
ConsumeAzureEventHub (#11944)
ffa7504314c is described below
commit ffa7504314c2f07e3a0de2a7899fd23d0c1c41a0
Author: David Handermann <[email protected]>
AuthorDate: Thu Nov 19 04:05:42 2026 -0600
NIFI-16605 Add per-event end attributes to ConsumeAzureEventHub (#11944)
---
.../azure/eventhub/ConsumeAzureEventHub.java | 83 ++++++++++--
.../azure/eventhub/TestConsumeAzureEventHub.java | 140 +++++++++++++++++----
2 files changed, 188 insertions(+), 35 deletions(-)
diff --git
a/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/eventhub/ConsumeAzureEventHub.java
b/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/eventhub/ConsumeAzureEventHub.java
index 35593017424..a28edb3cd81 100644
---
a/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/eventhub/ConsumeAzureEventHub.java
+++
b/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/eventhub/ConsumeAzureEventHub.java
@@ -122,12 +122,54 @@ import static
org.apache.nifi.processors.azure.eventhub.checkpoint.CheckpointSto
"Cluster state is used to store partition ownership and checkpoint
information when component state is configured as the checkpointing strategy.")
@TriggerSerially
@WritesAttributes({
- @WritesAttribute(attribute = "eventhub.enqueued.timestamp",
description = "The time (in milliseconds since epoch, UTC) at which the message
was enqueued in the event hub"),
- @WritesAttribute(attribute = "eventhub.offset", description = "The
offset into the partition at which the message was stored"),
- @WritesAttribute(attribute = "eventhub.sequence", description = "The
sequence number associated with the message"),
- @WritesAttribute(attribute = "eventhub.name", description = "The name
of the event hub from which the message was pulled"),
- @WritesAttribute(attribute = "eventhub.partition", description = "The
name of the partition from which the message was pulled"),
- @WritesAttribute(attribute = "eventhub.property.*", description = "The
application properties of this message. IE: 'application' would be
'eventhub.property.application'")
+ @WritesAttribute(
+ attribute = "eventhub.enqueued.timestamp",
+ description = "ISO-8601 Instant string of the Enqueued
Timestamp for the last event in the partition when the events were received"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.offset",
+ description = "Offset of the last event in the partition when
the events were received"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.sequence",
+ description = "Sequence Number of the last event in the
partition when the events were received"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.start.enqueued.timestamp",
+ description = "ISO-8601 Instant string of the Enqueued
Timestamp for the first event included in the FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.start.offset",
+ description = "Offset of the first event included in the
FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.start.sequence",
+ description = "Sequence Number of the first event included in
the FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.end.enqueued.timestamp",
+ description = "ISO-8601 Instant string of the Enqueued
Timestamp for the last event included in the FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.end.offset",
+ description = "Offset of the last event included in the
FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.event.end.sequence",
+ description = "Sequence Number of the last event included in
the FlowFile"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.name",
+ description = "Name of the Event Hub from which the message
was received"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.partition",
+ description = "Partition Identifier of the Event Hub from
which the message was received"
+ ),
+ @WritesAttribute(
+ attribute = "eventhub.property.*",
+ description = "Application property on the Event received"
+ )
})
public class ConsumeAzureEventHub extends AbstractSessionFactoryProcessor
implements AzureEventHubComponent {
@@ -757,7 +799,8 @@ public class ConsumeAzureEventHub extends
AbstractSessionFactoryProcessor implem
private void putEventHubAttributes(
final Map<String, String> attributes,
final PartitionContext partitionContext,
- final EventData eventData,
+ final EventData firstEventData,
+ final EventData lastEventData,
final LastEnqueuedEventProperties lastEnqueuedEventProperties
) {
if (lastEnqueuedEventProperties != null) {
@@ -766,7 +809,15 @@ public class ConsumeAzureEventHub extends
AbstractSessionFactoryProcessor implem
attributes.put("eventhub.sequence",
String.valueOf(lastEnqueuedEventProperties.getSequenceNumber()));
}
- final Map<String, String> applicationProperties =
AzureEventHubUtils.getApplicationProperties(eventData.getProperties());
+ attributes.put("eventhub.event.start.enqueued.timestamp",
String.valueOf(firstEventData.getEnqueuedTime()));
+ attributes.put("eventhub.event.start.offset",
firstEventData.getOffsetString());
+ attributes.put("eventhub.event.start.sequence",
String.valueOf(firstEventData.getSequenceNumber()));
+
+ attributes.put("eventhub.event.end.enqueued.timestamp",
String.valueOf(lastEventData.getEnqueuedTime()));
+ attributes.put("eventhub.event.end.offset",
lastEventData.getOffsetString());
+ attributes.put("eventhub.event.end.sequence",
String.valueOf(lastEventData.getSequenceNumber()));
+
+ final Map<String, String> applicationProperties =
AzureEventHubUtils.getApplicationProperties(lastEventData.getProperties());
attributes.putAll(applicationProperties);
attributes.put("eventhub.name", partitionContext.getEventHubName());
@@ -782,7 +833,7 @@ public class ConsumeAzureEventHub extends
AbstractSessionFactoryProcessor implem
final List<EventData> events = eventBatchContext.getEvents();
events.forEach(eventData -> {
final Map<String, String> attributes = new HashMap<>();
- putEventHubAttributes(attributes, partitionContext, eventData,
eventBatchContext.getLastEnqueuedEventProperties());
+ putEventHubAttributes(attributes, partitionContext, eventData,
eventData, eventBatchContext.getLastEnqueuedEventProperties());
FlowFile flowFile = session.create();
flowFile = session.putAllAttributes(flowFile, attributes);
@@ -815,6 +866,13 @@ public class ConsumeAzureEventHub extends
AbstractSessionFactoryProcessor implem
final LastEnqueuedEventProperties lastEnqueuedEventProperties =
eventBatchContext.getLastEnqueuedEventProperties();
final List<EventData> events = eventBatchContext.getEvents();
+ final EventData firstEventData;
+ if (events.isEmpty()) {
+ firstEventData = null;
+ } else {
+ firstEventData = events.getFirst();
+ }
+
try (final OutputStream out = session.write(flowFile)) {
for (final EventData eventData : events) {
final byte[] eventDataBytes = eventData.getBody();
@@ -843,14 +901,15 @@ public class ConsumeAzureEventHub extends
AbstractSessionFactoryProcessor implem
logger.error("Failed to parse message from Azure Event Hub
using configured Record Reader and Writer", e);
FlowFile failed = session.create();
session.write(failed, o -> o.write(eventData.getBody()));
- putEventHubAttributes(attributes, partitionContext,
eventData, lastEnqueuedEventProperties);
- failed = session.putAllAttributes(failed, attributes);
+ final Map<String, String> failureAttributes = new
HashMap<>();
+ putEventHubAttributes(failureAttributes, partitionContext,
firstEventData, eventData, lastEnqueuedEventProperties);
+ failed = session.putAllAttributes(failed,
failureAttributes);
transferTo(REL_PARSE_FAILURE, session, stopWatch,
partitionContext, failed);
}
}
if (lastEventData != null) {
- putEventHubAttributes(attributes, partitionContext,
lastEventData, lastEnqueuedEventProperties);
+ putEventHubAttributes(attributes, partitionContext,
firstEventData, lastEventData, lastEnqueuedEventProperties);
attributes.put("record.count", String.valueOf(recordCount));
if (writer != null) {
diff --git
a/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java
b/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java
index d3df351b258..6a9bc7d562c 100644
---
a/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java
+++
b/nifi-extension-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java
@@ -21,6 +21,7 @@ import com.azure.messaging.eventhubs.EventData;
import com.azure.messaging.eventhubs.EventProcessorClient;
import com.azure.messaging.eventhubs.models.Checkpoint;
import com.azure.messaging.eventhubs.models.EventBatchContext;
+import com.azure.messaging.eventhubs.models.LastEnqueuedEventProperties;
import com.azure.messaging.eventhubs.models.PartitionContext;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.flowfile.FlowFile;
@@ -68,6 +69,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.Proxy;
import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -104,8 +107,30 @@ public class TestConsumeAzureEventHub {
private static final String SECOND_CONTENT = "CONTENT-2";
private static final String THIRD_CONTENT = "CONTENT-3";
private static final String FOURTH_CONTENT = "CONTENT-4";
+ private static final String PROPERTY_ATTRIBUTE_NAME_FORMAT =
"eventhub.property.%s";
private static final String APPLICATION_PROPERTY = "application";
- private static final String APPLICATION_ATTRIBUTE_NAME =
String.format("eventhub.property.%s", APPLICATION_PROPERTY);
+ private static final String APPLICATION_ATTRIBUTE_NAME =
String.format(PROPERTY_ATTRIBUTE_NAME_FORMAT, APPLICATION_PROPERTY);
+ private static final String FAILED_EVENT_PROPERTY = "failed";
+ private static final String FAILED_EVENT_ATTRIBUTE_NAME =
String.format(PROPERTY_ATTRIBUTE_NAME_FORMAT, FAILED_EVENT_PROPERTY);
+ private static final String ENQUEUED_TIMESTAMP_ATTRIBUTE =
"eventhub.enqueued.timestamp";
+ private static final String OFFSET_ATTRIBUTE = "eventhub.offset";
+ private static final String SEQUENCE_ATTRIBUTE = "eventhub.sequence";
+
+ private static final String START_ENQUEUED_TIMESTAMP_ATTRIBUTE =
"eventhub.event.start.enqueued.timestamp";
+ private static final String START_OFFSET_ATTRIBUTE =
"eventhub.event.start.offset";
+ private static final String START_SEQUENCE_ATTRIBUTE =
"eventhub.event.start.sequence";
+ private static final String END_ENQUEUED_TIMESTAMP_ATTRIBUTE =
"eventhub.event.end.enqueued.timestamp";
+ private static final String END_OFFSET_ATTRIBUTE =
"eventhub.event.end.offset";
+ private static final String END_SEQUENCE_ATTRIBUTE =
"eventhub.event.end.sequence";
+
+ private static final long FIRST_SEQUENCE_NUMBER = 1;
+ private static final long OFFSET_INCREMENT = 256;
+ private static final Instant ENQUEUED_TIME_BASE =
Instant.parse("2026-11-18T12:00:00Z");
+ private static final long LAST_ENQUEUED_SEQUENCE_NUMBER = 128;
+ private static final String LAST_ENQUEUED_OFFSET = "32768";
+ private static final Instant LAST_ENQUEUED_TIME =
Instant.parse("2026-11-18T13:00:00Z");
+ private static final LastEnqueuedEventProperties
LAST_ENQUEUED_EVENT_PROPERTIES =
+ new LastEnqueuedEventProperties(LAST_ENQUEUED_SEQUENCE_NUMBER,
LAST_ENQUEUED_OFFSET, LAST_ENQUEUED_TIME, LAST_ENQUEUED_TIME);
private static final String EVENT_HUB_OAUTH_SERVICE_ID = "eventHubOauth";
private static final String EVENT_HUB_IDENTITY_SERVICE_ID =
"eventHubIdentity";
private static final String BLOB_OAUTH_SERVICE_ID = "blobOauth";
@@ -324,14 +349,14 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
final List<EventData> events = getEvents(FIRST_CONTENT);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
assertEquals(1, flowFiles.size());
final MockFlowFile flowFile = flowFiles.getFirst();
flowFile.assertContentEquals(FIRST_CONTENT);
- assertEventHubAttributesFound(flowFile);
+ assertEventHubAttributesFound(flowFile, events.getFirst(),
events.getFirst());
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(1, provenanceEvents.size());
@@ -346,15 +371,17 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
final List<EventData> events = getEvents(FIRST_CONTENT,
SECOND_CONTENT);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
assertEquals(2, flowFiles.size());
- final MockFlowFile msg1 = flowFiles.get(0);
+ final MockFlowFile msg1 = flowFiles.getFirst();
msg1.assertContentEquals(FIRST_CONTENT);
+ assertEventHubAttributesFound(msg1, events.getFirst(),
events.getFirst());
final MockFlowFile msg2 = flowFiles.get(1);
msg2.assertContentEquals(SECOND_CONTENT);
+ assertEventHubAttributesFound(msg2, events.get(1), events.get(1));
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(2, provenanceEvents.size());
@@ -370,14 +397,14 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
assertEquals(1, flowFiles.size());
final MockFlowFile ff1 = flowFiles.getFirst();
ff1.assertContentEquals(FIRST_CONTENT + SECOND_CONTENT);
- assertEventHubAttributesFound(ff1);
+ assertEventHubAttributesFound(ff1, events.getFirst(),
events.getLast());
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(1, provenanceEvents.size());
@@ -396,20 +423,20 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
assertEquals(1, flowFiles.size());
final MockFlowFile ff1 = flowFiles.getFirst();
ff1.assertContentEquals(FIRST_CONTENT + SECOND_CONTENT +
FOURTH_CONTENT);
- assertEventHubAttributesFound(ff1);
+ assertEventHubAttributesFound(ff1, events.getFirst(),
events.getLast());
final List<MockFlowFile> failedFFs =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_PARSE_FAILURE);
assertEquals(1, failedFFs.size());
final MockFlowFile failed1 = failedFFs.getFirst();
failed1.assertContentEquals(THIRD_CONTENT);
- assertEventHubAttributesFound(failed1);
+ assertEventHubAttributesFound(failed1, events.getFirst(),
events.get(2));
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(2, provenanceEvents.size());
@@ -433,7 +460,7 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
@@ -443,7 +470,7 @@ public class TestConsumeAzureEventHub {
assertEquals(1, failedFFs.size());
final MockFlowFile failed1 = failedFFs.getFirst();
failed1.assertContentEquals(FIRST_CONTENT);
- assertEventHubAttributesFound(failed1);
+ assertEventHubAttributesFound(failed1, events.getFirst(),
events.getFirst());
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(1, provenanceEvents.size());
@@ -463,20 +490,20 @@ public class TestConsumeAzureEventHub {
testRunner.run(1, false);
- final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore, null);
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
processor.eventBatchProcessor.accept(eventBatchContext);
final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
assertEquals(1, flowFiles.size());
final MockFlowFile ff1 = flowFiles.getFirst();
ff1.assertContentEquals(FIRST_CONTENT + THIRD_CONTENT +
FOURTH_CONTENT);
- assertEventHubAttributesFound(ff1);
+ assertEventHubAttributesFound(ff1, events.getFirst(),
events.getLast());
final List<MockFlowFile> failedFFs =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_PARSE_FAILURE);
assertEquals(1, failedFFs.size());
final MockFlowFile failed1 = failedFFs.getFirst();
failed1.assertContentEquals(SECOND_CONTENT);
- assertEventHubAttributesFound(failed1);
+ assertEventHubAttributesFound(failed1, events.getFirst(),
events.get(1));
final List<ProvenanceEventRecord> provenanceEvents =
testRunner.getProvenanceEvents();
assertEquals(2, provenanceEvents.size());
@@ -490,6 +517,36 @@ public class TestConsumeAzureEventHub {
assertEquals(EXPECTED_TRANSIT_URI, provenanceEvent2.getTransitUri());
}
+ @Test
+ public void testReceiveRecordWriterFailureLastEvent() throws Exception {
+ setProperties();
+
+ final List<EventData> events = getEvents(FIRST_CONTENT,
SECOND_CONTENT);
+ final EventData failedEvent = events.getLast();
+ failedEvent.getProperties().put(FAILED_EVENT_PROPERTY, SECOND_CONTENT);
+ setupRecordReader(events, -1, SECOND_CONTENT);
+ setupRecordWriter(SECOND_CONTENT);
+
+ testRunner.run(1, false);
+
+ final EventBatchContext eventBatchContext = new
EventBatchContext(partitionContext, events, checkpointStore,
LAST_ENQUEUED_EVENT_PROPERTIES);
+ processor.eventBatchProcessor.accept(eventBatchContext);
+
+ final List<MockFlowFile> flowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_SUCCESS);
+ assertEquals(1, flowFiles.size());
+ final MockFlowFile flowFile = flowFiles.getFirst();
+ flowFile.assertContentEquals(FIRST_CONTENT);
+ assertEventHubAttributesFound(flowFile, events.getFirst(),
events.getFirst());
+ flowFile.assertAttributeNotExists(FAILED_EVENT_ATTRIBUTE_NAME);
+
+ final List<MockFlowFile> failedFlowFiles =
testRunner.getFlowFilesForRelationship(ConsumeAzureEventHub.REL_PARSE_FAILURE);
+ assertEquals(1, failedFlowFiles.size());
+ final MockFlowFile failedFlowFile = failedFlowFiles.getFirst();
+ failedFlowFile.assertContentEquals(SECOND_CONTENT);
+ assertEventHubAttributesFound(failedFlowFile, events.getFirst(),
failedEvent);
+ failedFlowFile.assertAttributeEquals(FAILED_EVENT_ATTRIBUTE_NAME,
SECOND_CONTENT);
+ }
+
@Test
void testMigration() {
TestRunner testRunner =
TestRunners.newTestRunner(ConsumeAzureEventHub.class);
@@ -664,20 +721,33 @@ public class TestConsumeAzureEventHub {
}
}
- private void assertEventHubAttributesFound(final MockFlowFile flowFile) {
+ private void assertEventHubAttributesFound(final MockFlowFile flowFile,
final EventData startEvent, final EventData endEvent) {
flowFile.assertAttributeEquals("eventhub.name", EVENT_HUB_NAME);
flowFile.assertAttributeEquals("eventhub.partition", PARTITION_ID);
flowFile.assertAttributeEquals(APPLICATION_ATTRIBUTE_NAME,
MockConsumeAzureEventHub.class.getSimpleName());
+
+ flowFile.assertAttributeEquals(ENQUEUED_TIMESTAMP_ATTRIBUTE,
LAST_ENQUEUED_TIME.toString());
+ flowFile.assertAttributeEquals(OFFSET_ATTRIBUTE, LAST_ENQUEUED_OFFSET);
+ flowFile.assertAttributeEquals(SEQUENCE_ATTRIBUTE,
Long.toString(LAST_ENQUEUED_SEQUENCE_NUMBER));
+
+ flowFile.assertAttributeEquals(START_ENQUEUED_TIMESTAMP_ATTRIBUTE,
startEvent.getEnqueuedTime().toString());
+ flowFile.assertAttributeEquals(START_OFFSET_ATTRIBUTE,
startEvent.getOffsetString());
+ flowFile.assertAttributeEquals(START_SEQUENCE_ATTRIBUTE,
startEvent.getSequenceNumber().toString());
+
+ flowFile.assertAttributeEquals(END_ENQUEUED_TIMESTAMP_ATTRIBUTE,
endEvent.getEnqueuedTime().toString());
+ flowFile.assertAttributeEquals(END_OFFSET_ATTRIBUTE,
endEvent.getOffsetString());
+ flowFile.assertAttributeEquals(END_SEQUENCE_ATTRIBUTE,
endEvent.getSequenceNumber().toString());
}
private List<EventData> getEvents(final String... contents) {
- return Arrays.stream(contents)
- .map(content -> {
- final EventData eventData = new EventData(content);
- eventData.getProperties().put(APPLICATION_PROPERTY,
MockConsumeAzureEventHub.class.getSimpleName());
- return eventData;
- })
- .collect(Collectors.toList());
+ final List<EventData> events = new ArrayList<>();
+ for (int i = 0; i < contents.length; i++) {
+ final EventData eventData = new MockEventData(contents[i],
FIRST_SEQUENCE_NUMBER + i);
+ eventData.getProperties().put(APPLICATION_PROPERTY,
MockConsumeAzureEventHub.class.getSimpleName());
+ events.add(eventData);
+ }
+
+ return events;
}
private void configureProxyControllerService() throws
InitializationException {
@@ -732,6 +802,30 @@ public class TestConsumeAzureEventHub {
}
}
+ private static class MockEventData extends EventData {
+ private final long sequenceNumber;
+
+ private MockEventData(final String content, final long sequenceNumber)
{
+ super(content);
+ this.sequenceNumber = sequenceNumber;
+ }
+
+ @Override
+ public Long getSequenceNumber() {
+ return sequenceNumber;
+ }
+
+ @Override
+ public String getOffsetString() {
+ return Long.toString(sequenceNumber * OFFSET_INCREMENT);
+ }
+
+ @Override
+ public Instant getEnqueuedTime() {
+ return ENQUEUED_TIME_BASE.plusSeconds(sequenceNumber);
+ }
+ }
+
private static class MockOAuth2AccessTokenProvider extends
AbstractControllerService implements OAuth2AccessTokenProvider {
@Override
public AccessToken getAccessDetails() {