Search in sources :

Example 11 with SourceRecord

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());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 12 with SourceRecord

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());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 13 with SourceRecord

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")));
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 14 with SourceRecord

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());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 15 with SourceRecord

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());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

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