Search in sources :

Example 21 with Headers

use of org.apache.kafka.connect.header.Headers in project kafka by apache.

the class SinkRecordTest method shouldDuplicateRecordUsingNewHeaders.

@Test
public void shouldDuplicateRecordUsingNewHeaders() {
    Headers newHeaders = new ConnectHeaders().addString("h3", "hv3");
    SinkRecord duplicate = record.newRecord(TOPIC_NAME, PARTITION_NUMBER, Schema.STRING_SCHEMA, "key", Schema.BOOLEAN_SCHEMA, false, KAFKA_TIMESTAMP, newHeaders);
    assertEquals(TOPIC_NAME, duplicate.topic());
    assertEquals(PARTITION_NUMBER, duplicate.kafkaPartition());
    assertEquals(Schema.STRING_SCHEMA, duplicate.keySchema());
    assertEquals("key", duplicate.key());
    assertEquals(Schema.BOOLEAN_SCHEMA, duplicate.valueSchema());
    assertEquals(false, duplicate.value());
    assertEquals(KAFKA_OFFSET, duplicate.kafkaOffset());
    assertEquals(KAFKA_TIMESTAMP, duplicate.timestamp());
    assertEquals(TS_TYPE, duplicate.timestampType());
    assertNotNull(duplicate.headers());
    assertEquals(newHeaders, duplicate.headers());
    assertSame(newHeaders, duplicate.headers());
    assertNotSame(record.headers(), duplicate.headers());
    assertNotEquals(record.headers(), duplicate.headers());
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) Headers(org.apache.kafka.connect.header.Headers) Test(org.junit.jupiter.api.Test)

Example 22 with Headers

use of org.apache.kafka.connect.header.Headers in project kafka by apache.

the class InsertHeaderTest method insertionWithByteHeader.

@Test
public void insertionWithByteHeader() {
    xform.configure(config("inserted", "1"));
    ConnectHeaders headers = new ConnectHeaders();
    headers.addString("existing", "existing-value");
    Headers expect = headers.duplicate().addByte("inserted", (byte) 1);
    SourceRecord original = sourceRecord(headers);
    SourceRecord xformed = xform.apply(original);
    assertNonHeaders(original, xformed);
    assertEquals(expect, xformed.headers());
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) Headers(org.apache.kafka.connect.header.Headers) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Aggregations

Headers (org.apache.kafka.connect.header.Headers)22 ConnectHeaders (org.apache.kafka.connect.header.ConnectHeaders)17 Test (org.junit.jupiter.api.Test)7 SourceRecord (org.apache.kafka.connect.source.SourceRecord)5 SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)4 Test (org.junit.Test)4 TopicPartition (org.apache.kafka.common.TopicPartition)2 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)2 Header (org.apache.kafka.connect.header.Header)2 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)2 HashMap (java.util.HashMap)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 Field (org.apache.kafka.connect.data.Field)1 Schema (org.apache.kafka.connect.data.Schema)1 Struct (org.apache.kafka.connect.data.Struct)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1