use of org.apache.flink.api.common.typeutils.base.MapSerializer in project flink by apache.
the class MapStateDescriptorTest method testMapStateDescriptorEagerSerializer.
@Test
public void testMapStateDescriptorEagerSerializer() throws Exception {
TypeSerializer<Integer> keySerializer = new KryoSerializer<>(Integer.class, new ExecutionConfig());
TypeSerializer<String> valueSerializer = new KryoSerializer<>(String.class, new ExecutionConfig());
MapStateDescriptor<Integer, String> descr = new MapStateDescriptor<>("testName", keySerializer, valueSerializer);
assertEquals("testName", descr.getName());
assertNotNull(descr.getSerializer());
assertTrue(descr.getSerializer() instanceof MapSerializer);
assertNotNull(descr.getKeySerializer());
assertEquals(keySerializer, descr.getKeySerializer());
assertNotNull(descr.getValueSerializer());
assertEquals(valueSerializer, descr.getValueSerializer());
MapStateDescriptor<Integer, String> copy = CommonTestUtils.createCopySerializable(descr);
assertEquals("testName", copy.getName());
assertNotNull(copy.getSerializer());
assertTrue(copy.getSerializer() instanceof MapSerializer);
assertNotNull(copy.getKeySerializer());
assertEquals(keySerializer, copy.getKeySerializer());
assertNotNull(copy.getValueSerializer());
assertEquals(valueSerializer, copy.getValueSerializer());
}
use of org.apache.flink.api.common.typeutils.base.MapSerializer in project flink by apache.
the class MapStateDescriptorTest method testMapStateDescriptorLazySerializer.
@Test
public void testMapStateDescriptorLazySerializer() throws Exception {
// some different registered value
ExecutionConfig cfg = new ExecutionConfig();
cfg.registerKryoType(TaskInfo.class);
MapStateDescriptor<Path, String> descr = new MapStateDescriptor<>("testName", Path.class, String.class);
try {
descr.getSerializer();
fail("should cause an exception");
} catch (IllegalStateException ignored) {
}
descr.initializeSerializerUnlessSet(cfg);
assertNotNull(descr.getSerializer());
assertTrue(descr.getSerializer() instanceof MapSerializer);
assertNotNull(descr.getKeySerializer());
assertTrue(descr.getKeySerializer() instanceof KryoSerializer);
assertTrue(((KryoSerializer<?>) descr.getKeySerializer()).getKryo().getRegistration(TaskInfo.class).getId() > 0);
assertNotNull(descr.getValueSerializer());
assertTrue(descr.getValueSerializer() instanceof StringSerializer);
}
Aggregations