Search in sources :

Example 1 with TestingDeserializationContext

use of org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext in project flink by apache.

the class KafkaRecordDeserializationSchemaTest method testKafkaValueDeserializerWrapperWithoutConfigurable.

@Test
public void testKafkaValueDeserializerWrapperWithoutConfigurable() throws Exception {
    final Map<String, String> config = ImmutableMap.of("simpleKey", "simpleValue");
    KafkaRecordDeserializationSchema<String> schema = KafkaRecordDeserializationSchema.valueOnly(SimpleStringSerializer.class, config);
    schema.open(new TestingDeserializationContext());
    Assertions.assertEquals(configuration, config);
    assertFalse(isKeyDeserializer);
    assertTrue(configurableConfiguration.isEmpty());
}
Also used : TestingDeserializationContext(org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext) Test(org.junit.Test)

Example 2 with TestingDeserializationContext

use of org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext in project flink by apache.

the class KafkaRecordDeserializationSchemaTest method testKafkaValueDeserializerWrapper.

@Test
public void testKafkaValueDeserializerWrapper() throws Exception {
    final String topic = "Topic";
    byte[] value = new StringSerializer().serialize(topic, "world");
    final ConsumerRecord<byte[], byte[]> consumerRecord = new ConsumerRecord<>(topic, 0, 0L, null, value);
    KafkaRecordDeserializationSchema<String> schema = KafkaRecordDeserializationSchema.valueOnly(StringDeserializer.class);
    schema.open(new TestingDeserializationContext());
    SimpleCollector<String> collector = new SimpleCollector<>();
    schema.deserialize(consumerRecord, collector);
    assertEquals(1, collector.list.size());
    assertEquals("world", collector.list.get(0));
}
Also used : TestingDeserializationContext(org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 3 with TestingDeserializationContext

use of org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext in project flink by apache.

the class PulsarDeserializationSchemaTest method createFromFlinkDeserializationSchema.

@Test
void createFromFlinkDeserializationSchema() throws Exception {
    PulsarDeserializationSchema<String> schema = flinkSchema(new SimpleStringSchema());
    schema.open(new TestingDeserializationContext(), mock(SourceConfiguration.class));
    assertDoesNotThrow(() -> InstantiationUtil.clone(schema));
    Message<byte[]> message = getMessage("some-sample-message", String::getBytes);
    SingleMessageCollector<String> collector = new SingleMessageCollector<>();
    schema.deserialize(message, collector);
    assertNotNull(collector.result);
    assertEquals(collector.result, "some-sample-message");
}
Also used : SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration) SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) TestingDeserializationContext(org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext) Test(org.junit.jupiter.api.Test)

Example 4 with TestingDeserializationContext

use of org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext in project flink by apache.

the class KafkaRecordDeserializationSchemaTest method testKafkaValueDeserializerWrapperWithConfigurable.

@Test
public void testKafkaValueDeserializerWrapperWithConfigurable() throws Exception {
    final Map<String, String> config = ImmutableMap.of("configKey", "configValue");
    KafkaRecordDeserializationSchema<String> schema = KafkaRecordDeserializationSchema.valueOnly(ConfigurableStringSerializer.class, config);
    schema.open(new TestingDeserializationContext());
    Assertions.assertEquals(configurableConfiguration, config);
    assertFalse(isKeyDeserializer);
    assertTrue(configuration.isEmpty());
}
Also used : TestingDeserializationContext(org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext) Test(org.junit.Test)

Example 5 with TestingDeserializationContext

use of org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext in project flink by apache.

the class PulsarDeserializationSchemaTest method createFromPulsarSchema.

@Test
void createFromPulsarSchema() throws Exception {
    Schema<TestMessage> schema1 = PROTOBUF_NATIVE(TestMessage.class);
    PulsarDeserializationSchema<TestMessage> schema2 = pulsarSchema(schema1, TestMessage.class);
    schema2.open(new TestingDeserializationContext(), mock(SourceConfiguration.class));
    assertDoesNotThrow(() -> InstantiationUtil.clone(schema2));
    TestMessage message1 = TestMessage.newBuilder().setStringField(randomAlphabetic(10)).setDoubleField(ThreadLocalRandom.current().nextDouble()).setIntField(ThreadLocalRandom.current().nextInt()).build();
    Message<byte[]> message2 = getMessage(message1, schema1::encode);
    SingleMessageCollector<TestMessage> collector = new SingleMessageCollector<>();
    schema2.deserialize(message2, collector);
    assertNotNull(collector.result);
    assertEquals(collector.result, message1);
}
Also used : SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration) TestMessage(org.apache.flink.connector.pulsar.SampleMessage.TestMessage) TestingDeserializationContext(org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext) Test(org.junit.jupiter.api.Test)

Aggregations

TestingDeserializationContext (org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext)6 SourceConfiguration (org.apache.flink.connector.pulsar.source.config.SourceConfiguration)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)1 TestMessage (org.apache.flink.connector.pulsar.SampleMessage.TestMessage)1 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)1 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1