awelless commented on code in PR #11899:
URL: https://github.com/apache/nifi/pull/11899#discussion_r4527413401


##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/ConsumeKafkaDemarcatorTombstoneIT.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.kafka.processors;
+
+import org.apache.nifi.kafka.processors.consumer.ProcessingStrategy;
+import org.apache.nifi.kafka.service.api.consumer.AutoOffsetReset;
+import org.apache.nifi.kafka.shared.attribute.KafkaFlowFileAttribute;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Demarcator output when a batch contains a null tombstone, a non-null empty 
value, or both together with a real value.

Review Comment:
   Nit: the verb is missing, so I had some troubles understanding the sentence.
   ```suggestion
    * Verifies DEMARCATOR output when a batch contains a null tombstone, a 
non-null empty value, or both together with a real value.
   ```



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-3-integration/src/test/java/org/apache/nifi/kafka/processors/ConsumeKafkaTombstoneIT.java:
##########
@@ -107,4 +109,34 @@ void testProcessingStrategyFlowFileOneRecord() throws 
InterruptedException, Exec
         flowFile.assertAttributeNotExists("aaa");
         flowFile.assertAttributeNotExists("ccc");
     }
+
+    @Test
+    void testProcessingStrategyFlowFileEmptyRecord() throws 
InterruptedException, ExecutionException {
+        final String topic = UUID.randomUUID().toString();
+        final String groupId = topic.substring(0, topic.indexOf("-"));
+
+        runner.setProperty(ConsumeKafka.GROUP_ID, groupId);
+        runner.setProperty(ConsumeKafka.TOPICS, topic);
+        runner.setProperty(ConsumeKafka.PROCESSING_STRATEGY, 
ProcessingStrategy.FLOW_FILE.getValue());
+
+        runner.run(1, false, true);
+
+        produceBytes(topic, FIRST_PARTITION, "key-record", EMPTY_BYTES);
+        while 
(runner.getFlowFilesForRelationship(ConsumeKafka.SUCCESS).isEmpty()) {

Review Comment:
   Let's use `runUntil` method to stop execution if the condition is never met.



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-processors/src/test/java/org/apache/nifi/kafka/processors/consumer/convert/FlowFileStreamKafkaMessageConverterTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.kafka.processors.consumer.convert;
+
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.kafka.processors.ConsumeKafka;
+import org.apache.nifi.kafka.processors.consumer.OffsetTracker;
+import org.apache.nifi.kafka.service.api.record.ByteRecord;
+import org.apache.nifi.kafka.shared.attribute.KafkaFlowFileAttribute;
+import org.apache.nifi.kafka.shared.property.KeyEncoding;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.io.OutputStreamCallback;
+import org.apache.nifi.util.MockFlowFile;
+import org.junit.jupiter.api.Test;
+import org.mockito.Answers;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
+
+class FlowFileStreamKafkaMessageConverterTest {
+
+    private static final String TOPIC = "topic";
+    private static final String BROKER_URI = "brokerUri";
+    private static final byte[] NON_EMPTY_VALUE = 
"payload".getBytes(StandardCharsets.UTF_8);
+
+    @Test
+    void testTombstoneAttributeSetOnlyForTombstoneRecords() {
+        final ProcessSession session = mock(ProcessSession.class, 
withSettings().defaultAnswer(Answers.RETURNS_DEEP_STUBS));
+        final FlowFile tombstoneFlowFile = new MockFlowFile(1);
+        final FlowFile emptyFlowFile = new MockFlowFile(2);
+        final FlowFile valueFlowFile = new MockFlowFile(3);
+        when(session.create()).thenReturn(tombstoneFlowFile, emptyFlowFile, 
valueFlowFile);
+        when(session.putAttribute(any(FlowFile.class), any(), 
any())).thenAnswer(invocation -> invocation.getArgument(0));
+        when(session.putAllAttributes(any(FlowFile.class), 
any())).thenAnswer(invocation -> invocation.getArgument(0));
+        when(session.write(any(FlowFile.class), 
any(OutputStreamCallback.class))).thenAnswer(invocation -> 
invocation.getArgument(0));

Review Comment:
   I suggest using `MockProcessSession` instead of handcrafted mocks.



##########
nifi-extension-bundles/nifi-kafka-bundle/nifi-kafka-processors/src/main/java/org/apache/nifi/kafka/processors/consumer/bundle/ByteRecordBundler.java:
##########
@@ -65,8 +65,11 @@ private ByteRecord toByteRecord(final BundleKey key, final 
BundleValue value) {
         final TopicPartitionSummary topicPartition = key.getTopicPartition();
         key.headers.add(new 
RecordHeader(KafkaFlowFileAttribute.KAFKA_MAX_OFFSET, 
Long.toString(value.getLastOffset()).getBytes(StandardCharsets.UTF_8)));
         key.headers.add(new RecordHeader(KafkaFlowFileAttribute.KAFKA_COUNT, 
Long.toString(value.getCount()).getBytes(StandardCharsets.UTF_8)));
+        final byte[] data = value.getData();
+        // Demarcator emits one FlowFile per bundle, so an empty bundle is 
still reported as a tombstone.
+        final boolean tombstone = data.length == 0;

Review Comment:
   Nit: let's mention that this is done for compatibility. It's hard to tell 
why we check for empty content from the code alone.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to