Search in sources :

Example 96 with SourceRecord

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

the class CastTest method castWholeRecordValueSchemalessFloat32.

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

Example 97 with SourceRecord

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

the class CastTest method castWholeRecordValueWithSchemaBooleanFalse.

@Test
public void castWholeRecordValueWithSchemaBooleanFalse() {
    xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "boolean"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Schema.INT32_SCHEMA, 0));
    assertEquals(Schema.Type.BOOLEAN, transformed.valueSchema().type());
    assertEquals(false, transformed.value());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.jupiter.api.Test)

Example 98 with SourceRecord

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

the class CastTest method castLogicalToString.

@Test
public void castLogicalToString() {
    Date date = new Date(MILLIS_PER_DAY);
    Date time = new Date(MILLIS_PER_HOUR);
    Date timestamp = new Date();
    xformValue.configure(Collections.singletonMap(Cast.SPEC_CONFIG, "date:string,decimal:string,time:string,timestamp:string"));
    SchemaBuilder builder = SchemaBuilder.struct();
    builder.field("date", org.apache.kafka.connect.data.Date.SCHEMA);
    builder.field("decimal", Decimal.schema(new BigDecimal(1982).scale()));
    builder.field("time", Time.SCHEMA);
    builder.field("timestamp", Timestamp.SCHEMA);
    Schema supportedTypesSchema = builder.build();
    Struct recordValue = new Struct(supportedTypesSchema);
    recordValue.put("date", date);
    recordValue.put("decimal", new BigDecimal(1982));
    recordValue.put("time", time);
    recordValue.put("timestamp", timestamp);
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, supportedTypesSchema, recordValue));
    assertEquals(Values.dateFormatFor(date).format(date), ((Struct) transformed.value()).get("date"));
    assertEquals("1982", ((Struct) transformed.value()).get("decimal"));
    assertEquals(Values.dateFormatFor(time).format(time), ((Struct) transformed.value()).get("time"));
    assertEquals(Values.dateFormatFor(timestamp).format(timestamp), ((Struct) transformed.value()).get("timestamp"));
    Schema transformedSchema = ((Struct) transformed.value()).schema();
    assertEquals(Type.STRING, transformedSchema.field("date").schema().type());
    assertEquals(Type.STRING, transformedSchema.field("decimal").schema().type());
    assertEquals(Type.STRING, transformedSchema.field("time").schema().type());
    assertEquals(Type.STRING, transformedSchema.field("timestamp").schema().type());
}
Also used : Schema(org.apache.kafka.connect.data.Schema) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.jupiter.api.Test)

Example 99 with SourceRecord

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

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.jupiter.api.Test)

Example 100 with SourceRecord

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

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.jupiter.api.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