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