Search in sources :

Example 1 with TestOutputView

use of org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView in project flink by apache.

the class PulsarSchemaTypeSerializerTest method serializeAndDeserializeInstance.

@Test
void serializeAndDeserializeInstance() throws Exception {
    TestOutputView output = new TestOutputView();
    serializer.serialize(message, output);
    TestInputView input = output.getInputView();
    TestMessage message1 = serializer.deserialize(input);
    assertEquals(message, message1);
}
Also used : TestOutputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView) TestInputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView) TestMessage(org.apache.flink.connector.pulsar.SampleMessage.TestMessage) Test(org.junit.jupiter.api.Test)

Example 2 with TestOutputView

use of org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView in project flink by apache.

the class PulsarSchemaTypeSerializerTest method copyValueAmongDataView.

@Test
void copyValueAmongDataView() throws Exception {
    TestOutputView output1 = new TestOutputView();
    serializer.serialize(message, output1);
    // Copy bytes among view.
    TestInputView input1 = output1.getInputView();
    TestOutputView output2 = new TestOutputView();
    serializer.copy(input1, output2);
    TestInputView input2 = output2.getInputView();
    TestMessage message1 = serializer.deserialize(input2);
    assertEquals(message, message1);
}
Also used : TestOutputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView) TestInputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView) TestMessage(org.apache.flink.connector.pulsar.SampleMessage.TestMessage) Test(org.junit.jupiter.api.Test)

Example 3 with TestOutputView

use of org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView in project flink by apache.

the class PulsarSchemaTypeSerializerTest method snapshotSerializerAndRecreateIt.

@Test
void snapshotSerializerAndRecreateIt() throws Exception {
    TypeSerializerSnapshot<TestMessage> snapshot = serializer.snapshotConfiguration();
    // Snapshot
    TestOutputView output = new TestOutputView();
    snapshot.writeSnapshot(output);
    // Restore from snapshot
    snapshot.readSnapshot(snapshot.getCurrentVersion(), output.getInputView(), PulsarSchemaTypeSerializerTest.class.getClassLoader());
    TypeSerializer<TestMessage> serializer1 = snapshot.restoreSerializer();
    assertEquals(serializer, serializer1);
}
Also used : TestOutputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView) TestMessage(org.apache.flink.connector.pulsar.SampleMessage.TestMessage) Test(org.junit.jupiter.api.Test)

Example 4 with TestOutputView

use of org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView in project flink by apache.

the class EitherSerializerTest method testSerializeIndividually.

@Test
public void testSerializeIndividually() throws IOException {
    EitherTypeInfo<LongValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(ValueTypeInfo.LONG_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
    EitherSerializer<LongValue, DoubleValue> eitherSerializer = (EitherSerializer<LongValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
    LongValue lv = new LongValue();
    DoubleValue dv = new DoubleValue();
    Either<LongValue, DoubleValue> left = Left(lv);
    Either<LongValue, DoubleValue> right = Right(dv);
    TestOutputView out = new TestOutputView();
    eitherSerializer.serialize(left, out);
    eitherSerializer.serialize(right, out);
    eitherSerializer.serialize(left, out);
    TestInputView in = out.getInputView();
    // the first deserialization creates a new instance of Left
    Either<LongValue, DoubleValue> copy0 = eitherSerializer.deserialize(right, in);
    // then the cross-references are used for future copies
    Either<LongValue, DoubleValue> copy1 = eitherSerializer.deserialize(copy0, in);
    Either<LongValue, DoubleValue> copy2 = eitherSerializer.deserialize(copy1, in);
    // validate reference equality
    assertSame(right, copy1);
    assertSame(copy0, copy2);
    // validate reference equality of contained objects
    assertSame(right.right(), copy1.right());
    assertSame(copy0.left(), copy2.left());
}
Also used : TestOutputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView) TestInputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView) DoubleValue(org.apache.flink.types.DoubleValue) LongValue(org.apache.flink.types.LongValue) EitherTypeInfo(org.apache.flink.api.java.typeutils.EitherTypeInfo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 5 with TestOutputView

use of org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView in project flink by apache.

the class AvroSchemaFactoryTest method createAvroTypeInformationAndSerializeValues.

@Test
void createAvroTypeInformationAndSerializeValues() throws Exception {
    AvroSchema<StructWithAnnotations> schema = AvroSchema.of(StructWithAnnotations.class);
    PulsarSchema<StructWithAnnotations> pulsarSchema = new PulsarSchema<>(schema, StructWithAnnotations.class);
    StructWithAnnotations struct1 = new StructWithAnnotations();
    struct1.setField1(5678);
    AvroSchemaFactory<StructWithAnnotations> factory = new AvroSchemaFactory<>();
    TypeInformation<StructWithAnnotations> information = factory.createTypeInfo(pulsarSchema.getSchemaInfo());
    assertThat(information).isInstanceOf(PulsarSchemaTypeInformation.class).hasFieldOrPropertyWithValue("typeClass", StructWithAnnotations.class);
    // Serialize by type information.
    TypeSerializer<StructWithAnnotations> serializer = information.createSerializer(new ExecutionConfig());
    // TypeInformation serialization.
    assertDoesNotThrow(() -> InstantiationUtil.clone(information));
    assertDoesNotThrow(() -> InstantiationUtil.clone(serializer));
    TestOutputView output = new TestOutputView();
    serializer.serialize(struct1, output);
    TestInputView input = output.getInputView();
    StructWithAnnotations struct2 = serializer.deserialize(input);
    assertThat(struct2).hasFieldOrPropertyWithValue("field1", struct1.getField1()).hasFieldOrPropertyWithValue("field2", null).hasFieldOrPropertyWithValue("field3", null);
}
Also used : TestOutputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView) TestInputView(org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView) PulsarSchemaTypeInformation(org.apache.flink.connector.pulsar.common.schema.PulsarSchemaTypeInformation) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) PulsarSchema(org.apache.flink.connector.pulsar.common.schema.PulsarSchema) Test(org.junit.jupiter.api.Test)

Aggregations

TestOutputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView)5 TestInputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView)4 Test (org.junit.jupiter.api.Test)4 TestMessage (org.apache.flink.connector.pulsar.SampleMessage.TestMessage)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 EitherTypeInfo (org.apache.flink.api.java.typeutils.EitherTypeInfo)1 PulsarSchema (org.apache.flink.connector.pulsar.common.schema.PulsarSchema)1 PulsarSchemaTypeInformation (org.apache.flink.connector.pulsar.common.schema.PulsarSchemaTypeInformation)1 DoubleValue (org.apache.flink.types.DoubleValue)1 LongValue (org.apache.flink.types.LongValue)1 Test (org.junit.Test)1