Search in sources :

Example 16 with ConnectHeaders

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

the class HeaderFromTest method schemaless.

@ParameterizedTest
@MethodSource("data")
public void schemaless(String description, boolean keyTransform, RecordBuilder originalBuilder, List<String> transformFields, List<String> headers1, HeaderFrom.Operation operation, RecordBuilder expectedBuilder) {
    HeaderFrom<SourceRecord> xform = keyTransform ? new HeaderFrom.Key<>() : new HeaderFrom.Value<>();
    xform.configure(config(headers1, transformFields, operation));
    ConnectHeaders headers = new ConnectHeaders();
    headers.addString("existing", "existing-value");
    SourceRecord originalRecord = originalBuilder.schemaless(keyTransform);
    SourceRecord expectedRecord = expectedBuilder.schemaless(keyTransform);
    SourceRecord xformed = xform.apply(originalRecord);
    assertSameRecord(expectedRecord, xformed);
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) SourceRecord(org.apache.kafka.connect.source.SourceRecord) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with ConnectHeaders

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

the class DropHeadersTest method dropNonExistingHeader.

@Test
public void dropNonExistingHeader() {
    xform.configure(config("to-drop"));
    ConnectHeaders expected = new ConnectHeaders();
    expected.addString("existing", "existing-value");
    ConnectHeaders headers = expected.duplicate();
    SourceRecord original = sourceRecord(headers);
    SourceRecord xformed = xform.apply(original);
    assertNonHeaders(original, xformed);
    assertEquals(expected, xformed.headers());
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 18 with ConnectHeaders

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

Example 19 with ConnectHeaders

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

the class DropHeadersTest method dropExistingHeader.

@Test
public void dropExistingHeader() {
    xform.configure(config("to-drop"));
    ConnectHeaders expected = new ConnectHeaders();
    expected.addString("existing", "existing-value");
    ConnectHeaders headers = expected.duplicate();
    headers.addString("to-drop", "existing-value");
    SourceRecord original = sourceRecord(headers);
    SourceRecord xformed = xform.apply(original);
    assertNonHeaders(original, xformed);
    assertEquals(expected, xformed.headers());
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 20 with ConnectHeaders

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

the class DropHeadersTest method dropExistingHeaderWithMultipleValues.

@Test
public void dropExistingHeaderWithMultipleValues() {
    xform.configure(config("to-drop"));
    ConnectHeaders expected = new ConnectHeaders();
    expected.addString("existing", "existing-value");
    ConnectHeaders headers = expected.duplicate();
    headers.addString("to-drop", "existing-value");
    headers.addString("to-drop", "existing-other-value");
    SourceRecord original = sourceRecord(headers);
    SourceRecord xformed = xform.apply(original);
    assertNonHeaders(original, xformed);
    assertEquals(expected, xformed.headers());
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) SourceRecord(org.apache.kafka.connect.source.SourceRecord) 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