Search in sources :

Example 6 with SchemaAndValue

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

the class JsonConverterTest method longToConnect.

@Test
public void longToConnect() {
    assertEquals(new SchemaAndValue(Schema.INT64_SCHEMA, 12L), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"int64\" }, \"payload\": 12 }".getBytes()));
    assertEquals(new SchemaAndValue(Schema.INT64_SCHEMA, 4398046511104L), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"int64\" }, \"payload\": 4398046511104 }".getBytes()));
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.Test)

Example 7 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.Test)

Example 8 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.Test)

Example 9 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.Test)

Example 10 with SchemaAndValue

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

the class JsonConverterTest method structToConnect.

@Test
public void structToConnect() {
    byte[] structJson = "{ \"schema\": { \"type\": \"struct\", \"fields\": [{ \"field\": \"field1\", \"type\": \"boolean\" }, { \"field\": \"field2\", \"type\": \"string\" }] }, \"payload\": { \"field1\": true, \"field2\": \"string\" } }".getBytes();
    Schema expectedSchema = SchemaBuilder.struct().field("field1", Schema.BOOLEAN_SCHEMA).field("field2", Schema.STRING_SCHEMA).build();
    Struct expected = new Struct(expectedSchema).put("field1", true).put("field2", "string");
    SchemaAndValue converted = converter.toConnectData(TOPIC, structJson);
    assertEquals(new SchemaAndValue(expectedSchema, expected), converted);
}
Also used : Schema(org.apache.kafka.connect.data.Schema) Struct(org.apache.kafka.connect.data.Struct) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.Test)

Aggregations

SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)46 Test (org.junit.Test)36 Schema (org.apache.kafka.connect.data.Schema)19 HashMap (java.util.HashMap)14 Date (org.apache.kafka.connect.data.Date)9 Struct (org.apache.kafka.connect.data.Struct)6 BigInteger (java.math.BigInteger)5 Map (java.util.Map)5 MockTime (org.apache.kafka.common.utils.MockTime)5 ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)5 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)4 BigDecimal (java.math.BigDecimal)3 Collection (java.util.Collection)3 GregorianCalendar (java.util.GregorianCalendar)3 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)3 ByteBuffer (java.nio.ByteBuffer)2 LinkedHashMap (java.util.LinkedHashMap)2