You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ce...@apache.org on 2023/07/20 14:38:45 UTC

[kafka] branch 3.3 updated: KAFKA-15216: InternalSinkRecord::newRecord should not ignore new headers (#14044)

This is an automated email from the ASF dual-hosted git repository.

cegerton pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.3 by this push:
     new fd4759791f4 KAFKA-15216: InternalSinkRecord::newRecord should not ignore new headers (#14044)
fd4759791f4 is described below

commit fd4759791f49b53111b60f8b39648fcf08521d64
Author: Yash Mayya <ya...@gmail.com>
AuthorDate: Thu Jul 20 15:22:35 2023 +0100

    KAFKA-15216: InternalSinkRecord::newRecord should not ignore new headers (#14044)
    
    Reviewers: Chris Egerton <ch...@aiven.io>
---
 .../org/apache/kafka/connect/sink/SinkRecord.java  |  2 +-
 .../kafka/connect/runtime/InternalSinkRecord.java  |  3 +-
 .../connect/runtime/InternalSinkRecordTest.java    | 44 ++++++++++++++++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/connect/api/src/main/java/org/apache/kafka/connect/sink/SinkRecord.java b/connect/api/src/main/java/org/apache/kafka/connect/sink/SinkRecord.java
index 12c7ee119ab..30799e0b427 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/sink/SinkRecord.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/sink/SinkRecord.java
@@ -65,7 +65,7 @@ public class SinkRecord extends ConnectRecord<SinkRecord> {
     @Override
     public SinkRecord newRecord(String topic, Integer kafkaPartition, Schema keySchema, Object key, Schema valueSchema, Object value,
                                 Long timestamp, Iterable<Header> headers) {
-        return new SinkRecord(topic, kafkaPartition, keySchema, key, valueSchema, value, kafkaOffset(), timestamp, timestampType, headers);
+        return new SinkRecord(topic, kafkaPartition, keySchema, key, valueSchema, value, kafkaOffset, timestamp, timestampType, headers);
     }
 
     @Override
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/InternalSinkRecord.java b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/InternalSinkRecord.java
index 69554ffb306..dadc5727737 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/InternalSinkRecord.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/InternalSinkRecord.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.kafka.connect.runtime;
 
 import org.apache.kafka.clients.consumer.ConsumerRecord;
@@ -52,7 +51,7 @@ public class InternalSinkRecord extends SinkRecord {
                                 Schema valueSchema, Object value, Long timestamp,
                                 Iterable<Header> headers) {
         return new InternalSinkRecord(originalRecord, topic, kafkaPartition, keySchema, key,
-            valueSchema, value, kafkaOffset(), timestamp, timestampType(), headers());
+            valueSchema, value, kafkaOffset(), timestamp, timestampType(), headers);
     }
 
     @Override
diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/InternalSinkRecordTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/InternalSinkRecordTest.java
new file mode 100644
index 00000000000..38798044913
--- /dev/null
+++ b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/InternalSinkRecordTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.kafka.connect.runtime;
+
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.connect.header.Header;
+import org.apache.kafka.connect.sink.SinkRecord;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+public class InternalSinkRecordTest {
+
+    @Test
+    public void testNewRecordHeaders() {
+        SinkRecord sinkRecord = new SinkRecord("test-topic", 0, null, null, null, null, 10);
+        ConsumerRecord<byte[], byte[]> consumerRecord = new ConsumerRecord<>("test-topic", 0, 10, null, null);
+        InternalSinkRecord internalSinkRecord = new InternalSinkRecord(consumerRecord, sinkRecord);
+        assertTrue(internalSinkRecord.headers().isEmpty());
+        assertTrue(sinkRecord.headers().isEmpty());
+
+        SinkRecord newRecord = internalSinkRecord.newRecord("test-topic", 0, null, null, null,
+                null, null, Collections.singletonList(mock(Header.class)));
+        assertEquals(1, newRecord.headers().size());
+    }
+}