/** * Creates a new MessageAcknowledgingSourceBase for IDs of the given type. * * @param idClass The class of the message ID type, used to create a serializer for the message IDs. */ protected MessageAcknowledgingSourceBase(Class<UId> idClass) { this(TypeExtractor.getForClass(idClass)); }
@Override public TypeInformation<ObjectNode> getProducedType() { return getForClass(ObjectNode.class); } }
@Override protected PojoTypeInfo<?>[] getTestData() { return new PojoTypeInfo<?>[] { (PojoTypeInfo<?>) TypeExtractor.getForClass(TestPojo.class), (PojoTypeInfo<?>) TypeExtractor.getForClass(AlternatePojo.class), (PojoTypeInfo<?>) TypeExtractor.getForClass(PrimitivePojo.class), (PojoTypeInfo<?>) TypeExtractor.getForClass(UnderscorePojo.class) }; }
@SuppressWarnings("unchecked") @Override public TypeInformation<Tuple2<KEYOUT, VALUEOUT>> getProducedType() { Class<KEYOUT> outKeyClass = (Class<KEYOUT>) TypeExtractor.getParameterType(Reducer.class, reducer.getClass(), 2); Class<VALUEOUT> outValClass = (Class<VALUEOUT>) TypeExtractor.getParameterType(Reducer.class, reducer.getClass(), 3); final TypeInformation<KEYOUT> keyTypeInfo = TypeExtractor.getForClass(outKeyClass); final TypeInformation<VALUEOUT> valueTypleInfo = TypeExtractor.getForClass(outValClass); return new TupleTypeInfo<>(keyTypeInfo, valueTypleInfo); }
@SuppressWarnings("unchecked") @Override public TypeInformation<Tuple2<KEYOUT, VALUEOUT>> getProducedType() { Class<KEYOUT> outKeyClass = (Class<KEYOUT>) TypeExtractor.getParameterType(Mapper.class, mapper.getClass(), 2); Class<VALUEOUT> outValClass = (Class<VALUEOUT>) TypeExtractor.getParameterType(Mapper.class, mapper.getClass(), 3); final TypeInformation<KEYOUT> keyTypeInfo = TypeExtractor.getForClass((Class<KEYOUT>) outKeyClass); final TypeInformation<VALUEOUT> valueTypleInfo = TypeExtractor.getForClass((Class<VALUEOUT>) outValClass); return new TupleTypeInfo<Tuple2<KEYOUT, VALUEOUT>>(keyTypeInfo, valueTypleInfo); }
@SuppressWarnings("unchecked") @Override public TypeInformation<Tuple2<KEYOUT, VALUEOUT>> getProducedType() { Class<KEYOUT> outKeyClass = (Class<KEYOUT>) TypeExtractor.getParameterType(Reducer.class, reducer.getClass(), 2); Class<VALUEOUT> outValClass = (Class<VALUEOUT>) TypeExtractor.getParameterType(Reducer.class, reducer.getClass(), 3); final TypeInformation<KEYOUT> keyTypeInfo = TypeExtractor.getForClass((Class<KEYOUT>) outKeyClass); final TypeInformation<VALUEOUT> valueTypleInfo = TypeExtractor.getForClass((Class<VALUEOUT>) outValClass); return new TupleTypeInfo<Tuple2<KEYOUT, VALUEOUT>>(keyTypeInfo, valueTypleInfo); }
@Override protected EitherTypeInfo<?, ?>[] getTestData() { return new EitherTypeInfo<?, ?>[] { new EitherTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO), new EitherTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, new TupleTypeInfo<Tuple2<Double, Long>>(TypeExtractor.getForClass(Double.class), TypeExtractor.getForClass(String.class))) }; } }
@Test public void testNestedPojoTypeExtraction() { TypeInformation<NestedPojoOuter> type = TypeExtractor.getForClass(NestedPojoOuter.class); assertTrue("Extracted type is not a Pojo type but should be.", type instanceof CompositeType); }
@Test public void testRecursivePojoTypeExtraction() { // This one tests whether a recursive pojo is detected using the set of visited // types in the type extractor. The recursive field will be handled using the generic serializer. TypeInformation<Recursive1Pojo> type = TypeExtractor.getForClass(Recursive1Pojo.class); assertTrue("Extracted type is not a Pojo type but should be.", type instanceof CompositeType); }
@Test(expected = InvalidProgramException.class) public void testTupleNonKeyField() { // selected field is not a key type TypeInformation<Tuple3<String, Long, GenericNonKeyType>> ti = new TupleTypeInfo<>( BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO, TypeExtractor.getForClass(GenericNonKeyType.class) ); new ExpressionKeys<>(2, ti); }
@Test(expected = Keys.IncompatibleKeysException.class) public void testAreCompatible7() throws Keys.IncompatibleKeysException { TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class); TypeInformation<Tuple2<String, Long>> t2 = new TupleTypeInfo<>( BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO ); ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>(new String[]{"a", "b"}, t1); ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(0, t2); ek1.areCompatible(ek2); }
@Test public void testStringArray() { String[][] array = new String[][]{{null,"b"},{"c","d"},{"e","f"},{"g","h"},null}; TypeInformation<String[][]> ti = TypeExtractor.getForClass(String[][].class); SerializerTestInstance<String[][]> testInstance = new SerializerTestInstance<String[][]>(ti.createSerializer(new ExecutionConfig()), String[][].class, -1, array); testInstance.testAll(); }
@Test public void testPrimitiveArray() { int[][] array = new int[][]{{12,1},{48,42},{23,80},{484,849},{987,4}}; TypeInformation<int[][]> ti = TypeExtractor.getForClass(int[][].class); SerializerTestInstance<int[][]> testInstance = new SerializerTestInstance<int[][]>(ti.createSerializer(new ExecutionConfig()), int[][].class, -1, array); testInstance.testAll(); }
@Test public void testLombokPojo() { TypeInformation<TestLombok> ti = TypeExtractor.getForClass(TestLombok.class); Assert.assertTrue(ti instanceof PojoTypeInfo); PojoTypeInfo<TestLombok> pti = (PojoTypeInfo<TestLombok>) ti; Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, pti.getTypeAt(0)); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, pti.getTypeAt(1)); } }
@Test public void testObjectArrays() { Integer[][] array = new Integer[][]{{0,1}, null, {null, 42}}; TypeInformation<Integer[][]> ti = TypeExtractor.getForClass(Integer[][].class); SerializerTestInstance<Integer[][]> testInstance = new SerializerTestInstance<Integer[][]>(ti.createSerializer(new ExecutionConfig()), Integer[][].class, -1, array); testInstance.testAll(); MyPojo[][] array2 = new MyPojo[][]{{new MyPojo(null, 42), new MyPojo("test2", -1)}, {null, null}, null}; TypeInformation<MyPojo[][]> ti2 = TypeExtractor.getForClass(MyPojo[][].class); SerializerTestInstance<MyPojo[][]> testInstance2 = new SerializerTestInstance<MyPojo[][]>(ti2.createSerializer(new ExecutionConfig()), MyPojo[][].class, -1, array2); testInstance2.testAll(); }
@Test public void testAreCompatible1() throws Keys.IncompatibleKeysException { TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class); ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1); ExpressionKeys<Pojo1> ek2 = new ExpressionKeys<>("b", t1); Assert.assertTrue(ek1.areCompatible(ek2)); Assert.assertTrue(ek2.areCompatible(ek1)); }
@Test public void testAreCompatible3() throws Keys.IncompatibleKeysException { TypeInformation<String> t1 = BasicTypeInfo.STRING_TYPE_INFO; TypeInformation<Pojo2> t2 = TypeExtractor.getForClass(Pojo2.class); Keys.ExpressionKeys<String> ek1 = new Keys.ExpressionKeys<>("*", t1); Keys<Pojo2> sk2 = new Keys.SelectorFunctionKeys<>( new KeySelector1(), t2, BasicTypeInfo.STRING_TYPE_INFO ); Assert.assertTrue(sk2.areCompatible(ek1)); }
@Test public void testSimpleType() { TypeInformation<?> ti = TypeExtractor.createTypeInfo(IntLike.class); assertEquals(INT_TYPE_INFO, ti); ti = TypeExtractor.getForClass(IntLike.class); assertEquals(INT_TYPE_INFO, ti); ti = TypeExtractor.getForObject(new IntLike()); assertEquals(INT_TYPE_INFO, ti); }
@Test public void testAreCompatible5() throws Keys.IncompatibleKeysException { TypeInformation<PojoWithMultiplePojos> t1 = TypeExtractor.getForClass(PojoWithMultiplePojos.class); TypeInformation<Tuple2<String, String>> t2 = new TupleTypeInfo<>( BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO ); ExpressionKeys<PojoWithMultiplePojos> ek1 = new ExpressionKeys<>(new String[]{"p1.b", "p2.a2"}, t1); ExpressionKeys<Tuple2<String, String>> ek2 = new ExpressionKeys<>("*", t2); Assert.assertTrue(ek1.areCompatible(ek2)); Assert.assertTrue(ek2.areCompatible(ek1)); }
@Test public void testAreCompatible2() throws Keys.IncompatibleKeysException { TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class); TypeInformation<Tuple2<String, Long>> t2 = new TupleTypeInfo<>( BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO ); ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1); ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(0, t2); Assert.assertTrue(ek1.areCompatible(ek2)); Assert.assertTrue(ek2.areCompatible(ek1)); }