Search in sources :

Example 11 with KryoSerializer

use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer 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)

Example 12 with KryoSerializer

use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.

the class ReducingStateDescriptorTest method testValueStateDescriptorEagerSerializer.

@Test
public void testValueStateDescriptorEagerSerializer() throws Exception {
    @SuppressWarnings("unchecked") ReduceFunction<String> reducer = mock(ReduceFunction.class);
    TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());
    ReducingStateDescriptor<String> descr = new ReducingStateDescriptor<String>("testName", reducer, serializer);
    assertEquals("testName", descr.getName());
    assertNotNull(descr.getSerializer());
    assertEquals(serializer, descr.getSerializer());
    ReducingStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);
    assertEquals("testName", copy.getName());
    assertNotNull(copy.getSerializer());
    assertEquals(serializer, copy.getSerializer());
}
Also used : ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) Test(org.junit.Test)

Example 13 with KryoSerializer

use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.

the class ValueStateDescriptorTest method testVeryLargeDefaultValue.

@Test
public void testVeryLargeDefaultValue() throws Exception {
    // ensure that we correctly read very large data when deserializing the default value
    TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig());
    byte[] data = new byte[200000];
    for (int i = 0; i < 200000; i++) {
        data[i] = 65;
    }
    data[199000] = '\0';
    String defaultValue = new String(data, ConfigConstants.DEFAULT_CHARSET);
    ValueStateDescriptor<String> descr = new ValueStateDescriptor<String>("testName", serializer, defaultValue);
    assertEquals("testName", descr.getName());
    assertEquals(defaultValue, descr.getDefaultValue());
    assertNotNull(descr.getSerializer());
    assertEquals(serializer, descr.getSerializer());
    ValueStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr);
    assertEquals("testName", copy.getName());
    assertEquals(defaultValue, copy.getDefaultValue());
    assertNotNull(copy.getSerializer());
    assertEquals(serializer, copy.getSerializer());
}
Also used : ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) Test(org.junit.Test)

Example 14 with KryoSerializer

use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.

the class SubclassFromInterfaceSerializerTest method createSerializer.

@Override
protected TypeSerializer<TestUserInterface> createSerializer() {
    // only register one of the two child classes
    ExecutionConfig conf = new ExecutionConfig();
    conf.registerPojoType(TestUserClass2.class);
    TypeSerializer<TestUserInterface> serializer = type.createSerializer(conf);
    assert (serializer instanceof KryoSerializer);
    return serializer;
}
Also used : ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)

Example 15 with KryoSerializer

use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.

the class StreamingRuntimeContextTest method testMapStateInstantiation.

@Test
public void testMapStateInstantiation() throws Exception {
    final ExecutionConfig config = new ExecutionConfig();
    config.registerKryoType(Path.class);
    final AtomicReference<Object> descriptorCapture = new AtomicReference<>();
    StreamingRuntimeContext context = new StreamingRuntimeContext(createDescriptorCapturingMockOp(descriptorCapture, config), createMockEnvironment(), Collections.<String, Accumulator<?, ?>>emptyMap());
    MapStateDescriptor<String, TaskInfo> descr = new MapStateDescriptor<>("name", String.class, TaskInfo.class);
    context.getMapState(descr);
    MapStateDescriptor<?, ?> descrIntercepted = (MapStateDescriptor<?, ?>) descriptorCapture.get();
    TypeSerializer<?> valueSerializer = descrIntercepted.getValueSerializer();
    // check that the Path class is really registered, i.e., the execution config was applied
    assertTrue(valueSerializer instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) valueSerializer).getKryo().getRegistration(Path.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) TaskInfo(org.apache.flink.api.common.TaskInfo) Test(org.junit.Test)

Aggregations

KryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)17 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)15 Test (org.junit.Test)14 TaskInfo (org.apache.flink.api.common.TaskInfo)9 Path (org.apache.flink.core.fs.Path)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)4 ListSerializer (org.apache.flink.api.common.typeutils.base.ListSerializer)4 FoldingStateDescriptor (org.apache.flink.api.common.state.FoldingStateDescriptor)3 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)3 Kryo (com.esotericsoftware.kryo.Kryo)2 JavaSerializer (com.esotericsoftware.kryo.serializers.JavaSerializer)2 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)2 StateDescriptor (org.apache.flink.api.common.state.StateDescriptor)2 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)2 MapSerializer (org.apache.flink.api.common.typeutils.base.MapSerializer)2 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)2 WindowOperator (org.apache.flink.streaming.runtime.operators.windowing.WindowOperator)2 File (java.io.File)1 FoldFunction (org.apache.flink.api.common.functions.FoldFunction)1