flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-core/src/test/java/org/apache/flink/api/common/typeutils/TypeSerializerSerializationUtilTest.java
/**
	 * Verifies that serializers of anonymous classes can be deserialized, even if serialVersionUID changes.
	 */
Verifies that serializers of anonymous classes can be deserialized, even if serialVersionUID changes.
Verifies that serializers of anonymous classes can be deserialized even if serialVersionUID changes .
@Test
	public void testAnonymousSerializerClassWithChangedSerialVersionUID() throws Exception {
		TypeSerializer anonymousClassSerializer = new AbstractIntSerializer() {};
		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.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());
		}
		Assert.assertNotNull(anonymousClassSerializer);
		Assert.assertTrue(anonymousClassSerializer.getClass().isAnonymousClass());
	}
@ Test public void testAnonymousSerializerClassWithChangedSerialVersionUID ( ) throws Exception { TypeSerializer anonymousClassSerializer = new AbstractIntSerializer ( ) { } ; 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 . 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 ( ) ) ; } Assert . assertNotNull ( anonymousClassSerializer ) ; Assert . assertTrue ( anonymousClassSerializer . getClass ( ) . isAnonymousClass ( ) ) ; }
Verifies that serializers of anonymous classes can be deserialized, even if serialVersionUID changes.
Verifies that serializers of anonymous classes can be deserialized even if serialVersionUID changes .
// assert that our assumption holds // assert that we're actually modifying to a different serialVersionUID // serializer should have been deserialized despite serialVersionUID mismatch