use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.
the class StreamingRuntimeContextTest method testReducingStateInstantiation.
@Test
public void testReducingStateInstantiation() 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") ReduceFunction<TaskInfo> reducer = (ReduceFunction<TaskInfo>) mock(ReduceFunction.class);
ReducingStateDescriptor<TaskInfo> descr = new ReducingStateDescriptor<>("name", reducer, TaskInfo.class);
context.getReducingState(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);
}
use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer in project flink by apache.
the class StateDescriptorPassingTest method validateListStateDescriptorConfigured.
private void validateListStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
StateDescriptor<?, ?> descr = op.getStateDescriptor();
assertTrue(descr instanceof ListStateDescriptor);
ListStateDescriptor<?> listDescr = (ListStateDescriptor<?>) descr;
// this would be the first statement to fail if state descriptors were not properly initialized
TypeSerializer<?> serializer = listDescr.getSerializer();
assertTrue(serializer instanceof ListSerializer);
TypeSerializer<?> elementSerializer = listDescr.getElementSerializer();
assertTrue(elementSerializer instanceof KryoSerializer);
Kryo kryo = ((KryoSerializer<?>) elementSerializer).getKryo();
assertTrue("serializer registration was not properly passed on", kryo.getSerializer(File.class) instanceof JavaSerializer);
}
Aggregations