Search in sources :

Example 1 with KvStateRegistryListener

use of org.apache.flink.runtime.query.KvStateRegistryListener in project flink by apache.

the class StateBackendTestBase method testQueryableStateRegistration.

/**
	 * Tests registration with the KvStateRegistry.
	 */
@Test
public void testQueryableStateRegistration() throws Exception {
    DummyEnvironment env = new DummyEnvironment("test", 1, 0);
    KvStateRegistry registry = env.getKvStateRegistry();
    CheckpointStreamFactory streamFactory = createStreamFactory();
    AbstractKeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE, env);
    KeyGroupRange expectedKeyGroupRange = backend.getKeyGroupRange();
    KvStateRegistryListener listener = mock(KvStateRegistryListener.class);
    registry.registerListener(listener);
    ValueStateDescriptor<Integer> desc = new ValueStateDescriptor<>("test", IntSerializer.INSTANCE);
    desc.setQueryable("banana");
    backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc);
    // Verify registered
    verify(listener, times(1)).notifyKvStateRegistered(eq(env.getJobID()), eq(env.getJobVertexId()), eq(expectedKeyGroupRange), eq("banana"), any(KvStateID.class));
    KeyGroupsStateHandle snapshot = FutureUtil.runIfNotDoneAndGet(backend.snapshot(682375462379L, 4, streamFactory, CheckpointOptions.forFullCheckpoint()));
    backend.dispose();
    verify(listener, times(1)).notifyKvStateUnregistered(eq(env.getJobID()), eq(env.getJobVertexId()), eq(expectedKeyGroupRange), eq("banana"));
    backend.dispose();
    // Initialize again
    backend = restoreKeyedBackend(IntSerializer.INSTANCE, snapshot, env);
    snapshot.discardState();
    backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, desc);
    // Verify registered again
    verify(listener, times(2)).notifyKvStateRegistered(eq(env.getJobID()), eq(env.getJobVertexId()), eq(expectedKeyGroupRange), eq("banana"), any(KvStateID.class));
    backend.dispose();
}
Also used : ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) BlockerCheckpointStreamFactory(org.apache.flink.runtime.util.BlockerCheckpointStreamFactory) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) KvStateID(org.apache.flink.runtime.query.KvStateID) KvStateRegistryListener(org.apache.flink.runtime.query.KvStateRegistryListener) Test(org.junit.Test)

Aggregations

ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)1 KvStateID (org.apache.flink.runtime.query.KvStateID)1 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)1 KvStateRegistryListener (org.apache.flink.runtime.query.KvStateRegistryListener)1 BlockerCheckpointStreamFactory (org.apache.flink.runtime.util.BlockerCheckpointStreamFactory)1 Test (org.junit.Test)1