Search in sources :

Example 86 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.

the class CastTest method castNullKeyRecordWithSchema.

@Test
public void castNullKeyRecordWithSchema() {
    xformKey.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "foo:int64"));
    SourceRecord original = new SourceRecord(null, null, "topic", 0, Schema.STRING_SCHEMA, null, Schema.STRING_SCHEMA, "value");
    SourceRecord transformed = xformKey.apply(original);
    assertEquals(original, transformed);
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 87 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.

the class CastTest method castWholeRecordValueSchemalessInt16.

@Test
public void castWholeRecordValueSchemalessInt16() {
    xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int16"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, 42));
    assertNull(transformed.valueSchema());
    assertEquals((short) 42, transformed.value());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 88 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.

the class CastTest method castWholeRecordKeySchemaless.

@Test
public void castWholeRecordKeySchemaless() {
    xformKey.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int8"));
    SourceRecord transformed = xformKey.apply(new SourceRecord(null, null, "topic", 0, null, 42, Schema.STRING_SCHEMA, "bogus"));
    assertNull(transformed.keySchema());
    assertEquals((byte) 42, transformed.key());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 89 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project kafka by apache.

the class CastTest method castWholeRecordDefaultValue.

@Test
public void castWholeRecordDefaultValue() {
    // Validate default value in schema is correctly converted
    xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int32"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, SchemaBuilder.float32().defaultValue(-42.125f).build(), 42.125f));
    assertEquals(Schema.Type.INT32, transformed.valueSchema().type());
    assertEquals(42, transformed.value());
    assertEquals(-42, transformed.valueSchema().defaultValue());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 90 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord 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);
}
Also used : ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) Headers(org.apache.kafka.connect.header.Headers) SourceRecord(org.apache.kafka.connect.source.SourceRecord) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

SourceRecord (org.apache.kafka.connect.source.SourceRecord)308 Test (org.junit.Test)148 Test (org.junit.jupiter.api.Test)98 Struct (org.apache.kafka.connect.data.Struct)68 HashMap (java.util.HashMap)60 Schema (org.apache.kafka.connect.data.Schema)45 ThreadedTest (org.apache.kafka.connect.util.ThreadedTest)27 ParameterizedTest (org.apache.kafka.connect.util.ParameterizedTest)23 ArrayList (java.util.ArrayList)22 RetryWithToleranceOperatorTest (org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest)21 Map (java.util.Map)15 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)13 ConnectException (org.apache.kafka.connect.errors.ConnectException)13 Document (org.bson.Document)13 FixFor (io.debezium.doc.FixFor)12 List (java.util.List)12 RecordsForCollection (io.debezium.connector.mongodb.RecordMakers.RecordsForCollection)11 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)11 ConnectHeaders (org.apache.kafka.connect.header.ConnectHeaders)11 BsonTimestamp (org.bson.BsonTimestamp)11