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