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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations