/** * Binary format layout of a written serializer snapshot is as follows: * * <ul> * <li>1. Format version of this util.</li> * <li>2. Name of the TypeSerializerSnapshot class.</li> * <li>3. The version of the TypeSerializerSnapshot's binary format.</li> * <li>4. The actual serializer snapshot data.</li> * </ul> */ @SuppressWarnings("deprecation") @Override public void write(DataOutputView out) throws IOException { setSerializerForWriteIfOldPath(serializerSnapshot, serializer); // write the format version of this utils format super.write(out); TypeSerializerSnapshot.writeVersionedSnapshot(out, serializerSnapshot); }
/** * Writes the composite snapshot of all the contained serializers. */ public final void writeNestedSerializerSnapshots(DataOutputView out) throws IOException { out.writeInt(MAGIC_NUMBER); out.writeInt(VERSION); out.writeInt(nestedSnapshots.length); for (TypeSerializerSnapshot<?> snap : nestedSnapshots) { TypeSerializerSnapshot.writeVersionedSnapshot(out, snap); } }
@Test public void testSerializeConfigWhenSerializerMissing() throws Exception { TestSerializer ser = new TestSerializer(); TypeSerializerConfigSnapshot<Object> snap = (TypeSerializerConfigSnapshot<Object>) ser.snapshotConfiguration(); try { TypeSerializerSnapshot.writeVersionedSnapshot(new DataOutputSerializer(64), snap); fail("exception expected"); } catch (IllegalStateException e) { // expected } }
private TypeSerializerSchemaCompatibility<String> snapshotCompositeSerializerAndGetSchemaCompatibilityAfterRestore( TypeSerializer<?>[] testNestedSerializers, String initialOuterConfiguration, String newOuterConfiguration) throws IOException { TestCompositeTypeSerializer testSerializer = new TestCompositeTypeSerializer(initialOuterConfiguration, testNestedSerializers); TypeSerializerSnapshot<String> testSerializerSnapshot = testSerializer.snapshotConfiguration(); DataOutputSerializer out = new DataOutputSerializer(128); TypeSerializerSnapshot.writeVersionedSnapshot(out, testSerializerSnapshot); DataInputDeserializer in = new DataInputDeserializer(out.getCopyOfBuffer()); testSerializerSnapshot = TypeSerializerSnapshot.readVersionedSnapshot( in, Thread.currentThread().getContextClassLoader()); TestCompositeTypeSerializer newTestSerializer = new TestCompositeTypeSerializer(newOuterConfiguration, testNestedSerializers); return testSerializerSnapshot.resolveSchemaCompatibility(newTestSerializer); }
@Test public void testRestoreCompositeTypeSerializer() throws IOException { // the target compatibilities of the nested serializers doesn't matter, // because we're only testing the restore serializer TypeSerializer<?>[] testNestedSerializers = { new NestedSerializer(TargetCompatibility.COMPATIBLE_AS_IS), new NestedSerializer(TargetCompatibility.INCOMPATIBLE), new NestedSerializer(TargetCompatibility.COMPATIBLE_AFTER_MIGRATION) }; TestCompositeTypeSerializer testSerializer = new TestCompositeTypeSerializer("outer-config", testNestedSerializers); TypeSerializerSnapshot<String> testSerializerSnapshot = testSerializer.snapshotConfiguration(); DataOutputSerializer out = new DataOutputSerializer(128); TypeSerializerSnapshot.writeVersionedSnapshot(out, testSerializerSnapshot); DataInputDeserializer in = new DataInputDeserializer(out.getCopyOfBuffer()); testSerializerSnapshot = TypeSerializerSnapshot.readVersionedSnapshot( in, Thread.currentThread().getContextClassLoader()); // now, restore the composite type serializer; // the restored nested serializer should be a RestoredNestedSerializer testSerializer = (TestCompositeTypeSerializer) testSerializerSnapshot.restoreSerializer(); Assert.assertTrue(testSerializer.getNestedSerializers()[0].getClass() == RestoredNestedSerializer.class); Assert.assertTrue(testSerializer.getNestedSerializers()[1].getClass() == RestoredNestedSerializer.class); Assert.assertTrue(testSerializer.getNestedSerializers()[2].getClass() == RestoredNestedSerializer.class); }
@Test public void testSerializerDeserializationFailure() throws Exception { TestSerializer ser = new TestSerializer(); TypeSerializerConfigSnapshot<Object> snap = (TypeSerializerConfigSnapshot<Object>) ser.snapshotConfiguration(); snap.setPriorSerializer(ser); DataOutputSerializer out = new DataOutputSerializer(64); TypeSerializerSnapshot.writeVersionedSnapshot(out, snap); TypeSerializerSnapshot<Object> readBack = TypeSerializerSnapshot.readVersionedSnapshot( new DataInputDeserializer(out.getCopyOfBuffer()), getClass().getClassLoader()); assertNotNull(readBack); try { readBack.restoreSerializer(); fail("expected exception"); } catch (IllegalStateException e) { // expected } ((TypeSerializerConfigSnapshot<Object>) readBack).setPriorSerializer( new UnloadableDummyTypeSerializer<>(new byte[0])); try { readBack.restoreSerializer(); fail("expected exception"); } catch (IllegalStateException e) { // expected } }
/** * Binary format layout of a written serializer snapshot is as follows: * * <ul> * <li>1. Format version of this util.</li> * <li>2. Name of the TypeSerializerSnapshot class.</li> * <li>3. The version of the TypeSerializerSnapshot's binary format.</li> * <li>4. The actual serializer snapshot data.</li> * </ul> */ @SuppressWarnings("deprecation") @Override public void write(DataOutputView out) throws IOException { setSerializerForWriteIfOldPath(serializerSnapshot, serializer); // write the format version of this utils format super.write(out); TypeSerializerSnapshot.writeVersionedSnapshot(out, serializerSnapshot); }
/** * Writes the composite snapshot of all the contained serializers. */ public final void writeCompositeSnapshot(DataOutputView out) throws IOException { out.writeInt(MAGIC_NUMBER); out.writeInt(VERSION); out.writeInt(nestedSnapshots.length); for (TypeSerializerSnapshot<?> snap : nestedSnapshots) { TypeSerializerSnapshot.writeVersionedSnapshot(out, snap); } }