Search in sources :

Example 1 with MapSerializer

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());
}
Also used : MapSerializer(org.apache.flink.api.common.typeutils.base.MapSerializer) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) Test(org.junit.Test)

Example 2 with MapSerializer

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);
}
Also used : Path(org.apache.flink.core.fs.Path) TaskInfo(org.apache.flink.api.common.TaskInfo) MapSerializer(org.apache.flink.api.common.typeutils.base.MapSerializer) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) Test(org.junit.Test)

Aggregations

ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 MapSerializer (org.apache.flink.api.common.typeutils.base.MapSerializer)2 KryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)2 Test (org.junit.Test)2 TaskInfo (org.apache.flink.api.common.TaskInfo)1 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)1 Path (org.apache.flink.core.fs.Path)1