Search in sources :

Example 1 with PojoSerializer

use of org.apache.flink.api.java.typeutils.runtime.PojoSerializer in project flink by apache.

the class FlinkKinesisConsumerTest method testStreamShardMetadataSerializedUsingPojoSerializer.

@Test
public void testStreamShardMetadataSerializedUsingPojoSerializer() {
    TypeInformation<StreamShardMetadata> typeInformation = TypeInformation.of(StreamShardMetadata.class);
    assertTrue(typeInformation.createSerializer(new ExecutionConfig()) instanceof PojoSerializer);
}
Also used : PojoSerializer(org.apache.flink.api.java.typeutils.runtime.PojoSerializer) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) StreamShardMetadata(org.apache.flink.streaming.connectors.kinesis.model.StreamShardMetadata) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with PojoSerializer

use of org.apache.flink.api.java.typeutils.runtime.PojoSerializer in project flink by apache.

the class StateBackendTestBase method testPojoRestoreResilienceWithDifferentRegistrationOrder.

@Test
public void testPojoRestoreResilienceWithDifferentRegistrationOrder() throws Exception {
    CheckpointStreamFactory streamFactory = createStreamFactory();
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    // register A first then B
    env.getExecutionConfig().registerPojoType(TestNestedPojoClassA.class);
    env.getExecutionConfig().registerPojoType(TestNestedPojoClassB.class);
    CheckpointableKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE, env);
    try {
        TypeInformation<TestPojo> pojoType = TypeExtractor.getForClass(TestPojo.class);
        // make sure that we are in fact using the PojoSerializer
        assertTrue(pojoType.createSerializer(env.getExecutionConfig()) instanceof PojoSerializer);
        ValueStateDescriptor<TestPojo> kvId = new ValueStateDescriptor<>("id", pojoType);
        ValueState<TestPojo> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
        // ============== create snapshot of current configuration ==============
        // make some more modifications
        backend.setCurrentKey(1);
        state.update(new TestPojo("u1", 1, new TestNestedPojoClassA(1.0, 2), new TestNestedPojoClassB(2.3, "foo")));
        backend.setCurrentKey(2);
        state.update(new TestPojo("u2", 2, new TestNestedPojoClassA(2.0, 5), new TestNestedPojoClassB(3.1, "bar")));
        KeyedStateHandle snapshot = runSnapshot(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()), sharedStateRegistry);
        backend.dispose();
        // ========== restore snapshot, with a different registration order in the configuration
        // ==========
        env.close();
        env = buildMockEnv();
        env.getExecutionConfig().registerPojoType(// this time register B first
        TestNestedPojoClassB.class);
        env.getExecutionConfig().registerPojoType(TestNestedPojoClassA.class);
        backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot, env);
        // re-initialize to ensure that we create the PojoSerializer from scratch, otherwise
        // initializeSerializerUnlessSet would not pick up our new config
        kvId = new ValueStateDescriptor<>("id", pojoType);
        state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
        backend.setCurrentKey(1);
        // update to test state backends that eagerly serialize, such as RocksDB
        state.update(new TestPojo("u1", 11, new TestNestedPojoClassA(22.1, 12), new TestNestedPojoClassB(1.23, "foobar")));
        // this tests backends that lazily serialize, such as memory state backend
        runSnapshot(backend.snapshot(682375462378L, 2, streamFactory, CheckpointOptions.forCheckpointWithDefaultLocation()), sharedStateRegistry);
        snapshot.discardState();
    } finally {
        backend.dispose();
    }
}
Also used : BlockerCheckpointStreamFactory(org.apache.flink.runtime.util.BlockerCheckpointStreamFactory) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) PojoSerializer(org.apache.flink.api.java.typeutils.runtime.PojoSerializer) Test(org.junit.Test)

Aggregations

PojoSerializer (org.apache.flink.api.java.typeutils.runtime.PojoSerializer)2 Test (org.junit.Test)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 BlockerCheckpointStreamFactory (org.apache.flink.runtime.util.BlockerCheckpointStreamFactory)1 StreamShardMetadata (org.apache.flink.streaming.connectors.kinesis.model.StreamShardMetadata)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1