Search in sources :

Example 51 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class JsonConverterTest method noSchemaToConnect.

@Test
public void noSchemaToConnect() {
    Map<String, Boolean> props = Collections.singletonMap("schemas.enable", false);
    converter.configure(props, true);
    assertEquals(new SchemaAndValue(null, true), converter.toConnectData(TOPIC, "true".getBytes()));
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 52 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class JsonConverterTest method timeToConnectWithDefaultValue.

@Test
public void timeToConnectWithDefaultValue() {
    java.util.Date reference = new java.util.Date(0);
    Schema schema = Time.builder().defaultValue(reference).schema();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1, \"default\": 0 }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, schemaAndValue.value());
}
Also used : Schema(org.apache.kafka.connect.data.Schema) Date(org.apache.kafka.connect.data.Date) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 53 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class JsonConverterTest method arrayToConnect.

@Test
public void arrayToConnect() {
    byte[] arrayJson = "{ \"schema\": { \"type\": \"array\", \"items\": { \"type\" : \"int32\" } }, \"payload\": [1, 2, 3] }".getBytes();
    assertEquals(new SchemaAndValue(SchemaBuilder.array(Schema.INT32_SCHEMA).build(), Arrays.asList(1, 2, 3)), converter.toConnectData(TOPIC, arrayJson));
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 54 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class JsonConverterTest method timestampToConnectOptionalWithDefaultValue.

@Test
public void timestampToConnectOptionalWithDefaultValue() {
    Schema schema = Timestamp.builder().optional().defaultValue(new java.util.Date(42)).schema();
    String msg = "{ \"schema\": { \"type\": \"int64\", \"name\": \"org.apache.kafka.connect.data.Timestamp\", \"version\": 1,  \"optional\": true, \"default\": 42 }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(new java.util.Date(42), schemaAndValue.value());
}
Also used : Schema(org.apache.kafka.connect.data.Schema) Date(org.apache.kafka.connect.data.Date) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 55 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class JsonConverterTest method dateToConnectOptional.

@Test
public void dateToConnectOptional() {
    Schema schema = Date.builder().optional().schema();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Date\", \"version\": 1, \"optional\": true }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertNull(schemaAndValue.value());
}
Also used : Schema(org.apache.kafka.connect.data.Schema) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)140 Test (org.junit.Test)57 Schema (org.apache.kafka.connect.data.Schema)49 Test (org.junit.jupiter.api.Test)46 HashMap (java.util.HashMap)32 Struct (org.apache.kafka.connect.data.Struct)21 Date (org.apache.kafka.connect.data.Date)18 BigInteger (java.math.BigInteger)12 Map (java.util.Map)12 ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)11 BigDecimal (java.math.BigDecimal)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)8 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)8 Callback (org.apache.kafka.clients.producer.Callback)7 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Collection (java.util.Collection)6 GregorianCalendar (java.util.GregorianCalendar)6 LinkedHashMap (java.util.LinkedHashMap)6