use of org.apache.kafka.connect.header.ConnectHeaders in project kafka by apache.
the class HeaderFromTest method withSchema.
@ParameterizedTest
@MethodSource("data")
public void withSchema(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");
Headers expect = headers.duplicate();
for (int i = 0; i < headers1.size(); i++) {
expect.add(headers1.get(i), originalBuilder.fieldValues.get(i), originalBuilder.fieldSchemas.get(i));
}
SourceRecord originalRecord = originalBuilder.withSchema(keyTransform);
SourceRecord expectedRecord = expectedBuilder.withSchema(keyTransform);
SourceRecord xformed = xform.apply(originalRecord);
assertSameRecord(expectedRecord, xformed);
}
use of org.apache.kafka.connect.header.ConnectHeaders in project kafka by apache.
the class InsertHeaderTest method insertionWithExistingSameHeader.
@Test
public void insertionWithExistingSameHeader() {
xform.configure(config("existing", "inserted-value"));
ConnectHeaders headers = new ConnectHeaders();
headers.addString("existing", "preexisting-value");
Headers expect = headers.duplicate().addString("existing", "inserted-value");
SourceRecord original = sourceRecord(headers);
SourceRecord xformed = xform.apply(original);
assertNonHeaders(original, xformed);
assertEquals(expect, xformed.headers());
}
use of org.apache.kafka.connect.header.ConnectHeaders in project kafka by apache.
the class InsertHeaderTest method insertionWithExistingOtherHeader.
@Test
public void insertionWithExistingOtherHeader() {
xform.configure(config("inserted", "inserted-value"));
ConnectHeaders headers = new ConnectHeaders();
headers.addString("existing", "existing-value");
Headers expect = headers.duplicate().addString("inserted", "inserted-value");
SourceRecord original = sourceRecord(headers);
SourceRecord xformed = xform.apply(original);
assertNonHeaders(original, xformed);
assertEquals(expect, xformed.headers());
}
use of org.apache.kafka.connect.header.ConnectHeaders in project apache-kafka-on-k8s by banzaicloud.
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());
}
use of org.apache.kafka.connect.header.ConnectHeaders in project apache-kafka-on-k8s by banzaicloud.
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());
}
Aggregations