use of org.apache.flink.util.StateMigrationException in project flink by apache.
the class StateBackendTestBase method testValueStateRestoreWithWrongSerializers.
@Test
@SuppressWarnings("unchecked")
public void testValueStateRestoreWithWrongSerializers() throws Exception {
assumeTrue(supportsMetaInfoVerification());
CheckpointStreamFactory streamFactory = createStreamFactory();
SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
CheckpointableKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class);
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
backend.setCurrentKey(1);
state.update("1");
backend.setCurrentKey(2);
state.update("2");
// draw a snapshot
KeyedStateHandle snapshot1 = runSnapshot(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()), sharedStateRegistry);
backend.dispose();
// restore the first snapshot and validate it
backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot1);
snapshot1.discardState();
@SuppressWarnings("unchecked") TypeSerializer<String> fakeStringSerializer = (TypeSerializer<String>) (TypeSerializer<?>) FloatSerializer.INSTANCE;
try {
kvId = new ValueStateDescriptor<>("id", fakeStringSerializer);
state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
state.value();
fail("should recognize wrong serializers");
} catch (StateMigrationException ignored) {
// expected
}
} finally {
IOUtils.closeQuietly(backend);
backend.dispose();
}
}
use of org.apache.flink.util.StateMigrationException in project flink by apache.
the class StateBackendTestBase method testRestoreWithWrongKeySerializer.
@Test
public void testRestoreWithWrongKeySerializer() throws Exception {
assumeTrue(supportsMetaInfoVerification());
CheckpointStreamFactory streamFactory = createStreamFactory();
SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class);
KeyedStateHandle snapshot = null;
// use an IntSerializer at first
CheckpointableKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
try {
ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
// write some state
backend.setCurrentKey(1);
state.update("1");
backend.setCurrentKey(2);
state.update("2");
// draw a snapshot
snapshot = runSnapshot(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()), sharedStateRegistry);
} finally {
IOUtils.closeQuietly(backend);
backend.dispose();
}
// restore with the wrong key serializer
try {
restoreKeyedBackend(DoubleSerializer.INSTANCE, snapshot);
fail("should recognize wrong key serializer");
} catch (StateMigrationException ignored) {
// expected
} catch (BackendBuildingException ignored) {
assertTrue(ignored.getCause() instanceof StateMigrationException);
}
}
Aggregations