Search in sources :

Example 11 with ConnectHeaders

use of org.apache.kafka.connect.header.ConnectHeaders in project apache-kafka-on-k8s by banzaicloud.

the class SourceRecordTest method shouldCreateSinkRecordWithHeaders.

@Test
public void shouldCreateSinkRecordWithHeaders() {
    Headers headers = new ConnectHeaders().addString("h1", "hv1").addBoolean("h2", true);
    record = new SourceRecord(SOURCE_PARTITION, SOURCE_OFFSET, TOPIC_NAME, PARTITION_NUMBER, Schema.STRING_SCHEMA, "key", Schema.BOOLEAN_SCHEMA, false, KAFKA_TIMESTAMP, headers);
    assertNotNull(record.headers());
    assertSame(headers, record.headers());
    assertFalse(record.headers().isEmpty());
}
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.Test)

Example 12 with ConnectHeaders

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

the class WorkerSinkTask method convertHeadersFor.

private Headers convertHeadersFor(ConsumerRecord<byte[], byte[]> record) {
    Headers result = new ConnectHeaders();
    org.apache.kafka.common.header.Headers recordHeaders = record.headers();
    if (recordHeaders != null) {
        String topic = record.topic();
        for (org.apache.kafka.common.header.Header recordHeader : recordHeaders) {
            SchemaAndValue schemaAndValue = headerConverter.toConnectHeader(topic, recordHeader.key(), recordHeader.value());
            result.add(recordHeader.key(), schemaAndValue);
        }
    }
    return result;
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) Headers(org.apache.kafka.connect.header.Headers) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue)

Example 13 with ConnectHeaders

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

the class SinkRecordTest method shouldCreateSinkRecordWithHeaders.

@Test
public void shouldCreateSinkRecordWithHeaders() {
    Headers headers = new ConnectHeaders().addString("h1", "hv1").addBoolean("h2", true);
    record = new SinkRecord(TOPIC_NAME, PARTITION_NUMBER, Schema.STRING_SCHEMA, "key", Schema.BOOLEAN_SCHEMA, false, KAFKA_OFFSET, KAFKA_TIMESTAMP, TS_TYPE, headers);
    assertNotNull(record.headers());
    assertSame(headers, record.headers());
    assertFalse(record.headers().isEmpty());
}
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 14 with ConnectHeaders

use of org.apache.kafka.connect.header.ConnectHeaders 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 15 with ConnectHeaders

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

the class SourceRecordTest method shouldCreateSinkRecordWithHeaders.

@Test
public void shouldCreateSinkRecordWithHeaders() {
    Headers headers = new ConnectHeaders().addString("h1", "hv1").addBoolean("h2", true);
    record = new SourceRecord(SOURCE_PARTITION, SOURCE_OFFSET, TOPIC_NAME, PARTITION_NUMBER, Schema.STRING_SCHEMA, "key", Schema.BOOLEAN_SCHEMA, false, KAFKA_TIMESTAMP, headers);
    assertNotNull(record.headers());
    assertSame(headers, record.headers());
    assertFalse(record.headers().isEmpty());
}
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)

Aggregations

ConnectHeaders (org.apache.kafka.connect.header.ConnectHeaders)20 Headers (org.apache.kafka.connect.header.Headers)14 SourceRecord (org.apache.kafka.connect.source.SourceRecord)10 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)6 SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)3 ArrayList (java.util.ArrayList)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2 RetryWithToleranceOperatorTest (org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest)2 ParameterizedTest (org.apache.kafka.connect.util.ParameterizedTest)2 ThreadedTest (org.apache.kafka.connect.util.ThreadedTest)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Headers (org.apache.kafka.common.header.Headers)1 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)1 StringConverter (org.apache.kafka.connect.storage.StringConverter)1