Search in sources :

Example 6 with TestMessage

use of org.apache.flink.connector.pulsar.SampleMessage.TestMessage 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

TestMessage (org.apache.flink.connector.pulsar.SampleMessage.TestMessage)6 Test (org.junit.jupiter.api.Test)6 TestOutputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView)3 TestInputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView)2 PulsarSchema (org.apache.flink.connector.pulsar.common.schema.PulsarSchema)1 SourceConfiguration (org.apache.flink.connector.pulsar.source.config.SourceConfiguration)1 FL (org.apache.flink.connector.pulsar.testutils.SampleData.FL)1 Foo (org.apache.flink.connector.pulsar.testutils.SampleData.Foo)1 TestingDeserializationContext (org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext)1 KeyValue (org.apache.pulsar.common.schema.KeyValue)1 SchemaInfo (org.apache.pulsar.common.schema.SchemaInfo)1