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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations