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);
}
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();
}
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);
}
Aggregations