Search in sources :

Example 1 with KafkaJsonDeserializer

use of io.confluent.kafka.serializers.KafkaJsonDeserializer in project incubator-gobblin by apache.

the class KafkaDeserializerExtractorTest method testConfluentJsonDeserializer.

@Test
public void testConfluentJsonDeserializer() throws IOException {
    WorkUnitState mockWorkUnitState = getMockWorkUnitState();
    mockWorkUnitState.setProp("json.value.type", KafkaRecord.class.getName());
    KafkaRecord testKafkaRecord = new KafkaRecord("Hello World");
    Serializer<KafkaRecord> kafkaEncoder = new KafkaJsonSerializer<>();
    kafkaEncoder.configure(PropertiesUtils.propsToStringKeyMap(mockWorkUnitState.getProperties()), false);
    Deserializer<KafkaRecord> kafkaDecoder = new KafkaJsonDeserializer<>();
    kafkaDecoder.configure(PropertiesUtils.propsToStringKeyMap(mockWorkUnitState.getProperties()), false);
    ByteBuffer testKafkaRecordByteBuffer = ByteBuffer.wrap(kafkaEncoder.serialize(TEST_TOPIC_NAME, testKafkaRecord));
    KafkaSchemaRegistry<?, ?> mockKafkaSchemaRegistry = mock(KafkaSchemaRegistry.class);
    KafkaDeserializerExtractor kafkaDecoderExtractor = new KafkaDeserializerExtractor(mockWorkUnitState, Optional.fromNullable(Deserializers.CONFLUENT_JSON), kafkaDecoder, mockKafkaSchemaRegistry);
    ByteArrayBasedKafkaRecord mockMessageAndOffset = getMockMessageAndOffset(testKafkaRecordByteBuffer);
    Assert.assertEquals(kafkaDecoderExtractor.decodeRecord(mockMessageAndOffset), testKafkaRecord);
}
Also used : KafkaJsonDeserializer(io.confluent.kafka.serializers.KafkaJsonDeserializer) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) ByteArrayBasedKafkaRecord(org.apache.gobblin.kafka.client.ByteArrayBasedKafkaRecord) KafkaJsonSerializer(io.confluent.kafka.serializers.KafkaJsonSerializer) ByteBuffer(java.nio.ByteBuffer) ByteArrayBasedKafkaRecord(org.apache.gobblin.kafka.client.ByteArrayBasedKafkaRecord) Test(org.testng.annotations.Test)

Aggregations

KafkaJsonDeserializer (io.confluent.kafka.serializers.KafkaJsonDeserializer)1 KafkaJsonSerializer (io.confluent.kafka.serializers.KafkaJsonSerializer)1 ByteBuffer (java.nio.ByteBuffer)1 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)1 ByteArrayBasedKafkaRecord (org.apache.gobblin.kafka.client.ByteArrayBasedKafkaRecord)1 Test (org.testng.annotations.Test)1