Java Code Examples for org.apache.flink.api.common.serialization.SerializationSchema#serialize()

The following examples show how to use org.apache.flink.api.common.serialization.SerializationSchema#serialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PravegaSerializationTest.java    From flink-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializerFastPath() throws IOException {
    final FastSerializer pravegaSerializer = new FastSerializer();
    final SerializationSchema<Long> flinkSerializer = new PravegaSerializationSchema<>(pravegaSerializer);

    final Random rnd = new Random();

    for (int num = 100; num > 0; --num) {
        final long value = rnd.nextLong();

        byte[] serialized = flinkSerializer.serialize(value);
        assertEquals(value, ByteBuffer.wrap(serialized).getLong());

        // make sure we avoid copies where possible
        assertTrue(serialized == pravegaSerializer.array);
    }
}
 
Example 2
Source File: PravegaSerializationTest.java    From flink-connectors with Apache License 2.0 5 votes vote down vote up
private void runNotFullyWrappingByteBufferTest(int arraySize, int offset, int capacity, boolean direct) throws IOException {
    final Serializer<Long> pravegaSerializer =
            new ByteBufferReusingSerializer(arraySize, offset, capacity, direct);

    final SerializationSchema<Long> flinkSerializer = new PravegaSerializationSchema<>(pravegaSerializer);

    final Random rnd = new Random();

    for (int num = 100; num > 0; --num) {
        final long value = rnd.nextLong();

        byte[] serialized = flinkSerializer.serialize(value);
        assertEquals(value, ByteBuffer.wrap(serialized).getLong());
    }
}
 
Example 3
Source File: AvroSerializationSchemaTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenericRecord() throws Exception {
	SerializationSchema<GenericRecord> deserializationSchema =
		AvroSerializationSchema.forGeneric(
			address.getSchema()
		);

	byte[] encodedAddress = writeRecord(address, Address.getClassSchema());
	byte[] dataSerialized = deserializationSchema.serialize(address);
	assertArrayEquals(encodedAddress, dataSerialized);
}
 
Example 4
Source File: AvroSerializationSchemaTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpecificRecordWithConfluentSchemaRegistry() throws Exception {
	SerializationSchema<Address> deserializer = AvroSerializationSchema.forSpecific(Address.class);

	byte[] encodedAddress = writeRecord(address, Address.getClassSchema());
	byte[] serializedAddress = deserializer.serialize(address);
	assertArrayEquals(encodedAddress, serializedAddress);
}
 
Example 5
Source File: BackupCreatorIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenProperBackupObject_whenSerializeIsInvoked_thenObjectIsProperlySerialized() throws IOException {
    InputMessage message = new InputMessage("Me", "User", LocalDateTime.now(), "Test Message");
    List<InputMessage> messages = Arrays.asList(message);
    Backup backup = new Backup(messages, LocalDateTime.now());
    byte[] backupSerialized = mapper.writeValueAsBytes(backup);
    SerializationSchema<Backup> serializationSchema = new BackupSerializationSchema();
    byte[] backupProcessed = serializationSchema.serialize(backup);
    
    assertArrayEquals(backupSerialized, backupProcessed);
}