org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer Java Examples
The following examples show how to use
org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinaryRowTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSerStringToKryo() throws IOException { KryoSerializer<BinaryString> serializer = new KryoSerializer<>( BinaryString.class, new ExecutionConfig()); BinaryString string = BinaryString.fromString("hahahahaha"); RandomAccessOutputView out = new RandomAccessOutputView( new MemorySegment[]{MemorySegmentFactory.wrap(new byte[1024])}, 64); serializer.serialize(string, out); RandomAccessInputView input = new RandomAccessInputView( new ArrayList<>(Collections.singletonList(out.getCurrentSegment())), 64, 64); BinaryString newStr = serializer.deserialize(input); assertEquals(string, newStr); }
Example #2
Source File: AvroKryoSerializerRegistrationsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a Kryo serializer and writes the default registrations out to a * comma separated file with one entry per line: * * <pre> * id,class * </pre> * * <p>The produced file is used to check that the registered IDs don't change * in future Flink versions. * * <p>This method is not used in the tests, but documents how the test file * has been created and can be used to re-create it if needed. * * @param filePath File path to write registrations to */ private void writeDefaultKryoRegistrations(String filePath) throws IOException { final File file = new File(filePath); if (file.exists()) { assertTrue(file.delete()); } final Kryo kryo = new KryoSerializer<>(Integer.class, new ExecutionConfig()).getKryo(); final int nextId = kryo.getNextRegistrationId(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (int i = 0; i < nextId; i++) { Registration registration = kryo.getRegistration(i); String str = registration.getId() + "," + registration.getType().getName(); writer.write(str, 0, str.length()); writer.newLine(); } System.out.println("Created file with registrations at " + file.getAbsolutePath()); } }
Example #3
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testListStateInstantiation() throws Exception { final ExecutionConfig config = new ExecutionConfig(); config.registerKryoType(Path.class); final AtomicReference<Object> descriptorCapture = new AtomicReference<>(); StreamingRuntimeContext context = createRuntimeContext(descriptorCapture, config); 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); }
Example #4
Source File: ListStateDescriptorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testListStateDescriptor() throws Exception { TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ListStateDescriptor<String> descr = new ListStateDescriptor<>("testName", serializer); assertEquals("testName", descr.getName()); assertNotNull(descr.getSerializer()); assertTrue(descr.getSerializer() instanceof ListSerializer); assertNotNull(descr.getElementSerializer()); assertEquals(serializer, descr.getElementSerializer()); ListStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertNotNull(copy.getSerializer()); assertTrue(copy.getSerializer() instanceof ListSerializer); assertNotNull(copy.getElementSerializer()); assertEquals(serializer, copy.getElementSerializer()); }
Example #5
Source File: StatefulStreamJobUpgradeTestProgram.java From flink with Apache License 2.0 | 6 votes |
private static void executeOriginalVariant(StreamExecutionEnvironment env, ParameterTool pt) throws Exception { KeyedStream<Event, Integer> source = env.addSource(createEventSource(pt)) .name("EventSource") .uid("EventSource") .assignTimestampsAndWatermarks(createTimestampExtractor(pt)) .keyBy(Event::getKey); List<TypeSerializer<ComplexPayload>> stateSer = Collections.singletonList(new KryoSerializer<>(ComplexPayload.class, env.getConfig())); KeyedStream<Event, Integer> afterStatefulOperations = applyOriginalStatefulOperations(source, stateSer, Collections.emptyList()); afterStatefulOperations .flatMap(createSemanticsCheckMapper(pt)) .name("SemanticsCheckMapper") .addSink(new PrintSinkFunction<>()); env.execute("General purpose test job"); }
Example #6
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: MapStateDescriptorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * FLINK-6775. * * <p>Tests that the returned serializer is duplicated. This allows to * share the state descriptor. */ @Test public void testSerializerDuplication() { // we need a serializer that actually duplicates for testing (a stateful one) // we use Kryo here, because it meets these conditions TypeSerializer<String> keySerializer = new KryoSerializer<>(String.class, new ExecutionConfig()); TypeSerializer<Long> valueSerializer = new KryoSerializer<>(Long.class, new ExecutionConfig()); MapStateDescriptor<String, Long> descr = new MapStateDescriptor<>("foobar", keySerializer, valueSerializer); TypeSerializer<String> keySerializerA = descr.getKeySerializer(); TypeSerializer<String> keySerializerB = descr.getKeySerializer(); TypeSerializer<Long> valueSerializerA = descr.getValueSerializer(); TypeSerializer<Long> valueSerializerB = descr.getValueSerializer(); // check that we did not retrieve the same serializers assertNotSame(keySerializerA, keySerializerB); assertNotSame(valueSerializerA, valueSerializerB); TypeSerializer<Map<String, Long>> serializerA = descr.getSerializer(); TypeSerializer<Map<String, Long>> serializerB = descr.getSerializer(); assertNotSame(serializerA, serializerB); }
Example #8
Source File: StateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testInitializeSerializerAfterSerializationWithCustomConfig() throws Exception { // guard our test assumptions. assertEquals("broken test assumption", -1, new KryoSerializer<>(String.class, new ExecutionConfig()).getKryo() .getRegistration(File.class).getId()); final ExecutionConfig config = new ExecutionConfig(); config.registerKryoType(File.class); final TestStateDescriptor<Path> original = new TestStateDescriptor<>("test", Path.class); TestStateDescriptor<Path> clone = CommonTestUtils.createCopySerializable(original); clone.initializeSerializerUnlessSet(config); // serialized one (later initialized) carries the registration assertTrue(((KryoSerializer<?>) clone.getSerializer()).getKryo() .getRegistration(File.class).getId() > 0); }
Example #9
Source File: ReducingStateDescriptorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testReducingStateDescriptor() throws Exception { ReduceFunction<String> reducer = (a, b) -> a; TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ReducingStateDescriptor<String> descr = new ReducingStateDescriptor<>("testName", reducer, serializer); assertEquals("testName", descr.getName()); assertNotNull(descr.getSerializer()); assertEquals(serializer, descr.getSerializer()); assertEquals(reducer, descr.getReduceFunction()); ReducingStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertNotNull(copy.getSerializer()); assertEquals(serializer, copy.getSerializer()); }
Example #10
Source File: AvroKryoSerializerRegistrationsTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that the registered classes in Kryo did not change. * * <p>Once we have proper serializer versioning this test will become obsolete. * But currently a change in the serializers can break savepoint backwards * compatibility between Flink versions. */ @Test public void testDefaultKryoRegisteredClassesDidNotChange() throws Exception { final Kryo kryo = new KryoSerializer<>(Integer.class, new ExecutionConfig()).getKryo(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream("flink_11-kryo_registrations")))) { String line; while ((line = reader.readLine()) != null) { String[] split = line.split(","); final int tag = Integer.parseInt(split[0]); final String registeredClass = split[1]; Registration registration = kryo.getRegistration(tag); if (registration == null) { fail(String.format("Registration for %d = %s got lost", tag, registeredClass)); } else if (!registeredClass.equals(registration.getType().getName())) { fail(String.format("Registration for %d = %s changed to %s", tag, registeredClass, registration.getType().getName())); } } } }
Example #11
Source File: AvroKryoSerializerRegistrationsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that the registered classes in Kryo did not change. * * <p>Once we have proper serializer versioning this test will become obsolete. * But currently a change in the serializers can break savepoint backwards * compatibility between Flink versions. */ @Test public void testDefaultKryoRegisteredClassesDidNotChange() throws Exception { final Kryo kryo = new KryoSerializer<>(Integer.class, new ExecutionConfig()).getKryo(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream("flink_11-kryo_registrations")))) { String line; while ((line = reader.readLine()) != null) { String[] split = line.split(","); final int tag = Integer.parseInt(split[0]); final String registeredClass = split[1]; Registration registration = kryo.getRegistration(tag); if (registration == null) { fail(String.format("Registration for %d = %s got lost", tag, registeredClass)); } else if (!registeredClass.equals(registration.getType().getName())) { fail(String.format("Registration for %d = %s changed to %s", tag, registeredClass, registration.getType().getName())); } } } }
Example #12
Source File: ReducingStateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testReducingStateDescriptor() throws Exception { ReduceFunction<String> reducer = (a, b) -> a; TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ReducingStateDescriptor<String> descr = new ReducingStateDescriptor<>("testName", reducer, serializer); assertEquals("testName", descr.getName()); assertNotNull(descr.getSerializer()); assertEquals(serializer, descr.getSerializer()); assertEquals(reducer, descr.getReduceFunction()); ReducingStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertNotNull(copy.getSerializer()); assertEquals(serializer, copy.getSerializer()); }
Example #13
Source File: ReducingStateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testReducingStateDescriptor() throws Exception { ReduceFunction<String> reducer = (a, b) -> a; TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ReducingStateDescriptor<String> descr = new ReducingStateDescriptor<>("testName", reducer, serializer); assertEquals("testName", descr.getName()); assertNotNull(descr.getSerializer()); assertEquals(serializer, descr.getSerializer()); assertEquals(reducer, descr.getReduceFunction()); ReducingStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertNotNull(copy.getSerializer()); assertEquals(serializer, copy.getSerializer()); }
Example #14
Source File: ExecutionConfigTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testDisableGenericTypes() { ExecutionConfig conf = new ExecutionConfig(); TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class); // by default, generic types are supported TypeSerializer<Object> serializer = typeInfo.createSerializer(conf); assertTrue(serializer instanceof KryoSerializer); // expect an exception when generic types are disabled conf.disableGenericTypes(); try { typeInfo.createSerializer(conf); fail("should have failed with an exception"); } catch (UnsupportedOperationException e) { // expected } }
Example #15
Source File: ExecutionConfigTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testDisableGenericTypes() { ExecutionConfig conf = new ExecutionConfig(); TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class); // by default, generic types are supported TypeSerializer<Object> serializer = typeInfo.createSerializer(conf); assertTrue(serializer instanceof KryoSerializer); // expect an exception when generic types are disabled conf.disableGenericTypes(); try { typeInfo.createSerializer(conf); fail("should have failed with an exception"); } catch (UnsupportedOperationException e) { // expected } }
Example #16
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example #17
Source File: AvroKryoSerializerRegistrationsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that the registered classes in Kryo did not change. * * <p>Once we have proper serializer versioning this test will become obsolete. * But currently a change in the serializers can break savepoint backwards * compatibility between Flink versions. */ @Test public void testDefaultKryoRegisteredClassesDidNotChange() throws Exception { final Kryo kryo = new KryoSerializer<>(Integer.class, new ExecutionConfig()).getKryo(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream("flink_11-kryo_registrations")))) { String line; while ((line = reader.readLine()) != null) { String[] split = line.split(","); final int tag = Integer.parseInt(split[0]); final String registeredClass = split[1]; Registration registration = kryo.getRegistration(tag); if (registration == null) { fail(String.format("Registration for %d = %s got lost", tag, registeredClass)); } else if (!registeredClass.equals(registration.getType().getName())) { fail(String.format("Registration for %d = %s changed to %s", tag, registeredClass, registration.getType().getName())); } } } }
Example #18
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example #19
Source File: StateDescriptorPassingTest.java From flink with Apache License 2.0 | 6 votes |
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); }
Example #20
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAnyType() { testAll( new AnyType<>(Human.class, new KryoSerializer<>(Human.class, new ExecutionConfig())), "ANY('org.apache.flink.table.types.LogicalTypesTest$Human', " + "'AEdvcmcuYXBhY2hlLmZsaW5rLmFwaS5qYXZhLnR5cGV1dGlscy5ydW50aW1lLmtyeW8uS3J5b1Nlcml" + "hbGl6ZXJTbmFwc2hvdAAAAAIAM29yZy5hcGFjaGUuZmxpbmsudGFibGUudHlwZXMuTG9naWNhbFR5cG" + "VzVGVzdCRIdW1hbgAABPLGmj1wAAAAAgAzb3JnLmFwYWNoZS5mbGluay50YWJsZS50eXBlcy5Mb2dpY" + "2FsVHlwZXNUZXN0JEh1bWFuAQAAADUAM29yZy5hcGFjaGUuZmxpbmsudGFibGUudHlwZXMuTG9naWNh" + "bFR5cGVzVGVzdCRIdW1hbgEAAAA5ADNvcmcuYXBhY2hlLmZsaW5rLnRhYmxlLnR5cGVzLkxvZ2ljYWx" + "UeXBlc1Rlc3QkSHVtYW4AAAAAAClvcmcuYXBhY2hlLmF2cm8uZ2VuZXJpYy5HZW5lcmljRGF0YSRBcn" + "JheQEAAAArAClvcmcuYXBhY2hlLmF2cm8uZ2VuZXJpYy5HZW5lcmljRGF0YSRBcnJheQEAAAC2AFVvc" + "mcuYXBhY2hlLmZsaW5rLmFwaS5qYXZhLnR5cGV1dGlscy5ydW50aW1lLmtyeW8uU2VyaWFsaXplcnMk" + "RHVtbXlBdnJvUmVnaXN0ZXJlZENsYXNzAAAAAQBZb3JnLmFwYWNoZS5mbGluay5hcGkuamF2YS50eXB" + "ldXRpbHMucnVudGltZS5rcnlvLlNlcmlhbGl6ZXJzJER1bW15QXZyb0tyeW9TZXJpYWxpemVyQ2xhc3" + "MAAATyxpo9cAAAAAAAAATyxpo9cAAAAAA=')", "ANY('org.apache.flink.table.types.LogicalTypesTest$Human', '...')", new Class[]{Human.class, User.class}, // every User is Human new Class[]{Human.class}, new LogicalType[]{}, new AnyType<>(User.class, new KryoSerializer<>(User.class, new ExecutionConfig())) ); }
Example #21
Source File: StateDescriptorPassingTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
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); }
Example #22
Source File: KryoSerializerRegistrationsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a Kryo serializer and writes the default registrations out to a * comma separated file with one entry per line: * * <pre> * id,class * </pre> * * <p>The produced file is used to check that the registered IDs don't change * in future Flink versions. * * <p>This method is not used in the tests, but documents how the test file * has been created and can be used to re-create it if needed. * * @param filePath File path to write registrations to */ private void writeDefaultKryoRegistrations(String filePath) throws IOException { final File file = new File(filePath); if (file.exists()) { assertTrue(file.delete()); } final Kryo kryo = new KryoSerializer<>(Integer.class, new ExecutionConfig()).getKryo(); final int nextId = kryo.getNextRegistrationId(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (int i = 0; i < nextId; i++) { Registration registration = kryo.getRegistration(i); String str = registration.getId() + "," + registration.getType().getName(); writer.write(str, 0, str.length()); writer.newLine(); } System.out.println("Created file with registrations at " + file.getAbsolutePath()); } }
Example #23
Source File: ListStateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
/** * FLINK-6775. * * <p>Tests that the returned serializer is duplicated. This allows to * share the state descriptor. */ @Test public void testSerializerDuplication() { // we need a serializer that actually duplicates for testing (a stateful one) // we use Kryo here, because it meets these conditions TypeSerializer<String> statefulSerializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ListStateDescriptor<String> descr = new ListStateDescriptor<>("foobar", statefulSerializer); TypeSerializer<String> serializerA = descr.getElementSerializer(); TypeSerializer<String> serializerB = descr.getElementSerializer(); // check that the retrieved serializers are not the same assertNotSame(serializerA, serializerB); TypeSerializer<List<String>> listSerializerA = descr.getSerializer(); TypeSerializer<List<String>> listSerializerB = descr.getSerializer(); assertNotSame(listSerializerA, listSerializerB); }
Example #24
Source File: StreamingRuntimeContextTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example #25
Source File: StreamingRuntimeContextTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example #26
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testValueStateInstantiation() throws Exception { final ExecutionConfig config = new ExecutionConfig(); config.registerKryoType(Path.class); final AtomicReference<Object> descriptorCapture = new AtomicReference<>(); StreamingRuntimeContext context = createRuntimeContext(descriptorCapture, config); 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); }
Example #27
Source File: ListStateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
/** * FLINK-6775. * * <p>Tests that the returned serializer is duplicated. This allows to * share the state descriptor. */ @Test public void testSerializerDuplication() { // we need a serializer that actually duplicates for testing (a stateful one) // we use Kryo here, because it meets these conditions TypeSerializer<String> statefulSerializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ListStateDescriptor<String> descr = new ListStateDescriptor<>("foobar", statefulSerializer); TypeSerializer<String> serializerA = descr.getElementSerializer(); TypeSerializer<String> serializerB = descr.getElementSerializer(); // check that the retrieved serializers are not the same assertNotSame(serializerA, serializerB); TypeSerializer<List<String>> listSerializerA = descr.getSerializer(); TypeSerializer<List<String>> listSerializerB = descr.getSerializer(); assertNotSame(listSerializerA, listSerializerB); }
Example #28
Source File: ListStateDescriptorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testListStateDescriptor() throws Exception { TypeSerializer<String> serializer = new KryoSerializer<>(String.class, new ExecutionConfig()); ListStateDescriptor<String> descr = new ListStateDescriptor<>("testName", serializer); assertEquals("testName", descr.getName()); assertNotNull(descr.getSerializer()); assertTrue(descr.getSerializer() instanceof ListSerializer); assertNotNull(descr.getElementSerializer()); assertEquals(serializer, descr.getElementSerializer()); ListStateDescriptor<String> copy = CommonTestUtils.createCopySerializable(descr); assertEquals("testName", copy.getName()); assertNotNull(copy.getSerializer()); assertTrue(copy.getSerializer() instanceof ListSerializer); assertNotNull(copy.getElementSerializer()); assertEquals(serializer, copy.getElementSerializer()); }
Example #29
Source File: StreamingRuntimeContextTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testAggregatingStateInstantiation() throws Exception { final ExecutionConfig config = new ExecutionConfig(); config.registerKryoType(Path.class); final AtomicReference<Object> descriptorCapture = new AtomicReference<>(); StreamingRuntimeContext context = createRuntimeContext(descriptorCapture, config); @SuppressWarnings("unchecked") AggregateFunction<String, TaskInfo, String> aggregate = (AggregateFunction<String, TaskInfo, String>) mock(AggregateFunction.class); AggregatingStateDescriptor<String, TaskInfo, String> descr = new AggregatingStateDescriptor<>("name", aggregate, TaskInfo.class); context.getAggregatingState(descr); AggregatingStateDescriptor<?, ?, ?> descrIntercepted = (AggregatingStateDescriptor<?, ?, ?>) 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); }
Example #30
Source File: GenericTypeInfo.java From flink with Apache License 2.0 | 5 votes |
@Override @PublicEvolving public TypeSerializer<T> createSerializer(ExecutionConfig config) { if (config.hasGenericTypesDisabled()) { throw new UnsupportedOperationException( "Generic types have been disabled in the ExecutionConfig and type " + this.typeClass.getName() + " is treated as a generic type."); } return new KryoSerializer<T>(this.typeClass, config); }