Search in sources :

Example 1 with KryoSerializer

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

the class StreamingRuntimeContextTest method testFoldingStateInstantiation.

@Test
public void testFoldingStateInstantiation() 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());
    @SuppressWarnings("unchecked") FoldFunction<String, TaskInfo> folder = (FoldFunction<String, TaskInfo>) mock(FoldFunction.class);
    FoldingStateDescriptor<String, TaskInfo> descr = new FoldingStateDescriptor<>("name", null, folder, TaskInfo.class);
    context.getFoldingState(descr);
    FoldingStateDescriptor<?, ?> descrIntercepted = (FoldingStateDescriptor<?, ?>) descriptorCapture.get();
    TypeSerializer<?> serializer = descrIntercepted.getSerializer();
    // check that the Path class is really registered, i.e., the execution config was applied
    assertTrue(serializer instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) serializer).getKryo().getRegistration(Path.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) FoldFunction(org.apache.flink.api.common.functions.FoldFunction) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) FoldingStateDescriptor(org.apache.flink.api.common.state.FoldingStateDescriptor) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) TaskInfo(org.apache.flink.api.common.TaskInfo) Test(org.junit.Test)

Example 2 with KryoSerializer

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

the class StreamingRuntimeContextTest method testValueStateInstantiation.

@Test
public void testValueStateInstantiation() 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());
    ValueStateDescriptor<TaskInfo> descr = new ValueStateDescriptor<>("name", TaskInfo.class);
    context.getState(descr);
    StateDescriptor<?, ?> descrIntercepted = (StateDescriptor<?, ?>) descriptorCapture.get();
    TypeSerializer<?> serializer = descrIntercepted.getSerializer();
    // check that the Path class is really registered, i.e., the execution config was applied
    assertTrue(serializer instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) serializer).getKryo().getRegistration(Path.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) TaskInfo(org.apache.flink.api.common.TaskInfo) ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) StateDescriptor(org.apache.flink.api.common.state.StateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) FoldingStateDescriptor(org.apache.flink.api.common.state.FoldingStateDescriptor) Test(org.junit.Test)

Example 3 with KryoSerializer

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

the class StreamingRuntimeContextTest method testListStateInstantiation.

@Test
public void testListStateInstantiation() 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());
    ListStateDescriptor<TaskInfo> descr = new ListStateDescriptor<>("name", TaskInfo.class);
    context.getListState(descr);
    ListStateDescriptor<?> descrIntercepted = (ListStateDescriptor<?>) descriptorCapture.get();
    TypeSerializer<?> serializer = descrIntercepted.getSerializer();
    // check that the Path class is really registered, i.e., the execution config was applied
    assertTrue(serializer instanceof ListSerializer);
    TypeSerializer<?> elementSerializer = descrIntercepted.getElementSerializer();
    assertTrue(elementSerializer instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) elementSerializer).getKryo().getRegistration(Path.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) ListSerializer(org.apache.flink.api.common.typeutils.base.ListSerializer) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) 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)

Example 4 with KryoSerializer

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

the class StateDescriptorPassingTest method validateStateDescriptorConfigured.

// ------------------------------------------------------------------------
//  generic validation
// ------------------------------------------------------------------------
private void validateStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
    OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
    WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
    StateDescriptor<?, ?> descr = op.getStateDescriptor();
    // this would be the first statement to fail if state descriptors were not properly initialized
    TypeSerializer<?> serializer = descr.getSerializer();
    assertTrue(serializer instanceof KryoSerializer);
    Kryo kryo = ((KryoSerializer<?>) serializer).getKryo();
    assertTrue("serializer registration was not properly passed on", kryo.getSerializer(File.class) instanceof JavaSerializer);
}
Also used : WindowOperator(org.apache.flink.streaming.runtime.operators.windowing.WindowOperator) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) JavaSerializer(com.esotericsoftware.kryo.serializers.JavaSerializer) Kryo(com.esotericsoftware.kryo.Kryo) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)

Example 5 with KryoSerializer

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

the class ListStateDescriptorTest method testValueStateDescriptorLazySerializer.

@Test
public void testValueStateDescriptorLazySerializer() throws Exception {
    // some different registered value
    ExecutionConfig cfg = new ExecutionConfig();
    cfg.registerKryoType(TaskInfo.class);
    ListStateDescriptor<Path> descr = new ListStateDescriptor<Path>("testName", Path.class);
    try {
        descr.getSerializer();
        fail("should cause an exception");
    } catch (IllegalStateException ignored) {
    }
    descr.initializeSerializerUnlessSet(cfg);
    assertNotNull(descr.getSerializer());
    assertTrue(descr.getSerializer() instanceof ListSerializer);
    assertNotNull(descr.getElementSerializer());
    assertTrue(descr.getElementSerializer() instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) descr.getElementSerializer()).getKryo().getRegistration(TaskInfo.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) TaskInfo(org.apache.flink.api.common.TaskInfo) ListSerializer(org.apache.flink.api.common.typeutils.base.ListSerializer) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) 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