Search in sources :

Example 66 with SchemaAndValue

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

the class SimpleHeaderConverterTest method shouldParseStringOfMapWithStringValuesWithWhitespaceAsMap.

@Test
public void shouldParseStringOfMapWithStringValuesWithWhitespaceAsMap() {
    SchemaAndValue result = roundTrip(Schema.STRING_SCHEMA, "{ \"foo\" : \"123\", \n\"bar\" : \"baz\" } ");
    assertEquals(STRING_MAP_SCHEMA, result.schema());
    assertEquals(STRING_MAP, result.value());
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 67 with SchemaAndValue

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

the class SimpleHeaderConverterTest method assertRoundTrip.

protected void assertRoundTrip(Schema schema, Object value) {
    byte[] serialized = converter.fromConnectHeader(TOPIC, HEADER, schema, value);
    SchemaAndValue result = converter.toConnectHeader(TOPIC, HEADER, serialized);
    if (value == null) {
        assertNull(serialized);
        assertNull(result.schema());
        assertNull(result.value());
    } else {
        assertNotNull(serialized);
        assertEquals(value, result.value());
        assertEquals(schema, result.schema());
        byte[] serialized2 = converter.fromConnectHeader(TOPIC, HEADER, result.schema(), result.value());
        SchemaAndValue result2 = converter.toConnectHeader(TOPIC, HEADER, serialized2);
        assertNotNull(serialized2);
        assertEquals(schema, result2.schema());
        assertEquals(value, result2.value());
        assertEquals(result, result2);
        assertArrayEquals(serialized, serialized);
    }
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue)

Example 68 with SchemaAndValue

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

the class SimpleHeaderConverterTest method shouldConvertMapWithStringKeysAndMixedValuesToMap.

@Test
public void shouldConvertMapWithStringKeysAndMixedValuesToMap() {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("foo", "bar");
    map.put("baz", (short) 3456);
    SchemaAndValue result = roundTrip(null, map);
    assertEquals(Schema.Type.MAP, result.schema().type());
    assertEquals(Schema.Type.STRING, result.schema().keySchema().type());
    assertNull(result.schema().valueSchema());
    assertEquals(map, result.value());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 69 with SchemaAndValue

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

the class StringConverterTest method testBytesToString.

@Test
public void testBytesToString() {
    SchemaAndValue data = converter.toConnectData(TOPIC, SAMPLE_STRING.getBytes());
    assertEquals(Schema.OPTIONAL_STRING_SCHEMA, data.schema());
    assertEquals(SAMPLE_STRING, data.value());
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.jupiter.api.Test)

Example 70 with SchemaAndValue

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

the class StringConverterTest method testBytesToStringNonUtf8Encoding.

@Test
public void testBytesToStringNonUtf8Encoding() {
    converter.configure(Collections.singletonMap("converter.encoding", StandardCharsets.UTF_16.name()), true);
    SchemaAndValue data = converter.toConnectData(TOPIC, SAMPLE_STRING.getBytes(StandardCharsets.UTF_16));
    assertEquals(Schema.OPTIONAL_STRING_SCHEMA, data.schema());
    assertEquals(SAMPLE_STRING, data.value());
}
Also used : 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