Search in sources :

Example 1 with HeapKeyedStateBackend

use of org.apache.flink.runtime.state.heap.HeapKeyedStateBackend in project flink by apache.

the class KvStateRequestSerializerTest method testListSerialization.

/**
	 * Tests list serialization utils.
	 */
@Test
public void testListSerialization() throws Exception {
    final long key = 0L;
    // objects for heap state list serialisation
    final HeapKeyedStateBackend<Long> longHeapKeyedStateBackend = new HeapKeyedStateBackend<>(mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, ClassLoader.getSystemClassLoader(), 1, new KeyGroupRange(0, 0), async, new ExecutionConfig());
    longHeapKeyedStateBackend.setCurrentKey(key);
    final InternalListState<VoidNamespace, Long> listState = longHeapKeyedStateBackend.createListState(VoidNamespaceSerializer.INSTANCE, new ListStateDescriptor<>("test", LongSerializer.INSTANCE));
    testListSerialization(key, listState);
}
Also used : HeapKeyedStateBackend(org.apache.flink.runtime.state.heap.HeapKeyedStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 2 with HeapKeyedStateBackend

use of org.apache.flink.runtime.state.heap.HeapKeyedStateBackend in project flink by apache.

the class MemoryStateBackendTest method testNumStateEntries.

@Test
@SuppressWarnings("unchecked")
public void testNumStateEntries() throws Exception {
    KeyedStateBackend<Integer> backend = createKeyedBackend(IntSerializer.INSTANCE);
    ValueStateDescriptor<String> kvId = new ValueStateDescriptor<>("id", String.class, null);
    kvId.initializeSerializerUnlessSet(new ExecutionConfig());
    HeapKeyedStateBackend<Integer> heapBackend = (HeapKeyedStateBackend<Integer>) backend;
    assertEquals(0, heapBackend.numStateEntries());
    ValueState<String> state = backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, kvId);
    backend.setCurrentKey(0);
    state.update("hello");
    state.update("ciao");
    assertEquals(1, heapBackend.numStateEntries());
    backend.setCurrentKey(42);
    state.update("foo");
    assertEquals(2, heapBackend.numStateEntries());
    backend.setCurrentKey(0);
    state.clear();
    assertEquals(1, heapBackend.numStateEntries());
    backend.setCurrentKey(42);
    state.clear();
    assertEquals(0, heapBackend.numStateEntries());
    backend.dispose();
}
Also used : ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) HeapKeyedStateBackend(org.apache.flink.runtime.state.heap.HeapKeyedStateBackend) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 3 with HeapKeyedStateBackend

use of org.apache.flink.runtime.state.heap.HeapKeyedStateBackend in project flink by apache.

the class KvStateRequestSerializerTest method testMapSerialization.

/**
	 * Tests map serialization utils.
	 */
@Test
public void testMapSerialization() throws Exception {
    final long key = 0L;
    // objects for heap state list serialisation
    final HeapKeyedStateBackend<Long> longHeapKeyedStateBackend = new HeapKeyedStateBackend<>(mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, ClassLoader.getSystemClassLoader(), 1, new KeyGroupRange(0, 0), async, new ExecutionConfig());
    longHeapKeyedStateBackend.setCurrentKey(key);
    final InternalMapState<VoidNamespace, Long, String> mapState = (InternalMapState<VoidNamespace, Long, String>) longHeapKeyedStateBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, new MapStateDescriptor<>("test", LongSerializer.INSTANCE, StringSerializer.INSTANCE));
    testMapSerialization(key, mapState);
}
Also used : InternalMapState(org.apache.flink.runtime.state.internal.InternalMapState) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) HeapKeyedStateBackend(org.apache.flink.runtime.state.heap.HeapKeyedStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Aggregations

ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 HeapKeyedStateBackend (org.apache.flink.runtime.state.heap.HeapKeyedStateBackend)3 Test (org.junit.Test)3 TaskKvStateRegistry (org.apache.flink.runtime.query.TaskKvStateRegistry)2 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)2 VoidNamespace (org.apache.flink.runtime.state.VoidNamespace)2 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 InternalMapState (org.apache.flink.runtime.state.internal.InternalMapState)1