Search in sources :

Example 26 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverterTest method testSchemalessDateToTimestamp.

// Conversions without schemas (core types -> most flexible Timestamp format)
@Test
public void testSchemalessDateToTimestamp() {
    xformValue.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "Timestamp"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, DATE.getTime()));
    assertNull(transformed.valueSchema());
    // No change expected since the source type is coarser-grained
    assertEquals(DATE.getTime(), transformed.value());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 27 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverterTest method testSchemalessTimestampToUnix.

@Test
public void testSchemalessTimestampToUnix() {
    xformValue.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "unix"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, DATE_PLUS_TIME.getTime()));
    assertNull(transformed.valueSchema());
    assertEquals(DATE_PLUS_TIME_UNIX, transformed.value());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 28 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverterTest method testWithSchemaIdentity.

// Conversions with schemas (most flexible Timestamp -> other types)
@Test
public void testWithSchemaIdentity() {
    xformValue.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "Timestamp"));
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Timestamp.SCHEMA, DATE_PLUS_TIME.getTime()));
    assertEquals(Timestamp.SCHEMA, transformed.valueSchema());
    assertEquals(DATE_PLUS_TIME.getTime(), transformed.value());
}
Also used : SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 29 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverterTest method testWithSchemaTimestampToString.

@Test
public void testWithSchemaTimestampToString() {
    Map<String, String> config = new HashMap<>();
    config.put(TimestampConverter.TARGET_TYPE_CONFIG, "string");
    config.put(TimestampConverter.FORMAT_CONFIG, STRING_DATE_FMT);
    xformValue.configure(config);
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, Timestamp.SCHEMA, DATE_PLUS_TIME.getTime()));
    assertEquals(Schema.STRING_SCHEMA, transformed.valueSchema());
    assertEquals(DATE_PLUS_TIME_STRING, transformed.value());
}
Also used : HashMap(java.util.HashMap) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Test(org.junit.Test)

Example 30 with SourceRecord

use of org.apache.kafka.connect.source.SourceRecord in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverterTest method testSchemalessStringToTimestamp.

@Test
public void testSchemalessStringToTimestamp() {
    Map<String, String> config = new HashMap<>();
    config.put(TimestampConverter.TARGET_TYPE_CONFIG, "Timestamp");
    config.put(TimestampConverter.FORMAT_CONFIG, STRING_DATE_FMT);
    xformValue.configure(config);
    SourceRecord transformed = xformValue.apply(new SourceRecord(null, null, "topic", 0, null, DATE_PLUS_TIME_STRING));
    assertNull(transformed.valueSchema());
    assertEquals(DATE_PLUS_TIME.getTime(), transformed.value());
}
Also used : HashMap(java.util.HashMap) 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