http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/CompositeTypeTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/CompositeTypeTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/CompositeTypeTest.java deleted file mode 100644 index cd405bc..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/CompositeTypeTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import static org.junit.Assert.*; - -import org.apache.flink.api.common.typeinfo.BasicTypeInfo; -import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.api.java.tuple.Tuple3; -import org.apache.flink.api.java.tuple.Tuple4; -import org.junit.Test; - -public class CompositeTypeTest { - - private final TupleTypeInfo<?> tupleTypeInfo = new TupleTypeInfo<Tuple4<Integer, Integer, Integer, Integer>>( - BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO); - - - private final TupleTypeInfo<Tuple3<Integer, String, Long>> inNestedTuple1 = new TupleTypeInfo<Tuple3<Integer, String, Long>>( - BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO); - - private final TupleTypeInfo<Tuple2<Double, Double>> inNestedTuple2 = new TupleTypeInfo<Tuple2<Double, Double>>( - BasicTypeInfo.DOUBLE_TYPE_INFO, BasicTypeInfo.DOUBLE_TYPE_INFO); - - private final TupleTypeInfo<?> nestedTypeInfo = new TupleTypeInfo<Tuple4<Integer, Tuple3<Integer, String, Long>, Integer, Tuple2<Double, Double>>>( - BasicTypeInfo.INT_TYPE_INFO, - inNestedTuple1, - BasicTypeInfo.INT_TYPE_INFO, - inNestedTuple2); - - private final TupleTypeInfo<Tuple2<Integer, Tuple2<Integer, Integer>>> inNestedTuple3 = new TupleTypeInfo<Tuple2<Integer, Tuple2<Integer, Integer>>>( - BasicTypeInfo.INT_TYPE_INFO, - new TupleTypeInfo<Tuple2<Integer, Integer>>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO)); - - private final TupleTypeInfo<?> deepNestedTupleTypeInfo = new TupleTypeInfo<Tuple3<Integer, Tuple2<Integer, Tuple2<Integer, Integer>>, Integer>>( - BasicTypeInfo.INT_TYPE_INFO, - inNestedTuple3, - BasicTypeInfo.INT_TYPE_INFO ); - - private final PojoTypeInfo<?> pojoTypeInfo = ((PojoTypeInfo<?>) TypeExtractor.getForClass - (MyPojo.class)); - - private final TupleTypeInfo<?> pojoInTupleTypeInfo = new TupleTypeInfo<Tuple2<Integer, MyPojo>>(BasicTypeInfo.INT_TYPE_INFO, pojoTypeInfo); - - @Test - public void testGetFlatFields() { - assertEquals(0, tupleTypeInfo.getFlatFields("0").get(0).getPosition()); - assertEquals(1, tupleTypeInfo.getFlatFields("1").get(0).getPosition()); - assertEquals(2, tupleTypeInfo.getFlatFields("2").get(0).getPosition()); - assertEquals(3, tupleTypeInfo.getFlatFields("3").get(0).getPosition()); - assertEquals(0, tupleTypeInfo.getFlatFields("f0").get(0).getPosition()); - assertEquals(1, tupleTypeInfo.getFlatFields("f1").get(0).getPosition()); - assertEquals(2, tupleTypeInfo.getFlatFields("f2").get(0).getPosition()); - assertEquals(3, tupleTypeInfo.getFlatFields("f3").get(0).getPosition()); - - assertEquals(0, nestedTypeInfo.getFlatFields("0").get(0).getPosition()); - assertEquals(1, nestedTypeInfo.getFlatFields("1.0").get(0).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("1.1").get(0).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("1.2").get(0).getPosition()); - assertEquals(4, nestedTypeInfo.getFlatFields("2").get(0).getPosition()); - assertEquals(5, nestedTypeInfo.getFlatFields("3.0").get(0).getPosition()); - assertEquals(6, nestedTypeInfo.getFlatFields("3.1").get(0).getPosition()); - assertEquals(4, nestedTypeInfo.getFlatFields("f2").get(0).getPosition()); - assertEquals(5, nestedTypeInfo.getFlatFields("f3.f0").get(0).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("1").size()); - assertEquals(1, nestedTypeInfo.getFlatFields("1").get(0).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("1").get(1).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("1").get(2).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("1.*").size()); - assertEquals(1, nestedTypeInfo.getFlatFields("1.*").get(0).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("1.*").get(1).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("1.*").get(2).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("3").size()); - assertEquals(5, nestedTypeInfo.getFlatFields("3").get(0).getPosition()); - assertEquals(6, nestedTypeInfo.getFlatFields("3").get(1).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("f1").size()); - assertEquals(1, nestedTypeInfo.getFlatFields("f1").get(0).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("f1").get(1).getPosition()); - assertEquals(3, nestedTypeInfo.getFlatFields("f1").get(2).getPosition()); - assertEquals(2, nestedTypeInfo.getFlatFields("f3").size()); - assertEquals(5, nestedTypeInfo.getFlatFields("f3").get(0).getPosition()); - assertEquals(6, nestedTypeInfo.getFlatFields("f3").get(1).getPosition()); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, - nestedTypeInfo.getFlatFields("0").get(0).getType()); - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, - nestedTypeInfo.getFlatFields("1.1").get(0).getType()); - assertEquals(BasicTypeInfo.LONG_TYPE_INFO, - nestedTypeInfo.getFlatFields("1").get(2).getType()); - assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, - nestedTypeInfo.getFlatFields("3").get(1).getType()); - - assertEquals(3, deepNestedTupleTypeInfo.getFlatFields("1").size()); - assertEquals(1, deepNestedTupleTypeInfo.getFlatFields("1").get(0).getPosition()); - assertEquals(2, deepNestedTupleTypeInfo.getFlatFields("1").get(1).getPosition()); - assertEquals(3, deepNestedTupleTypeInfo.getFlatFields("1").get(2).getPosition()); - assertEquals(5, deepNestedTupleTypeInfo.getFlatFields("*").size()); - assertEquals(0, deepNestedTupleTypeInfo.getFlatFields("*").get(0).getPosition()); - assertEquals(1, deepNestedTupleTypeInfo.getFlatFields("*").get(1).getPosition()); - assertEquals(2, deepNestedTupleTypeInfo.getFlatFields("*").get(2).getPosition()); - assertEquals(3, deepNestedTupleTypeInfo.getFlatFields("*").get(3).getPosition()); - assertEquals(4, deepNestedTupleTypeInfo.getFlatFields("*").get(4).getPosition()); - - assertEquals(0, pojoTypeInfo.getFlatFields("a").get(0).getPosition()); - assertEquals(1, pojoTypeInfo.getFlatFields("b").get(0).getPosition()); - assertEquals(2, pojoTypeInfo.getFlatFields("*").size()); - assertEquals(0, pojoTypeInfo.getFlatFields("*").get(0).getPosition()); - assertEquals(1, pojoTypeInfo.getFlatFields("*").get(1).getPosition()); - - assertEquals(1, pojoInTupleTypeInfo.getFlatFields("f1.a").get(0).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("1.b").get(0).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("1").size()); - assertEquals(1, pojoInTupleTypeInfo.getFlatFields("1.*").get(0).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("1").get(1).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("f1.*").size()); - assertEquals(1, pojoInTupleTypeInfo.getFlatFields("f1.*").get(0).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("f1").get(1).getPosition()); - assertEquals(3, pojoInTupleTypeInfo.getFlatFields("*").size()); - assertEquals(0, pojoInTupleTypeInfo.getFlatFields("*").get(0).getPosition()); - assertEquals(1, pojoInTupleTypeInfo.getFlatFields("*").get(1).getPosition()); - assertEquals(2, pojoInTupleTypeInfo.getFlatFields("*").get(2).getPosition()); - - } - - @Test - public void testFieldAtStringRef() { - - assertEquals(BasicTypeInfo.INT_TYPE_INFO, tupleTypeInfo.getTypeAt("0")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, tupleTypeInfo.getTypeAt("2")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, tupleTypeInfo.getTypeAt("f1")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, tupleTypeInfo.getTypeAt("f3")); - - assertEquals(BasicTypeInfo.INT_TYPE_INFO, nestedTypeInfo.getTypeAt("0")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, nestedTypeInfo.getTypeAt("1.0")); - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, nestedTypeInfo.getTypeAt("1.1")); - assertEquals(BasicTypeInfo.LONG_TYPE_INFO, nestedTypeInfo.getTypeAt("1.2")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, nestedTypeInfo.getTypeAt("2")); - assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, nestedTypeInfo.getTypeAt("3.0")); - assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, nestedTypeInfo.getTypeAt("3.1")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, nestedTypeInfo.getTypeAt("f2")); - assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, nestedTypeInfo.getTypeAt("f3.f0")); - assertEquals(inNestedTuple1, nestedTypeInfo.getTypeAt("1")); - assertEquals(inNestedTuple2, nestedTypeInfo.getTypeAt("3")); - assertEquals(inNestedTuple1, nestedTypeInfo.getTypeAt("f1")); - assertEquals(inNestedTuple2, nestedTypeInfo.getTypeAt("f3")); - - assertEquals(inNestedTuple3, deepNestedTupleTypeInfo.getTypeAt("1")); - - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, pojoTypeInfo.getTypeAt("a")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, pojoTypeInfo.getTypeAt("b")); - - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, pojoInTupleTypeInfo.getTypeAt("f1.a")); - assertEquals(BasicTypeInfo.INT_TYPE_INFO, pojoInTupleTypeInfo.getTypeAt("1.b")); - assertEquals(pojoTypeInfo, pojoInTupleTypeInfo.getTypeAt("1")); - assertEquals(pojoTypeInfo, pojoInTupleTypeInfo.getTypeAt("f1")); - - } - - public static class MyPojo { - public String a; - public int b; - } - -}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EitherTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EitherTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EitherTypeInfoTest.java deleted file mode 100644 index caa3402..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EitherTypeInfoTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import org.apache.flink.api.common.typeinfo.BasicTypeInfo; -import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.api.java.typeutils.Either.Right; -import org.apache.flink.util.TestLogger; -import org.junit.Test; - -public class EitherTypeInfoTest extends TestLogger { - - Either<Integer, String> intEither = Either.Left(1); - Either<Integer, String> stringEither = Either.Right("boo"); - Either<Integer, Tuple2<Double, Long>> tuple2Either = new Right<>(new Tuple2<Double, Long>(42.0, 2l)); - - @Test - public void testEitherTypeEquality() { - EitherTypeInfo<Integer, String> eitherInfo1 = new EitherTypeInfo<Integer, String>( - BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); - - EitherTypeInfo<Integer, String> eitherInfo2 = new EitherTypeInfo<Integer, String>( - BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); - - assertEquals(eitherInfo1, eitherInfo2); - assertEquals(eitherInfo1.hashCode(), eitherInfo2.hashCode()); - } - - @Test - public void testEitherTypeInEquality() { - EitherTypeInfo<Integer, String> eitherInfo1 = new EitherTypeInfo<Integer, String>( - BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); - - EitherTypeInfo<Integer, Tuple2<Double, Long>> eitherInfo2 = new EitherTypeInfo<Integer, Tuple2<Double, Long>>( - BasicTypeInfo.INT_TYPE_INFO, new TupleTypeInfo<Tuple2<Double, Long>>( - TypeExtractor.getForClass(Double.class), TypeExtractor.getForClass(String.class))); - - assertNotEquals(eitherInfo1, eitherInfo2); - assertNotEquals(eitherInfo1.hashCode(), eitherInfo2.hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EnumTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EnumTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EnumTypeInfoTest.java deleted file mode 100644 index b200566..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/EnumTypeInfoTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.util.TestLogger; -import org.junit.Test; -import static org.junit.Assert.*; - -public class EnumTypeInfoTest extends TestLogger { - - enum TestEnum { - ONE, TWO - } - - enum AlternativeEnum { - ONE, TWO - } - - @Test - public void testEnumTypeEquality() { - EnumTypeInfo<TestEnum> enumTypeInfo1 = new EnumTypeInfo<TestEnum>(TestEnum.class); - EnumTypeInfo<TestEnum> enumTypeInfo2 = new EnumTypeInfo<TestEnum>(TestEnum.class); - - assertEquals(enumTypeInfo1, enumTypeInfo2); - assertEquals(enumTypeInfo1.hashCode(), enumTypeInfo2.hashCode()); - } - - @Test - public void testEnumTypeInequality() { - EnumTypeInfo<TestEnum> enumTypeInfo1 = new EnumTypeInfo<TestEnum>(TestEnum.class); - EnumTypeInfo<AlternativeEnum> enumTypeInfo2 = new EnumTypeInfo<AlternativeEnum>(AlternativeEnum.class); - - assertNotEquals(enumTypeInfo1, enumTypeInfo2); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/GenericTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/GenericTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/GenericTypeInfoTest.java deleted file mode 100644 index fad43df..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/GenericTypeInfoTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.util.TestLogger; -import org.junit.Test; -import static org.junit.Assert.*; - -public class GenericTypeInfoTest extends TestLogger { - - static class TestClass {} - static class AlternativeClass {} - - @Test - public void testGenericTypeInfoEquality() { - GenericTypeInfo<TestClass> tpeInfo1 = new GenericTypeInfo<>(TestClass.class); - GenericTypeInfo<TestClass> tpeInfo2 = new GenericTypeInfo<>(TestClass.class); - - assertEquals(tpeInfo1, tpeInfo2); - assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); - } - - @Test - public void testGenericTypeInfoInequality() { - GenericTypeInfo<TestClass> tpeInfo1 = new GenericTypeInfo<>(TestClass.class); - GenericTypeInfo<AlternativeClass> tpeInfo2 = new GenericTypeInfo<>(AlternativeClass.class); - - assertNotEquals(tpeInfo1, tpeInfo2); - } - -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/MissingTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/MissingTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/MissingTypeInfoTest.java deleted file mode 100644 index ee57475..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/MissingTypeInfoTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.api.common.functions.InvalidTypesException; -import org.apache.flink.util.TestLogger; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class MissingTypeInfoTest extends TestLogger { - static final String functionName = "foobar"; - static final InvalidTypesException testException = new InvalidTypesException("Test exception."); - - @Test - public void testMissingTypeInfoEquality() { - MissingTypeInfo tpeInfo1 = new MissingTypeInfo(functionName, testException); - MissingTypeInfo tpeInfo2 = new MissingTypeInfo(functionName, testException); - - assertEquals(tpeInfo1, tpeInfo2); - assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); - } - - @Test - public void testMissingTypeInfoInequality() { - MissingTypeInfo tpeInfo1 = new MissingTypeInfo(functionName, testException); - MissingTypeInfo tpeInfo2 = new MissingTypeInfo("alt" + functionName, testException); - - assertNotEquals(tpeInfo1, tpeInfo2); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ObjectArrayTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ObjectArrayTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ObjectArrayTypeInfoTest.java deleted file mode 100644 index f3b39c0..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ObjectArrayTypeInfoTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.util.TestLogger; -import org.junit.Test; - -import java.util.ArrayList; - -import static org.junit.Assert.*; - -public class ObjectArrayTypeInfoTest extends TestLogger { - - public static class TestClass{} - - @Test - public void testObjectArrayTypeInfoEquality() { - ObjectArrayTypeInfo<TestClass[], TestClass> tpeInfo1 = ObjectArrayTypeInfo.getInfoFor( - TestClass[].class, - new GenericTypeInfo<TestClass>(TestClass.class)); - - ObjectArrayTypeInfo<TestClass[], TestClass> tpeInfo2 = ObjectArrayTypeInfo.getInfoFor( - TestClass[].class, - new GenericTypeInfo<TestClass>(TestClass.class)); - - assertEquals(tpeInfo1, tpeInfo2); - assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); - } - - @Test - public void testObjectArrayTypeInfoInequality() { - ObjectArrayTypeInfo<TestClass[], TestClass> tpeInfo1 = ObjectArrayTypeInfo.getInfoFor( - TestClass[].class, - new GenericTypeInfo<TestClass>(TestClass.class)); - - ObjectArrayTypeInfo<TestClass[], TestClass> tpeInfo2 = ObjectArrayTypeInfo.getInfoFor( - TestClass[].class, - new PojoTypeInfo<TestClass>(TestClass.class, new ArrayList<PojoField>())); - - assertNotEquals(tpeInfo1, tpeInfo2); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/PojoTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/PojoTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/PojoTypeInfoTest.java deleted file mode 100644 index dbe5115..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/PojoTypeInfoTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import static org.junit.Assert.*; - -import org.apache.flink.api.common.typeinfo.TypeInformation; -import org.apache.flink.util.InstantiationUtil; -import org.junit.Test; - -import java.io.IOException; - -public class PojoTypeInfoTest { - - @Test - public void testPojoTypeInfoEquality() { - try { - TypeInformation<TestPojo> info1 = TypeExtractor.getForClass(TestPojo.class); - TypeInformation<TestPojo> info2 = TypeExtractor.getForClass(TestPojo.class); - - assertTrue(info1 instanceof PojoTypeInfo); - assertTrue(info2 instanceof PojoTypeInfo); - - assertTrue(info1.equals(info2)); - assertTrue(info1.hashCode() == info2.hashCode()); - } - catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void testPojoTypeInfoInequality() { - try { - TypeInformation<TestPojo> info1 = TypeExtractor.getForClass(TestPojo.class); - TypeInformation<AlternatePojo> info2 = TypeExtractor.getForClass(AlternatePojo.class); - - assertTrue(info1 instanceof PojoTypeInfo); - assertTrue(info2 instanceof PojoTypeInfo); - - assertFalse(info1.equals(info2)); - } - catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void testSerializabilityOfPojoTypeInfo() throws IOException, ClassNotFoundException { - PojoTypeInfo<TestPojo> pojoTypeInfo = (PojoTypeInfo<TestPojo>)TypeExtractor.getForClass(TestPojo.class); - - byte[] serializedPojoTypeInfo = InstantiationUtil.serializeObject(pojoTypeInfo); - PojoTypeInfo<TestPojo> deserializedPojoTypeInfo = (PojoTypeInfo<TestPojo>)InstantiationUtil.deserializeObject( - serializedPojoTypeInfo, - getClass().getClassLoader()); - - assertEquals(pojoTypeInfo, deserializedPojoTypeInfo); - } - - @Test - public void testPrimitivePojo() { - TypeInformation<PrimitivePojo> info1 = TypeExtractor.getForClass(PrimitivePojo.class); - - assertTrue(info1 instanceof PojoTypeInfo); - } - - @Test - public void testUnderscorePojo() { - TypeInformation<UnderscorePojo> info1 = TypeExtractor.getForClass(UnderscorePojo.class); - - assertTrue(info1 instanceof PojoTypeInfo); - } - - public static final class TestPojo { - - public int someInt; - - private String aString; - - public Double[] doubleArray; - - - public void setaString(String aString) { - this.aString = aString; - } - - public String getaString() { - return aString; - } - } - - public static final class AlternatePojo { - - public int someInt; - - private String aString; - - public Double[] doubleArray; - - - public void setaString(String aString) { - this.aString = aString; - } - - public String getaString() { - return aString; - } - } - - public static final class PrimitivePojo { - - private int someInt; - - public void setSomeInt(Integer someInt) { - this.someInt = someInt; - } - - public Integer getSomeInt() { - return this.someInt; - } - } - - public static final class UnderscorePojo { - - private int some_int; - - public void setSomeInt(int some_int) { - this.some_int = some_int; - } - - public Integer getSomeInt() { - return this.some_int; - } - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TupleTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TupleTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TupleTypeInfoTest.java deleted file mode 100644 index b6cff34..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TupleTypeInfoTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.api.common.ExecutionConfig; -import org.apache.flink.api.common.typeinfo.BasicTypeInfo; -import org.apache.flink.api.common.typeinfo.TypeInformation; -import org.apache.flink.api.common.typeutils.TypeSerializer; -import org.apache.flink.api.java.tuple.Tuple1; -import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.util.TestLogger; -import org.junit.Assert; -import org.junit.Test; - -public class TupleTypeInfoTest extends TestLogger { - - @Test - public void testTupleTypeInfoSymmetricEqualityRelation() { - TupleTypeInfo<Tuple1<Integer>> tupleTypeInfo = new TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO); - - TupleTypeInfoBase<Tuple1> anonymousTupleTypeInfo = new TupleTypeInfoBase<Tuple1>( - (Class<Tuple1>)Tuple1.class, - (TypeInformation<?>)BasicTypeInfo.INT_TYPE_INFO) { - - private static final long serialVersionUID = -7985593598027660836L; - - @Override - public TypeSerializer<Tuple1> createSerializer(ExecutionConfig config) { - return null; - } - - @Override - protected TypeComparatorBuilder<Tuple1> createTypeComparatorBuilder() { - return null; - } - - @Override - public String[] getFieldNames() { - return new String[0]; - } - - @Override - public int getFieldIndex(String fieldName) { - return 0; - } - }; - - boolean tupleVsAnonymous = tupleTypeInfo.equals(anonymousTupleTypeInfo); - boolean anonymousVsTuple = anonymousTupleTypeInfo.equals(tupleTypeInfo); - - Assert.assertTrue("Equality relation should be symmetric", tupleVsAnonymous == anonymousVsTuple); - } - - @Test - public void testTupleTypeInfoEquality() { - TupleTypeInfo<Tuple2<Integer, String>> tupleTypeInfo1 = new TupleTypeInfo<>( - BasicTypeInfo.INT_TYPE_INFO, - BasicTypeInfo.STRING_TYPE_INFO); - - TupleTypeInfo<Tuple2<Integer, String>> tupleTypeInfo2 = new TupleTypeInfo<>( - BasicTypeInfo.INT_TYPE_INFO, - BasicTypeInfo.STRING_TYPE_INFO); - - Assert.assertEquals(tupleTypeInfo1, tupleTypeInfo2); - Assert.assertEquals(tupleTypeInfo1.hashCode(), tupleTypeInfo2.hashCode()); - } - - @Test - public void testTupleTypeInfoInequality() { - TupleTypeInfo<Tuple2<Integer, String>> tupleTypeInfo1 = new TupleTypeInfo<>( - BasicTypeInfo.INT_TYPE_INFO, - BasicTypeInfo.STRING_TYPE_INFO); - - TupleTypeInfo<Tuple2<Integer, Boolean>> tupleTypeInfo2 = new TupleTypeInfo<>( - BasicTypeInfo.INT_TYPE_INFO, - BasicTypeInfo.BOOLEAN_TYPE_INFO); - - Assert.assertNotEquals(tupleTypeInfo1, tupleTypeInfo2); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TypeInfoParserTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TypeInfoParserTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TypeInfoParserTest.java deleted file mode 100644 index e225460..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/TypeInfoParserTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import org.junit.Assert; -import org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo; -import org.apache.flink.api.common.typeinfo.BasicTypeInfo; -import org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo; -import org.apache.flink.api.common.typeinfo.TypeInformation; -import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.types.BooleanValue; -import org.apache.flink.types.ByteValue; -import org.apache.flink.types.CharValue; -import org.apache.flink.types.DoubleValue; -import org.apache.flink.types.FloatValue; -import org.apache.flink.types.IntValue; -import org.apache.flink.types.ListValue; -import org.apache.flink.types.LongValue; -import org.apache.flink.types.MapValue; -import org.apache.flink.types.NullValue; -import org.apache.flink.types.ShortValue; -import org.apache.flink.types.StringValue; -import org.apache.hadoop.io.Writable; -import org.junit.Test; - -public class TypeInfoParserTest { - - @Test - public void testBasicTypes() { - Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, TypeInfoParser.parse("Integer")); - Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, TypeInfoParser.parse("Double")); - Assert.assertEquals(BasicTypeInfo.BYTE_TYPE_INFO, TypeInfoParser.parse("Byte")); - Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, TypeInfoParser.parse("Float")); - Assert.assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, TypeInfoParser.parse("Short")); - Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, TypeInfoParser.parse("Long")); - Assert.assertEquals(BasicTypeInfo.CHAR_TYPE_INFO, TypeInfoParser.parse("Character")); - Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInfoParser.parse("String")); - Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, TypeInfoParser.parse("Boolean")); - Assert.assertEquals(BasicTypeInfo.VOID_TYPE_INFO, TypeInfoParser.parse("Void")); - Assert.assertEquals(BasicTypeInfo.DATE_TYPE_INFO, TypeInfoParser.parse("Date")); - - Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, TypeInfoParser.parse("java.lang.Integer")); - Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, TypeInfoParser.parse("java.lang.Double")); - Assert.assertEquals(BasicTypeInfo.BYTE_TYPE_INFO, TypeInfoParser.parse("java.lang.Byte")); - Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, TypeInfoParser.parse("java.lang.Float")); - Assert.assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, TypeInfoParser.parse("java.lang.Short")); - Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, TypeInfoParser.parse("java.lang.Long")); - Assert.assertEquals(BasicTypeInfo.CHAR_TYPE_INFO, TypeInfoParser.parse("java.lang.Character")); - Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInfoParser.parse("java.lang.String")); - Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, TypeInfoParser.parse("java.lang.Boolean")); - Assert.assertEquals(BasicTypeInfo.VOID_TYPE_INFO, TypeInfoParser.parse("java.lang.Void")); - Assert.assertEquals(BasicTypeInfo.DATE_TYPE_INFO, TypeInfoParser.parse("java.util.Date")); - - Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, TypeInfoParser.parse("int")); - Assert.assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, TypeInfoParser.parse("double")); - Assert.assertEquals(BasicTypeInfo.BYTE_TYPE_INFO, TypeInfoParser.parse("byte")); - Assert.assertEquals(BasicTypeInfo.FLOAT_TYPE_INFO, TypeInfoParser.parse("float")); - Assert.assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, TypeInfoParser.parse("short")); - Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, TypeInfoParser.parse("long")); - Assert.assertEquals(BasicTypeInfo.CHAR_TYPE_INFO, TypeInfoParser.parse("char")); - Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, TypeInfoParser.parse("boolean")); - Assert.assertEquals(BasicTypeInfo.VOID_TYPE_INFO, TypeInfoParser.parse("void")); - } - - @Test - public void testValueTypes() { - helperValueType("StringValue", StringValue.class); - helperValueType("IntValue", IntValue.class); - helperValueType("ByteValue", ByteValue.class); - helperValueType("ShortValue", ShortValue.class); - helperValueType("CharValue", CharValue.class); - helperValueType("DoubleValue", DoubleValue.class); - helperValueType("FloatValue", FloatValue.class); - helperValueType("LongValue", LongValue.class); - helperValueType("BooleanValue", BooleanValue.class); - helperValueType("ListValue", ListValue.class); - helperValueType("MapValue", MapValue.class); - helperValueType("NullValue", NullValue.class); - } - - private static void helperValueType(String str, Class<?> clazz) { - TypeInformation<?> ti = TypeInfoParser.parse(str); - Assert.assertTrue(ti instanceof ValueTypeInfo); - ValueTypeInfo<?> vti = (ValueTypeInfo<?>) ti; - Assert.assertEquals(clazz, vti.getTypeClass()); - } - - @Test - public void testBasicArrays() { - Assert.assertEquals(BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, TypeInfoParser.parse("Integer[]")); - Assert.assertEquals(BasicArrayTypeInfo.DOUBLE_ARRAY_TYPE_INFO, TypeInfoParser.parse("Double[]")); - Assert.assertEquals(BasicArrayTypeInfo.BYTE_ARRAY_TYPE_INFO, TypeInfoParser.parse("Byte[]")); - Assert.assertEquals(BasicArrayTypeInfo.FLOAT_ARRAY_TYPE_INFO, TypeInfoParser.parse("Float[]")); - Assert.assertEquals(BasicArrayTypeInfo.SHORT_ARRAY_TYPE_INFO, TypeInfoParser.parse("Short[]")); - Assert.assertEquals(BasicArrayTypeInfo.LONG_ARRAY_TYPE_INFO, TypeInfoParser.parse("Long[]")); - Assert.assertEquals(BasicArrayTypeInfo.CHAR_ARRAY_TYPE_INFO, TypeInfoParser.parse("Character[]")); - Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, TypeInfoParser.parse("String[]")); - Assert.assertEquals(BasicArrayTypeInfo.BOOLEAN_ARRAY_TYPE_INFO, TypeInfoParser.parse("Boolean[]")); - - Assert.assertEquals(BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Integer[]")); - Assert.assertEquals(BasicArrayTypeInfo.DOUBLE_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Double[]")); - Assert.assertEquals(BasicArrayTypeInfo.BYTE_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Byte[]")); - Assert.assertEquals(BasicArrayTypeInfo.FLOAT_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Float[]")); - Assert.assertEquals(BasicArrayTypeInfo.SHORT_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Short[]")); - Assert.assertEquals(BasicArrayTypeInfo.LONG_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Long[]")); - Assert.assertEquals(BasicArrayTypeInfo.CHAR_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Character[]")); - Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.String[]")); - Assert.assertEquals(BasicArrayTypeInfo.BOOLEAN_ARRAY_TYPE_INFO, TypeInfoParser.parse("java.lang.Boolean[]")); - - Assert.assertEquals(PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("int[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("double[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("byte[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("float[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("short[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("long[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("char[]")); - Assert.assertEquals(PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO, TypeInfoParser.parse("boolean[]")); - } - - @Test - public void testTuples() { - TypeInformation<?> ti = TypeInfoParser.parse("Tuple2<Integer, Long>"); - Assert.assertEquals(2, ti.getArity()); - Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, ((TupleTypeInfo<?>)ti).getTypeAt(0)); - Assert.assertEquals(BasicTypeInfo.LONG_TYPE_INFO, ((TupleTypeInfo<?>)ti).getTypeAt(1)); - - ti = TypeInfoParser.parse("Tuple0"); - Assert.assertEquals(0, ti.getArity()); - Assert.assertEquals("Java Tuple0", ti.toString()); - - ti = TypeInfoParser.parse("org.apache.flink.api.java.tuple.Tuple0"); - Assert.assertEquals(0, ti.getArity()); - Assert.assertEquals("Java Tuple0", ti.toString()); - - ti = TypeInfoParser.parse("Tuple3<Tuple1<String>, Tuple1<Integer>, Tuple2<Long, Long>>"); - Assert.assertEquals("Java Tuple3<Java Tuple1<String>, Java Tuple1<Integer>, Java Tuple2<Long, Long>>", ti.toString()); - } - - @Test - public void testGenericType() { - TypeInformation<?> ti = TypeInfoParser.parse("java.lang.Class"); - Assert.assertTrue(ti instanceof GenericTypeInfo); - Assert.assertEquals(Class.class, ((GenericTypeInfo<?>) ti).getTypeClass()); - } - - public static class MyPojo { - public Integer basic; - public Tuple2<String, Integer> tuple; - public MyWritable hadoopCitizen; - public String[] array; - } - - @Test - public void testPojoType() { - TypeInformation<?> ti = TypeInfoParser.parse( - "org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyPojo<" - + "basic=Integer," - + "tuple=Tuple2<String, Integer>," - + "hadoopCitizen=Writable<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyWritable>," - + "array=String[]" - + ">"); - Assert.assertTrue(ti instanceof PojoTypeInfo); - PojoTypeInfo<?> pti = (PojoTypeInfo<?>) ti; - Assert.assertEquals("array", pti.getPojoFieldAt(0).getField().getName()); - Assert.assertTrue(pti.getPojoFieldAt(0).getTypeInformation() instanceof BasicArrayTypeInfo); - Assert.assertEquals("basic", pti.getPojoFieldAt(1).getField().getName()); - Assert.assertTrue(pti.getPojoFieldAt(1).getTypeInformation() instanceof BasicTypeInfo); - Assert.assertEquals("hadoopCitizen", pti.getPojoFieldAt(2).getField().getName()); - Assert.assertTrue(pti.getPojoFieldAt(2).getTypeInformation() instanceof WritableTypeInfo); - Assert.assertEquals("tuple", pti.getPojoFieldAt(3).getField().getName()); - Assert.assertTrue(pti.getPojoFieldAt(3).getTypeInformation() instanceof TupleTypeInfo); - } - - @Test - public void testPojoType2() { - TypeInformation<?> ti = TypeInfoParser.parse("Tuple2<String,Tuple2<Integer,org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyPojo<basic=String>>>"); - Assert.assertTrue(ti instanceof TupleTypeInfo); - TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; - Assert.assertTrue(tti.getTypeAt(0) instanceof BasicTypeInfo); - Assert.assertTrue(tti.getTypeAt(1) instanceof TupleTypeInfo); - TupleTypeInfo<?> tti2 = (TupleTypeInfo<?>)(Object)tti.getTypeAt(1); - Assert.assertTrue(tti2.getTypeAt(0) instanceof BasicTypeInfo); - Assert.assertTrue(tti2.getTypeAt(1) instanceof PojoTypeInfo); - PojoTypeInfo<?> pti = (PojoTypeInfo<?>) tti2.getTypeAt(1); - Assert.assertEquals("basic", pti.getPojoFieldAt(0).getField().getName()); - Assert.assertTrue(pti.getPojoFieldAt(0).getTypeInformation() instanceof BasicTypeInfo); - } - - public static class MyWritable implements Writable { - - @Override - public void write(DataOutput out) throws IOException { - - } - - @Override - public void readFields(DataInput in) throws IOException { - - } - - } - - @Test - public void testWritableType() { - TypeInformation<?> ti = TypeInfoParser.parse("Writable<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyWritable>"); - Assert.assertTrue(ti instanceof WritableTypeInfo<?>); - Assert.assertEquals(MyWritable.class, ((WritableTypeInfo<?>) ti).getTypeClass()); - } - - @Test - public void testObjectArrays() { - TypeInformation<?> ti = TypeInfoParser.parse("java.lang.Class[]"); - - Assert.assertTrue(ti instanceof ObjectArrayTypeInfo<?, ?>); - Assert.assertEquals(Class.class, ((ObjectArrayTypeInfo<?, ?>) ti).getComponentInfo().getTypeClass()); - - TypeInformation<?> ti2 = TypeInfoParser.parse("Tuple2<Integer,Double>[]"); - - Assert.assertTrue(ti2 instanceof ObjectArrayTypeInfo<?, ?>); - Assert.assertTrue(((ObjectArrayTypeInfo<?, ?>) ti2).getComponentInfo() instanceof TupleTypeInfo); - - TypeInformation<?> ti3 = TypeInfoParser.parse("Tuple2<Integer[],Double>[]"); - Assert.assertEquals("ObjectArrayTypeInfo<Java Tuple2<BasicArrayTypeInfo<Integer>, Double>>", ti3.toString()); - } - - @Test - public void testLargeMixedTuple() { - TypeInformation<?> ti = TypeInfoParser.parse("org.apache.flink.api.java.tuple.Tuple4<Double,java.lang.Class[],StringValue,Tuple1<int>>[]"); - Assert.assertEquals("ObjectArrayTypeInfo<Java Tuple4<Double, ObjectArrayTypeInfo<GenericType<java.lang.Class>>, ValueType<StringValue>, Java Tuple1<Integer>>>", ti.toString()); - } - - public static enum MyEnum { - ONE, TWO, THREE - } - - @Test - public void testEnumType() { - TypeInformation<?> ti = TypeInfoParser.parse("Enum<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>"); - Assert.assertEquals("EnumTypeInfo<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>", ti.toString()); - - TypeInformation<?> ti2 = TypeInfoParser.parse("java.lang.Enum<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>"); - Assert.assertEquals("EnumTypeInfo<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>", ti2.toString()); - } - - @Test - public void testException() { - try { - TypeInfoParser.parse("THIS_CLASS_DOES_NOT_EXIST"); - Assert.fail("exception expected"); - } catch (IllegalArgumentException e) { - // right - } - - try { - TypeInfoParser.parse("Tuple2<Integer>"); - Assert.fail("exception expected"); - } catch (IllegalArgumentException e) { - // right - } - - try { - TypeInfoParser.parse("Tuple3<Integer,,>"); - Assert.fail("exception expected"); - } catch (IllegalArgumentException e) { - // right - } - - try { - TypeInfoParser.parse("Tuple1<Integer,Double>"); - Assert.fail("exception expected"); - } catch (IllegalArgumentException e) { - // right - } - } - - @Test - public void testMultiDimensionalArray() { - // tuple - TypeInformation<?> ti = TypeInfoParser.parse("Tuple2<Integer, Double>[][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<Java Tuple2<Integer, Double>>>", ti.toString()); - - // pojos - ti = TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyPojo<basic=String>[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<" - + "PojoType<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyPojo, fields = [basic: String]>" - + ">>>", ti.toString()); - - // basic types - ti = TypeInfoParser.parse("Float[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<BasicArrayTypeInfo<Float>>>", ti.toString()); - ti = TypeInfoParser.parse("String[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<BasicArrayTypeInfo<String>>>", ti.toString()); - ti = TypeInfoParser.parse("Date[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<Date>>>", ti.toString()); - - // primitive types - ti = TypeInfoParser.parse("int[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<int[]>>", ti.toString()); - ti = TypeInfoParser.parse("boolean[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<boolean[]>>", ti.toString()); - - // value types - ti = TypeInfoParser.parse("IntValue[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<ValueType<IntValue>>>>", ti.toString()); - - // writable types - ti = TypeInfoParser.parse("Writable<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyWritable>[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<" - + "WritableType<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyWritable>" - + ">>>", ti.toString()); - - // enum types - ti = TypeInfoParser.parse("Enum<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>[][][]"); - Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<" - + "EnumTypeInfo<org.apache.flink.api.java.typeutils.TypeInfoParserTest$MyEnum>" - + ">>>", ti.toString()); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java deleted file mode 100644 index 4a579c8..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.core.memory.DataInputView; -import org.apache.flink.core.memory.DataOutputView; -import org.apache.flink.types.Record; -import org.apache.flink.types.Value; -import org.apache.flink.util.TestLogger; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; - -import static org.junit.Assert.*; - -public class ValueTypeInfoTest extends TestLogger { - - public static class TestClass implements Value { - private static final long serialVersionUID = -492760806806568285L; - - @Override - public void write(DataOutputView out) throws IOException { - - } - - @Override - public void read(DataInputView in) throws IOException { - - } - } - - public static class AlternativeClass implements Value { - - private static final long serialVersionUID = -163437084575260172L; - - @Override - public void write(DataOutputView out) throws IOException { - - } - - @Override - public void read(DataInputView in) throws IOException { - - } - } - - @Test - public void testValueTypeInfoEquality() { - ValueTypeInfo<TestClass> tpeInfo1 = new ValueTypeInfo<>(TestClass.class); - ValueTypeInfo<TestClass> tpeInfo2 = new ValueTypeInfo<>(TestClass.class); - - assertEquals(tpeInfo1, tpeInfo2); - assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); - } - - @Test - public void testValueTyepInfoInequality() { - ValueTypeInfo<TestClass> tpeInfo1 = new ValueTypeInfo<>(TestClass.class); - ValueTypeInfo<AlternativeClass> tpeInfo2 = new ValueTypeInfo<>(AlternativeClass.class); - - assertNotEquals(tpeInfo1, tpeInfo2); - } - - @Test - public void testValueTypeEqualsWithNull() throws Exception { - ValueTypeInfo<Record> tpeInfo = new ValueTypeInfo<>(Record.class); - - Assert.assertFalse(tpeInfo.equals(null)); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java deleted file mode 100644 index 2ab0021..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils; - -import org.apache.flink.util.TestLogger; -import org.apache.hadoop.io.Writable; -import org.junit.Test; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import static org.junit.Assert.*; - -public class WritableTypeInfoTest extends TestLogger { - - public static class TestClass implements Writable { - @Override - public void write(DataOutput dataOutput) throws IOException { - - } - - @Override - public void readFields(DataInput dataInput) throws IOException { - - } - } - - public static class AlternateClass implements Writable { - @Override - public void write(DataOutput dataOutput) throws IOException { - - } - - @Override - public void readFields(DataInput dataInput) throws IOException { - - } - } - - - @Test - public void testWritableTypeInfoEquality() { - WritableTypeInfo<TestClass> tpeInfo1 = new WritableTypeInfo<>(TestClass.class); - WritableTypeInfo<TestClass> tpeInfo2 = new WritableTypeInfo<>(TestClass.class); - - assertEquals(tpeInfo1, tpeInfo2); - assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); - } - - @Test - public void testWritableTypeInfoInequality() { - WritableTypeInfo<TestClass> tpeInfo1 = new WritableTypeInfo<>(TestClass.class); - WritableTypeInfo<AlternateClass> tpeInfo2 = new WritableTypeInfo<>(AlternateClass.class); - - assertNotEquals(tpeInfo1, tpeInfo2); - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java deleted file mode 100644 index 307a3d2..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils.runtime; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Random; - -import org.junit.Assert; -import org.junit.Test; -import org.apache.flink.api.common.typeutils.SerializerTestInstance; -import org.apache.flink.api.common.typeutils.TypeSerializer; -import org.apache.flink.api.common.typeutils.base.GenericArraySerializer; -import org.apache.flink.api.common.typeutils.base.StringSerializer; -import org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeSerializerTest.Book; -import org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeSerializerTest.BookAuthor; -import org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeSerializerTest.ComplexNestedObject1; -import org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeSerializerTest.ComplexNestedObject2; -import org.apache.flink.api.java.typeutils.runtime.AbstractGenericTypeSerializerTest.SimpleTypes; -import org.apache.flink.util.StringUtils; - -public abstract class AbstractGenericArraySerializerTest { - - private final Random rnd = new Random(349712539451944123L); - - - @Test - public void testString() { - String[] arr1 = new String[] {"abc", "", - StringUtils.getRandomString(new Random(289347567856686223L), 10, 100), - StringUtils.getRandomString(new Random(289347567856686223L), 15, 50), - StringUtils.getRandomString(new Random(289347567856686223L), 30, 170), - StringUtils.getRandomString(new Random(289347567856686223L), 14, 15), - ""}; - - String[] arr2 = new String[] {"foo", "", - StringUtils.getRandomString(new Random(289347567856686223L), 10, 100), - StringUtils.getRandomString(new Random(289347567856686223L), 1000, 5000), - StringUtils.getRandomString(new Random(289347567856686223L), 30000, 35000), - StringUtils.getRandomString(new Random(289347567856686223L), 100*1024, 105*1024), - "bar"}; - - // run tests with the string serializer as the component serializer - runTests(String.class, new StringSerializer(), arr1, arr2); - - // run the tests with the generic serializer as the component serializer - runTests(arr1, arr2); - } - - @Test - public void testSimpleTypesObjects() { - SimpleTypes a = new SimpleTypes(); - SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - - runTests(new SimpleTypes[] {a, b, c}, new SimpleTypes[] {d, e, f, g}); - } - - @Test - public void testCompositeObject() { - ComplexNestedObject1 o1 = new ComplexNestedObject1(5626435); - ComplexNestedObject1 o2 = new ComplexNestedObject1(76923); - ComplexNestedObject1 o3 = new ComplexNestedObject1(-1100); - ComplexNestedObject1 o4 = new ComplexNestedObject1(0); - ComplexNestedObject1 o5 = new ComplexNestedObject1(44); - - runTests(new ComplexNestedObject1[] {o1, o2}, new ComplexNestedObject1[] {o3}, new ComplexNestedObject1[] {o4, o5}); - } - - @Test - public void testNestedObjects() { - ComplexNestedObject2 o1 = new ComplexNestedObject2(rnd); - ComplexNestedObject2 o2 = new ComplexNestedObject2(); - ComplexNestedObject2 o3 = new ComplexNestedObject2(rnd); - ComplexNestedObject2 o4 = new ComplexNestedObject2(rnd); - - runTests( new ComplexNestedObject2[] {o1, o2, o3}, - new ComplexNestedObject2[] {}, - new ComplexNestedObject2[] {}, - new ComplexNestedObject2[] {o4}, - new ComplexNestedObject2[] {}); - } - - @Test - public void testBeanStyleObjects() { - { - Book b1 = new Book(976243875L, "The Serialization Odysse", 42); - Book b2 = new Book(0L, "Debugging byte streams", 1337); - Book b3 = new Book(-1L, "Low level interfaces", 0xC0FFEE); - Book b4 = new Book(Long.MAX_VALUE, "The joy of bits and bytes", 0xDEADBEEF); - Book b5 = new Book(Long.MIN_VALUE, "Winnign a prize for creative test strings", 0xBADF00); - Book b6 = new Book(-2L, "Distributed Systems", 0xABCDEF0123456789L); - - runTests( new Book[] {b1, b2}, - new Book[] {}, - new Book[] {}, - new Book[] {}, - new Book[] {}, - new Book[] {b3, b4, b5, b6}); - } - - // object with collection - { - ArrayList<String> list = new ArrayList<String>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - list.add("E"); - - BookAuthor b1 = new BookAuthor(976243875L, list, "Arno Nym"); - - ArrayList<String> list2 = new ArrayList<String>(); - BookAuthor b2 = new BookAuthor(987654321L, list2, "The Saurus"); - - runTests(new BookAuthor[] {b1, b2}); - } - } - - @SafeVarargs - private final <T> void runTests(T[]... instances) { - try { - @SuppressWarnings("unchecked") - Class<T> type = (Class<T>) instances[0][0].getClass(); - TypeSerializer<T> serializer = createComponentSerializer(type); - runTests(type, serializer, instances); - } - catch (Exception e) { - System.err.println(e.getMessage()); - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - } - - @SafeVarargs - private final <T> void runTests(Class<T> type, TypeSerializer<T> componentSerializer, T[]... instances) { - try { - if (type == null || componentSerializer == null || instances == null || instances.length == 0) { - throw new IllegalArgumentException(); - } - - @SuppressWarnings("unchecked") - Class<T[]> arrayClass = (Class<T[]>) (Class<?>) Array.newInstance(type, 0).getClass(); - - GenericArraySerializer<T> serializer = createSerializer(type, componentSerializer); - SerializerTestInstance<T[]> test = new SerializerTestInstance<T[]>(serializer, arrayClass, -1, instances); - test.testAll(); - } - catch (Exception e) { - System.err.println(e.getMessage()); - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - } - - private <T> GenericArraySerializer<T> createSerializer(Class<T> type, TypeSerializer<T> componentSerializer) { - return new GenericArraySerializer<T>(type, componentSerializer); - } - - abstract protected <T> TypeSerializer<T> createComponentSerializer(Class<T> type); -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java deleted file mode 100644 index ef168d8..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils.runtime; - -import org.apache.flink.api.common.typeutils.ComparatorTestBase; -import org.apache.flink.api.common.typeutils.TypeComparator; -import org.apache.flink.api.common.typeutils.TypeSerializer; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -abstract public class AbstractGenericTypeComparatorTest { - - @Test - public void testString() { - runTests(new String[]{ - "", - "Lorem Ipsum Dolor Omit Longer", - "aaaa", - "abcd", - "abce", - "abdd", - "accd", - "bbcd" - }); - } - - @Test - public void testSimpleTypesObjects() { - runTests( - new SimpleTypes(0, 1, (byte) 2, "", (short) 3, 4.0), - new SimpleTypes(1, 1, (byte) 2, "", (short) 3, 4.0), - new SimpleTypes(1, 2, (byte) 2, "", (short) 3, 4.0), - new SimpleTypes(1, 2, (byte) 3, "", (short) 3, 4.0), - new SimpleTypes(1, 2, (byte) 3, "a", (short) 3, 4.0), - new SimpleTypes(1, 2, (byte) 3, "b", (short) 3, 4.0), - new SimpleTypes(1, 2, (byte) 3, "b", (short) 4, 4.0), - new SimpleTypes(1, 2, (byte) 3, "b", (short) 4, 6.0) - ); - } - - @Test - public void testCompositeObject() { - ComplexNestedObject1 o1 = new ComplexNestedObject1(-1100); - ComplexNestedObject1 o2 = new ComplexNestedObject1(0); - ComplexNestedObject1 o3 = new ComplexNestedObject1(44); - ComplexNestedObject1 o4 = new ComplexNestedObject1(76923, "A"); - ComplexNestedObject1 o5 = new ComplexNestedObject1(5626435, "A somewhat random collection"); - - runTests(o1, o2, o3, o4, o5); - } - - @Test - public void testBeanStyleObjects() { - { - Book b111 = new Book(-1L, "A Low level interfaces", 0xC); - Book b122 = new Book(-1L, "Low level interfaces", 0xC); - Book b123 = new Book(-1L, "Low level interfaces", 0xC0FFEE); - - Book b2 = new Book(0L, "Debugging byte streams", 1337); - Book b3 = new Book(976243875L, "The Serialization Odysse", 42); - - runTests(b111, b122, b123, b2, b3); - } - - { - BookAuthor b1 = new BookAuthor(976243875L, new ArrayList<String>(), "Arno Nym"); - - ArrayList<String> list = new ArrayList<String>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - list.add("E"); - - BookAuthor b2 = new BookAuthor(976243875L, list, "The Saurus"); - - runTests(b1, b2); - } - } - - // ------------------------------------------------------------------------ - - private <T> void runTests(T... sortedTestData) { - ComparatorTestInstance<T> testBase = new ComparatorTestInstance<T>(sortedTestData); - testBase.testAll(); - } - - abstract protected <T> TypeSerializer<T> createSerializer(Class<T> type); - - // ------------------------------------------------------------------------ - // test instance - // ------------------------------------------------------------------------ - - private class ComparatorTestInstance<T> extends ComparatorTestBase<T> { - - private final T[] testData; - - private final Class<T> type; - - @SuppressWarnings("unchecked") - public ComparatorTestInstance(T[] testData) { - if (testData == null || testData.length == 0) { - throw new IllegalArgumentException(); - } - - this.testData = testData; - this.type = (Class<T>) testData[0].getClass(); - } - - @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) - protected TypeComparator<T> createComparator(boolean ascending) { - return new GenericTypeComparator(ascending, AbstractGenericTypeComparatorTest.this.createSerializer(this - .type), this.type); - } - - @Override - protected TypeSerializer<T> createSerializer() { - return AbstractGenericTypeComparatorTest.this.createSerializer(this.type); - } - - @Override - protected T[] getSortedTestData() { - return this.testData; - } - - public void testAll() { - testDuplicate(); - testEquality(); - testEqualityWithReference(); - testInequality(); - testInequalityWithReference(); - testNormalizedKeysEqualsFullLength(); - testNormalizedKeysEqualsHalfLength(); - testNormalizedKeysGreatSmallFullLength(); - testNormalizedKeysGreatSmallAscDescHalfLength(); - testNormalizedKeyReadWriter(); - } - } - - // ------------------------------------------------------------------------ - // test objects - // ------------------------------------------------------------------------ - - public static final class SimpleTypes implements Comparable<SimpleTypes> { - - private final int iVal; - private final long lVal; - private final byte bVal; - private final String sVal; - private final short rVal; - private final double dVal; - - public SimpleTypes() { - this(0, 0, (byte) 0, "", (short) 0, 0); - } - - public SimpleTypes(int iVal, long lVal, byte bVal, String sVal, short rVal, double dVal) { - this.iVal = iVal; - this.lVal = lVal; - this.bVal = bVal; - this.sVal = sVal; - this.rVal = rVal; - this.dVal = dVal; - } - - @Override - public String toString() { - return String.format("(%d, %d, %d, %s, %d, %f)", iVal, lVal, bVal, sVal, rVal, dVal); - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == SimpleTypes.class) { - SimpleTypes other = (SimpleTypes) obj; - - return other.iVal == this.iVal && - other.lVal == this.lVal && - other.bVal == this.bVal && - other.sVal.equals(this.sVal) && - other.rVal == this.rVal && - other.dVal == this.dVal; - } else { - return false; - } - } - - @Override - public int compareTo(SimpleTypes o) { - int cmp = (this.iVal < o.iVal ? -1 : (this.iVal == o.iVal ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - cmp = (this.lVal < o.lVal ? -1 : (this.lVal == o.lVal ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - cmp = (this.bVal < o.bVal ? -1 : (this.bVal == o.bVal ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - cmp = this.sVal.compareTo(o.sVal); - if (cmp != 0) { - return cmp; - } - - cmp = (this.rVal < o.rVal ? -1 : (this.rVal == o.rVal ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - return (this.dVal < o.dVal ? -1 : (this.dVal == o.dVal ? 0 : 1)); - } - } - - public static class ComplexNestedObject1 implements Comparable<ComplexNestedObject1> { - - private double doubleValue; - - private List<String> stringList; - - public ComplexNestedObject1() { - } - - public ComplexNestedObject1(double value, String... listElements) { - this.doubleValue = value; - - this.stringList = new ArrayList<String>(); - for (String str : listElements) { - this.stringList.add(str); - } - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == ComplexNestedObject1.class) { - ComplexNestedObject1 other = (ComplexNestedObject1) obj; - return other.doubleValue == this.doubleValue && this.stringList.equals(other.stringList); - } else { - return false; - } - } - - @Override - public int compareTo(ComplexNestedObject1 o) { - int cmp = (this.doubleValue < o.doubleValue ? -1 : (this.doubleValue == o.doubleValue ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - int size = this.stringList.size(); - int otherSize = o.stringList.size(); - - cmp = (size < otherSize ? -1 : (size == otherSize ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - for (int i = 0; i < size; i++) { - cmp = this.stringList.get(i).compareTo(o.stringList.get(i)); - if (cmp != 0) { - return cmp; - } - } - - return 0; - } - } - - public static class Book implements Comparable<Book> { - - private long bookId; - private String title; - private long authorId; - - public Book() { - } - - public Book(long bookId, String title, long authorId) { - this.bookId = bookId; - this.title = title; - this.authorId = authorId; - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == Book.class) { - Book other = (Book) obj; - return other.bookId == this.bookId && other.authorId == this.authorId && this.title.equals(other.title); - } else { - return false; - } - } - - @Override - public int compareTo(Book o) { - int cmp = (this.bookId < o.bookId ? -1 : (this.bookId == o.bookId ? 0 : 1)); - if (cmp != 0) { - return cmp; - } - - cmp = title.compareTo(o.title); - if (cmp != 0) { - return cmp; - } - - return (this.authorId < o.authorId ? -1 : (this.authorId == o.authorId ? 0 : 1)); - } - } - - public static class BookAuthor implements Comparable<BookAuthor> { - - private long authorId; - private List<String> bookTitles; - private String authorName; - - public BookAuthor() { - } - - public BookAuthor(long authorId, List<String> bookTitles, String authorName) { - this.authorId = authorId; - this.bookTitles = bookTitles; - this.authorName = authorName; - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == BookAuthor.class) { - BookAuthor other = (BookAuthor) obj; - return other.authorName.equals(this.authorName) && other.authorId == this.authorId && - other.bookTitles.equals(this.bookTitles); - } else { - return false; - } - } - - @Override - public int compareTo(BookAuthor o) { - int cmp = (this.authorId < o.authorId ? -1 : (this.authorId == o.authorId ? 0 : 1)); - if (cmp != 0) return cmp; - - int size = this.bookTitles.size(); - int oSize = o.bookTitles.size(); - cmp = (size < oSize ? -1 : (size == oSize ? 0 : 1)); - if (cmp != 0) return cmp; - - for (int i = 0; i < size; i++) { - cmp = this.bookTitles.get(i).compareTo(o.bookTitles.get(i)); - if (cmp != 0) return cmp; - } - - return this.authorName.compareTo(o.authorName); - } - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java deleted file mode 100644 index 059c78d..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils.runtime; - -import org.apache.flink.api.common.typeutils.SerializerTestInstance; -import org.apache.flink.api.common.typeutils.TypeSerializer; -import org.apache.flink.util.StringUtils; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -/** - * A test for the {@link AvroSerializer}. - */ -abstract public class AbstractGenericTypeSerializerTest { - - private final Random rnd = new Random(349712539451944123L); - - @Test - public void testString() { - runTests("abc", "", - StringUtils.getRandomString(new Random(289347567856686223L), 10, 100), - StringUtils.getRandomString(new Random(289347567856686223L), 1000, 5000), - StringUtils.getRandomString(new Random(289347567856686223L), 30000, 35000), - StringUtils.getRandomString(new Random(289347567856686223L), 100 * 1024, 105 * 1024)); - } - - @Test - public void testSimpleTypesObjects() { - SimpleTypes a = new SimpleTypes(); - SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), - StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); - - runTests(a, b, c, d, e, f, g); - } - - @Test - public void testCompositeObject() { - ComplexNestedObject1 o1 = new ComplexNestedObject1(5626435); - ComplexNestedObject1 o2 = new ComplexNestedObject1(76923); - ComplexNestedObject1 o3 = new ComplexNestedObject1(-1100); - ComplexNestedObject1 o4 = new ComplexNestedObject1(0); - ComplexNestedObject1 o5 = new ComplexNestedObject1(44); - - runTests(o1, o2, o3, o4, o5); - } - - @Test - public void testNestedObjects() { - ComplexNestedObject2 o1 = new ComplexNestedObject2(rnd); - ComplexNestedObject2 o2 = new ComplexNestedObject2(); - ComplexNestedObject2 o3 = new ComplexNestedObject2(rnd); - ComplexNestedObject2 o4 = new ComplexNestedObject2(rnd); - - runTests(o1, o2, o3, o4); - } - - @Test - public void testBeanStyleObjects() { - { - Book b1 = new Book(976243875L, "The Serialization Odysse", 42); - Book b2 = new Book(0L, "Debugging byte streams", 1337); - Book b3 = new Book(-1L, "Low level interfaces", 0xC0FFEE); - - runTests(b1, b2, b3); - } - - // object with collection - { - ArrayList<String> list = new ArrayList<String>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - list.add("E"); - - BookAuthor b1 = new BookAuthor(976243875L, list, "Arno Nym"); - - ArrayList<String> list2 = new ArrayList<String>(); - BookAuthor b2 = new BookAuthor(987654321L, list2, "The Saurus"); - - runTests(b1, b2); - } - } - - @Test - public void testNestedInterfaces() { - { - - SimpleWithNestedInterfaces s1 = new SimpleWithNestedInterfaces("Hello", 1); - SimpleWithNestedInterfaces s2 = new SimpleWithNestedInterfaces("Ciao", 2); - SimpleWithNestedInterfaces s3 = new SimpleWithNestedInterfaces("Foo", 3); - - runTests(s1, s2, s3); - } - - // object with collection - { - ArrayList<String> list = new ArrayList<String>(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - list.add("E"); - - BookAuthor b1 = new BookAuthor(976243875L, list, "Arno Nym"); - - ArrayList<String> list2 = new ArrayList<String>(); - BookAuthor b2 = new BookAuthor(987654321L, list2, "The Saurus"); - - runTests(b1, b2); - } - } - - protected final <T> void runTests(T... instances) { - if (instances == null || instances.length == 0) { - throw new IllegalArgumentException(); - } - - @SuppressWarnings("unchecked") - Class<T> clazz = (Class<T>) instances[0].getClass(); - - TypeSerializer<T> serializer = createSerializer(clazz); - SerializerTestInstance<T> test = new SerializerTestInstance<T>(serializer, clazz, -1, instances); - test.testAll(); - } - - abstract protected <T> TypeSerializer<T> createSerializer(Class<T> type); - - - // -------------------------------------------------------------------------------------------- - // Test Objects - // -------------------------------------------------------------------------------------------- - - public static final class SimpleWithNestedInterfaces { - Map<String, Integer> map1; - List<String> list; - - public SimpleWithNestedInterfaces() { - map1 = new HashMap<String, Integer>(); - list = new ArrayList<String>(); - } - - - public SimpleWithNestedInterfaces(String str, Integer i) { - map1 = new HashMap<String, Integer>(); - map1.put(str, i); - list = new ArrayList<String>(); - list.add(str); - } - - @Override - public boolean equals(Object o) { - if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { return false; } - - SimpleWithNestedInterfaces that = (SimpleWithNestedInterfaces) o; - - if (!list.equals(that.list)) { return false; } - if (!map1.equals(that.map1)) { return false; } - - return true; - } - - @Override - public int hashCode() { - int result = map1.hashCode(); - result = 31 * result + list.hashCode(); - return result; - } - } - - public static final class SimpleTypes { - - private final int iVal; - private final long lVal; - private final byte bVal; - private final String sVal; - private final short rVal; - private final double dVal; - - - public SimpleTypes() { - this(0, 0, (byte) 0, "", (short) 0, 0); - } - - public SimpleTypes(int iVal, long lVal, byte bVal, String sVal, short rVal, double dVal) { - this.iVal = iVal; - this.lVal = lVal; - this.bVal = bVal; - this.sVal = sVal; - this.rVal = rVal; - this.dVal = dVal; - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == SimpleTypes.class) { - SimpleTypes other = (SimpleTypes) obj; - - return other.iVal == this.iVal && - other.lVal == this.lVal && - other.bVal == this.bVal && - other.sVal.equals(this.sVal) && - other.rVal == this.rVal && - other.dVal == this.dVal; - - } else { - return false; - } - } - - @Override - public String toString() { - return String.format("(%d, %d, %d, %s, %d, %f)", iVal, lVal, bVal, sVal, rVal, dVal); - } - } - - public static class ComplexNestedObject1 { - - private double doubleValue; - - private List<String> stringList; - - public ComplexNestedObject1() { - } - - public ComplexNestedObject1(int offInit) { - this.doubleValue = 6293485.6723 + offInit; - - this.stringList = new ArrayList<String>(); - this.stringList.add("A" + offInit); - this.stringList.add("somewhat" + offInit); - this.stringList.add("random" + offInit); - this.stringList.add("collection" + offInit); - this.stringList.add("of" + offInit); - this.stringList.add("strings" + offInit); - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == ComplexNestedObject1.class) { - ComplexNestedObject1 other = (ComplexNestedObject1) obj; - return other.doubleValue == this.doubleValue && this.stringList.equals(other.stringList); - } else { - return false; - } - } - } - - public static class ComplexNestedObject2 { - - private long longValue; - - private Map<String, ComplexNestedObject1> theMap = new HashMap<String, ComplexNestedObject1>(); - - public ComplexNestedObject2() { - } - - public ComplexNestedObject2(Random rnd) { - this.longValue = rnd.nextLong(); - - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - this.theMap.put(String.valueOf(rnd.nextLong()), new ComplexNestedObject1(rnd.nextInt())); - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == ComplexNestedObject2.class) { - ComplexNestedObject2 other = (ComplexNestedObject2) obj; - return other.longValue == this.longValue && this.theMap.equals(other.theMap); - } else { - return false; - } - } - } - - public static class Book { - - private long bookId; - private String title; - private long authorId; - - public Book() { - } - - public Book(long bookId, String title, long authorId) { - this.bookId = bookId; - this.title = title; - this.authorId = authorId; - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == Book.class) { - Book other = (Book) obj; - return other.bookId == this.bookId && other.authorId == this.authorId && this.title.equals(other.title); - } else { - return false; - } - } - } - - public static class BookAuthor { - - private long authorId; - private List<String> bookTitles; - private String authorName; - - public BookAuthor() { - } - - public BookAuthor(long authorId, List<String> bookTitles, String authorName) { - this.authorId = authorId; - this.bookTitles = bookTitles; - this.authorName = authorName; - } - - @Override - public boolean equals(Object obj) { - if (obj.getClass() == BookAuthor.class) { - BookAuthor other = (BookAuthor) obj; - return other.authorName.equals(this.authorName) && other.authorId == this.authorId && - other.bookTitles.equals(this.bookTitles); - } else { - return false; - } - } - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java ---------------------------------------------------------------------- diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java deleted file mode 100644 index 5b08e52..0000000 --- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.api.java.typeutils.runtime; - -import org.apache.flink.api.common.typeutils.TypeSerializer; - -public class AvroGenericArraySerializerTest extends AbstractGenericArraySerializerTest { - @Override - protected <T> TypeSerializer<T> createComponentSerializer(Class<T> type) { - return new AvroSerializer<T>(type); - } -}