use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
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 apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueWithSchemaFloat32.
@Test
public void castWholeRecordValueWithSchemaFloat32() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "float32"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42));
assertEquals(Schema.Type.FLOAT32, transformed.valueSchema().type());
assertEquals(42.f, transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueSchemalessUnsupportedType.
@Test(expected = DataException.class)
public void castWholeRecordValueSchemalessUnsupportedType() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int8"));
xformValue.apply(new SourceRecord(null, null, "topic", 0, null, Collections.singletonList("foo")));
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordValueWithSchemaFloat64.
@Test
public void castWholeRecordValueWithSchemaFloat64() {
xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "float64"));
SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42));
assertEquals(Schema.Type.FLOAT64, transformed.valueSchema().type());
assertEquals(42., transformed.value());
}
use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.
the class CastTest method castWholeRecordKeyWithSchema.
@Test
public void castWholeRecordKeyWithSchema() {
xformKey.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "int8"));
SourceRecord transformed = xformKey.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 42, Schema.STRING_SCHEMA, "bogus"));
assertEquals(Schema.Type.INT8, transformed.keySchema().type());
assertEquals((byte) 42, transformed.key());
}
Aggregations