Java Code Examples for org.apache.flink.api.java.ExecutionEnvironment#registerTypeWithKryoSerializer()

The following examples show how to use org.apache.flink.api.java.ExecutionEnvironment#registerTypeWithKryoSerializer() . 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: RegisterTypeWithKryoSerializerITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the kryo serializer is forwarded via the ExecutionConfig.
 * @throws Exception
 */
@Test
public void testRegisterTypeWithKryoSerializer() throws Exception {
	int numElements = 10;
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.registerTypeWithKryoSerializer(TestClass.class, new TestClassSerializer());

	DataSet<Long> input = env.generateSequence(0, numElements - 1);

	DataSet<TestClass> mapped = input.map(new MapFunction<Long, TestClass>() {
		private static final long serialVersionUID = -529116076312998262L;

		@Override
		public TestClass map(Long value) throws Exception {
			return new TestClass(value);
		}
	});

	List<TestClass> expected = new ArrayList<>(numElements);

	for (int i = 0; i < numElements; i++) {
		expected.add(new TestClass(42));
	}

	compareResultCollections(expected, mapped.collect(), new Comparator<TestClass>() {
		@Override
		public int compare(TestClass o1, TestClass o2) {
			return (int) (o1.getValue() - o2.getValue());
		}
	});
}
 
Example 2
Source File: RegisterTypeWithKryoSerializerITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the kryo serializer is forwarded via the ExecutionConfig.
 * @throws Exception
 */
@Test
public void testRegisterTypeWithKryoSerializer() throws Exception {
	int numElements = 10;
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.registerTypeWithKryoSerializer(TestClass.class, new TestClassSerializer());

	DataSet<Long> input = env.generateSequence(0, numElements - 1);

	DataSet<TestClass> mapped = input.map(new MapFunction<Long, TestClass>() {
		private static final long serialVersionUID = -529116076312998262L;

		@Override
		public TestClass map(Long value) throws Exception {
			return new TestClass(value);
		}
	});

	List<TestClass> expected = new ArrayList<>(numElements);

	for (int i = 0; i < numElements; i++) {
		expected.add(new TestClass(42));
	}

	compareResultCollections(expected, mapped.collect(), new Comparator<TestClass>() {
		@Override
		public int compare(TestClass o1, TestClass o2) {
			return (int) (o1.getValue() - o2.getValue());
		}
	});
}
 
Example 3
Source File: RegisterTypeWithKryoSerializerITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the kryo serializer is forwarded via the ExecutionConfig.
 * @throws Exception
 */
@Test
public void testRegisterTypeWithKryoSerializer() throws Exception {
	int numElements = 10;
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.registerTypeWithKryoSerializer(TestClass.class, new TestClassSerializer());

	DataSet<Long> input = env.generateSequence(0, numElements - 1);

	DataSet<TestClass> mapped = input.map(new MapFunction<Long, TestClass>() {
		private static final long serialVersionUID = -529116076312998262L;

		@Override
		public TestClass map(Long value) throws Exception {
			return new TestClass(value);
		}
	});

	List<TestClass> expected = new ArrayList<>(numElements);

	for (int i = 0; i < numElements; i++) {
		expected.add(new TestClass(42));
	}

	compareResultCollections(expected, mapped.collect(), new Comparator<TestClass>() {
		@Override
		public int compare(TestClass o1, TestClass o2) {
			return (int) (o1.getValue() - o2.getValue());
		}
	});
}