@Override public final void writeSnapshot(DataOutputView out) throws IOException { checkState(serializer != null, "the prior serializer has not been set on this"); // write the snapshot for a non-updated serializer. // this mimics the previous behavior where the TypeSerializer was // Java-serialized, for backwards compatibility TypeSerializerSerializationUtil.writeSerializer(out, serializer); // now delegate to the snapshots own writing code write(out); }
TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0);
TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0);
for (Tuple2<TypeSerializer<?>, TypeSerializerConfigSnapshot> serAndConfSnapshot : serializersAndConfigs) { out.writeInt(bufferWithPos.getPosition()); writeSerializer(bufferWrapper, serAndConfSnapshot.f0);
/** * Verifies that serializers of anonymous classes can be deserialized, even if serialVersionUID changes. */ @Test public void testAnonymousSerializerClassWithChangedSerialVersionUID() throws Exception { TypeSerializer anonymousClassSerializer = new AbstractIntSerializer() {}; // assert that our assumption holds Assert.assertTrue(anonymousClassSerializer.getClass().isAnonymousClass()); byte[] anonymousSerializerBytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), anonymousClassSerializer); anonymousSerializerBytes = out.toByteArray(); } long newSerialVersionUID = 1234567L; // assert that we're actually modifying to a different serialVersionUID Assert.assertNotEquals(ObjectStreamClass.lookup(anonymousClassSerializer.getClass()).getSerialVersionUID(), newSerialVersionUID); modifySerialVersionUID(anonymousSerializerBytes, anonymousClassSerializer.getClass().getName(), newSerialVersionUID); try (ByteArrayInputStream in = new ByteArrayInputStream(anonymousSerializerBytes)) { anonymousClassSerializer = TypeSerializerSerializationUtil.tryReadSerializer(new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader()); } // serializer should have been deserialized despite serialVersionUID mismatch Assert.assertNotNull(anonymousClassSerializer); Assert.assertTrue(anonymousClassSerializer.getClass().isAnonymousClass()); }
/** * Verifies deserialization failure cases when reading a serializer from bytes, in the * case of a {@link InvalidClassException}. */ @Test public void testSerializerSerializationWithInvalidClass() throws Exception { TypeSerializer<?> serializer = IntSerializer.INSTANCE; byte[] serialized; try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) { TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer); serialized = out.toByteArray(); } TypeSerializer<?> deserializedSerializer; try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) { deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer( new DataInputViewStreamWrapper(in), new ArtificialCNFExceptionThrowingClassLoader( Thread.currentThread().getContextClassLoader(), Collections.singleton(IntSerializer.class.getName())), true); } Assert.assertTrue(deserializedSerializer instanceof UnloadableDummyTypeSerializer); }
/** * Verifies that reading and writing serializers work correctly. */ @Test public void testSerializerSerialization() throws Exception { TypeSerializer<?> serializer = IntSerializer.INSTANCE; byte[] serialized; try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) { TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer); serialized = out.toByteArray(); } TypeSerializer<?> deserializedSerializer; try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) { deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer( new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader()); } Assert.assertEquals(serializer, deserializedSerializer); }
/** * Verifies deserialization failure cases when reading a serializer from bytes, in the * case of a {@link ClassNotFoundException}. */ @Test public void testSerializerSerializationWithClassNotFound() throws Exception { TypeSerializer<?> serializer = IntSerializer.INSTANCE; byte[] serialized; try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) { TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer); serialized = out.toByteArray(); } TypeSerializer<?> deserializedSerializer; try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) { deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer( new DataInputViewStreamWrapper(in), new ArtificialCNFExceptionThrowingClassLoader( Thread.currentThread().getContextClassLoader(), Collections.singleton(IntSerializer.class.getName())), true); } Assert.assertTrue(deserializedSerializer instanceof UnloadableDummyTypeSerializer); Assert.assertArrayEquals( InstantiationUtil.serializeObject(serializer), ((UnloadableDummyTypeSerializer<?>) deserializedSerializer).getActualBytes()); }
for (Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> serAndConfSnapshot : serializersAndConfigs) { out.writeInt(bufferWithPos.getPosition()); writeSerializer(bufferWrapper, serAndConfSnapshot.f0);
@Override public final void writeSnapshot(DataOutputView out) throws IOException { checkState(serializer != null, "the prior serializer has not been set on this"); // write the snapshot for a non-updated serializer. // this mimics the previous behavior where the TypeSerializer was // Java-serialized, for backwards compatibility TypeSerializerSerializationUtil.writeSerializer(out, serializer); // now delegate to the snapshots own writing code write(out); }
@Override public void writeStateMetaInfo(DataOutputView out) throws IOException { out.writeInt(stateMetaInfo.getStateType().ordinal()); out.writeUTF(stateMetaInfo.getName()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getNamespaceSerializer()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getStateSerializer()); } }
@Override public void writeStateMetaInfo(DataOutputView out) throws IOException { out.writeInt(stateMetaInfo.getStateType().ordinal()); out.writeUTF(stateMetaInfo.getName()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getNamespaceSerializer()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getStateSerializer()); } }
TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0);
@Override public void writeStateMetaInfo(DataOutputView out) throws IOException { out.writeUTF(stateMetaInfo.getName()); out.writeByte(stateMetaInfo.getAssignmentMode().ordinal()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getPartitionStateSerializer()); } }
@Override public void writeOperatorStateMetaInfo(DataOutputView out) throws IOException { out.writeUTF(stateMetaInfo.getName()); out.writeByte(stateMetaInfo.getAssignmentMode().ordinal()); TypeSerializerSerializationUtil.writeSerializer(out, stateMetaInfo.getPartitionStateSerializer()); } }
for (Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> serAndConfSnapshot : serializersAndConfigs) { out.writeInt(bufferWithPos.getPosition()); writeSerializer(bufferWrapper, serAndConfSnapshot.f0);