Source:
public void applyStatefulSerializationTest() { final DAG<AvroVertexSerializable, StreamType.Direction> mockDag = mock(DAG.class); final ApplyStatefulOperatorStream statefulOpStream = new ApplyStatefulOperatorStream<>( expectedUpdateStateFunc, expectedProduceResultFunc, expectedInitializeStateSup, mockDag); final Vertex serializedVertex = statefulOpStream.getSerializedVertex(); Assert.assertEquals(serializedVertex.getVertexType(), VertexTypeEnum.INSTANT_OPERATOR); final InstantOperatorInfo statefulOpInfo = (InstantOperatorInfo) serializedVertex.getAttributes(); final List<ByteBuffer> statefulOpFunctions = statefulOpInfo.getFunctions(); byte[] serializedUpdateStateFunc = new byte[statefulOpFunctions.get(0).remaining()]; statefulOpFunctions.get(0).get(serializedUpdateStateFunc); final BiFunction deserializedUpdateStateFunc = (BiFunction) SerializationUtils.deserialize(serializedUpdateStateFunc); byte[] serializedProduceResultFunc = new byte[statefulOpFunctions.get(1).remaining()]; statefulOpFunctions.get(1).get(serializedProduceResultFunc); final Function deserializedProduceResultFunc = (Function) SerializationUtils.deserialize(serializedProduceResultFunc); byte[] serializedInitializeStateSup = new byte[statefulOpFunctions.get(2).remaining()]; statefulOpFunctions.get(2).get(serializedInitializeStateSup); final Supplier deserializedInitializeStateSup = (Supplier) SerializationUtils.deserialize(serializedInitializeStateSup); Assert.assertEquals(expectedInitializeStateSup.get(), deserializedInitializeStateSup.get()); Assert.assertEquals(expectedUpdateStateFunc.apply("10", 5), deserializedUpdateStateFunc.apply("10", 5)); Assert.assertEquals(expectedUpdateStateFunc.apply("10", 15), deserializedUpdateStateFunc.apply("10", 15)); Assert.assertEquals(expectedProduceResultFunc.apply(15), deserializedProduceResultFunc.apply(15)); Assert.assertNotEquals(expectedProduceResultFunc.apply(15), deserializedProduceResultFunc.apply(10)); }

Target:
public void applyStatefulSerializationTest() { final DAG<AvroVertexSerializable, StreamType.Direction> mockDag = mock(DAG.class); final ApplyStatefulOperatorStream statefulOpStream = new ApplyStatefulOperatorStream<>( expectedUpdateStateFunc, expectedProduceResultFunc, expectedInitializeStateSup, mockDag); final Vertex serializedVertex = statefulOpStream.getSerializedVertex(); Assert.assertEquals(serializedVertex.getVertexType(), VertexTypeEnum.INSTANT_OPERATOR); final InstantOperatorInfo statefulOpInfo = (InstantOperatorInfo) serializedVertex.getAttributes(); final List<ByteBuffer> statefulOpFunctions = statefulOpInfo.getFunctions(); final byte[] serializedUpdateStateFunc = new byte[statefulOpFunctions.get(0).remaining()]; statefulOpFunctions.get(0).get(serializedUpdateStateFunc); final BiFunction deserializedUpdateStateFunc = (BiFunction) SerializationUtils.deserialize(serializedUpdateStateFunc); final byte[] serializedProduceResultFunc = new byte[statefulOpFunctions.get(1).remaining()]; statefulOpFunctions.get(1).get(serializedProduceResultFunc); final Function deserializedProduceResultFunc = (Function) SerializationUtils.deserialize(serializedProduceResultFunc); final byte[] serializedInitializeStateSup = new byte[statefulOpFunctions.get(2).remaining()]; statefulOpFunctions.get(2).get(serializedInitializeStateSup); final Supplier deserializedInitializeStateSup = (Supplier) SerializationUtils.deserialize(serializedInitializeStateSup); Assert.assertEquals(expectedInitializeStateSup.get(), deserializedInitializeStateSup.get()); Assert.assertEquals(expectedUpdateStateFunc.apply("10", 5), deserializedUpdateStateFunc.apply("10", 5)); Assert.assertEquals(expectedUpdateStateFunc.apply("10", 15), deserializedUpdateStateFunc.apply("10", 15)); Assert.assertEquals(expectedProduceResultFunc.apply(15), deserializedProduceResultFunc.apply(15)); Assert.assertNotEquals(expectedProduceResultFunc.apply(15), deserializedProduceResultFunc.apply(10)); }