Search in sources :

Example 56 with SchemaAndValue

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

the class JsonConverterTest method nullToConnect.

@Test
public void nullToConnect() {
    // When schemas are enabled, trying to decode a tombstone should be an empty envelope
    // the behavior is the same as when the json is "{ "schema": null, "payload": null }"
    // to keep compatibility with the record
    SchemaAndValue converted = converter.toConnectData(TOPIC, null);
    assertEquals(SchemaAndValue.NULL, converted);
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 57 with SchemaAndValue

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

the class JsonConverterTest method decimalToConnectOptional.

@Test
public void decimalToConnectOptional() {
    Schema schema = Decimal.builder(2).optional().schema();
    String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"optional\": true, \"parameters\": { \"scale\": \"2\" } }, \"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)

Example 58 with SchemaAndValue

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

the class JsonConverterTest method decimalToConnectOptionalWithDefaultValue.

@Test
public void decimalToConnectOptionalWithDefaultValue() {
    BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
    Schema schema = Decimal.builder(2).optional().defaultValue(reference).build();
    String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"optional\": true, \"default\": \"AJw=\", \"parameters\": { \"scale\": \"2\" } }, \"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) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 59 with SchemaAndValue

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

the class JsonConverterTest method decimalToConnectWithDefaultValue.

@Test
public void decimalToConnectWithDefaultValue() {
    BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
    Schema schema = Decimal.builder(2).defaultValue(reference).build();
    String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"default\": \"AJw=\", \"parameters\": { \"scale\": \"2\" } }, \"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) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 60 with SchemaAndValue

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

the class JsonConverterTest method decimalToConnect.

@Test
public void decimalToConnect() {
    Schema schema = Decimal.schema(2);
    BigDecimal reference = new BigDecimal(new BigInteger("156"), 2);
    // Payload is base64 encoded byte[]{0, -100}, which is the two's complement encoding of 156.
    String msg = "{ \"schema\": { \"type\": \"bytes\", \"name\": \"org.apache.kafka.connect.data.Decimal\", \"version\": 1, \"parameters\": { \"scale\": \"2\" } }, \"payload\": \"AJw=\" }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    BigDecimal converted = (BigDecimal) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
Also used : Schema(org.apache.kafka.connect.data.Schema) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) 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