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);
}
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());
}
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());
}
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;
}
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);
}
Aggregations