Search in sources :

Example 6 with TestingDeserializationContext

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

the class PulsarDeserializationSchemaTest method createFromFlinkTypeInformation.

@Test
void createFromFlinkTypeInformation() throws Exception {
    PulsarDeserializationSchema<String> schema = flinkTypeInfo(Types.STRING, null);
    schema.open(new TestingDeserializationContext(), mock(SourceConfiguration.class));
    assertDoesNotThrow(() -> InstantiationUtil.clone(schema));
    Message<byte[]> message = getMessage("test-content", s -> {
        DataOutputSerializer serializer = new DataOutputSerializer(10);
        StringValue.writeString(s, serializer);
        return serializer.getSharedBuffer();
    });
    SingleMessageCollector<String> collector = new SingleMessageCollector<>();
    schema.deserialize(message, collector);
    assertNotNull(collector.result);
    assertEquals(collector.result, "test-content");
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration) 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