You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2016/02/02 18:23:15 UTC
[15/38] flink git commit: [FLINK-3303] [core] Move all type utilities
to flink-core
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java
new file mode 100644
index 0000000..4a579c8
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/ValueTypeInfoTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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-core/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java
new file mode 100644
index 0000000..2ab0021
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/WritableTypeInfoTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java
new file mode 100644
index 0000000..307a3d2
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericArraySerializerTest.java
@@ -0,0 +1,187 @@
+/*
+ * 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-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java
new file mode 100644
index 0000000..ef168d8
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeComparatorTest.java
@@ -0,0 +1,376 @@
+/*
+ * 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-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java
new file mode 100644
index 0000000..059c78d
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AbstractGenericTypeSerializerTest.java
@@ -0,0 +1,364 @@
+/*
+ * 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-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java
new file mode 100644
index 0000000..5b08e52
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericArraySerializerTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeComparatorTest.java
new file mode 100644
index 0000000..19fac43
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeComparatorTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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 AvroGenericTypeComparatorTest extends AbstractGenericTypeComparatorTest {
+ @Override
+ protected <T> TypeSerializer<T> createSerializer(Class<T> type) {
+ return new AvroSerializer<T>(type);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeSerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeSerializerTest.java
new file mode 100644
index 0000000..df1ff60
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroGenericTypeSerializerTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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 AvroGenericTypeSerializerTest extends AbstractGenericTypeSerializerTest {
+
+ @Override
+ protected <T> TypeSerializer<T> createSerializer(Class<T> type) {
+ return new AvroSerializer<T>(type);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroSerializerEmptyArrayTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroSerializerEmptyArrayTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroSerializerEmptyArrayTest.java
new file mode 100644
index 0000000..8a89410
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/AvroSerializerEmptyArrayTest.java
@@ -0,0 +1,189 @@
+/*
+ * 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 static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avro.reflect.Nullable;
+import org.apache.flink.api.common.typeutils.SerializerTestInstance;
+import org.junit.Test;
+
+public class AvroSerializerEmptyArrayTest {
+
+ @Test
+ public void testBookSerialization() {
+ try {
+ Book b = new Book(123, "This is a test book", 26382648);
+ AvroSerializer<Book> serializer = new AvroSerializer<Book>(Book.class);
+ SerializerTestInstance<Book> test = new SerializerTestInstance<Book>(serializer, Book.class, -1, b);
+ test.testAll();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testSerialization() {
+ try {
+ List<String> titles = new ArrayList<String>();
+
+ List<Book> books = new ArrayList<Book>();
+ books.add(new Book(123, "This is a test book", 1));
+ books.add(new Book(24234234, "This is a test book", 1));
+ books.add(new Book(1234324, "This is a test book", 3));
+
+ BookAuthor a = new BookAuthor(1, titles, "Test Author");
+ a.books = books;
+ a.bookType = BookAuthor.BookType.journal;
+
+ AvroSerializer<BookAuthor> serializer = new AvroSerializer<BookAuthor>(BookAuthor.class);
+
+ SerializerTestInstance<BookAuthor> test = new SerializerTestInstance<BookAuthor>(serializer, BookAuthor.class, -1, a);
+ test.testAll();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public static class Book {
+
+ long bookId;
+ @Nullable
+ String title;
+ long authorId;
+
+ public Book() {}
+
+ public Book(long bookId, String title, long authorId) {
+ this.bookId = bookId;
+ this.title = title;
+ this.authorId = authorId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (authorId ^ (authorId >>> 32));
+ result = prime * result + (int) (bookId ^ (bookId >>> 32));
+ result = prime * result + ((title == null) ? 0 : title.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Book other = (Book) obj;
+ if (authorId != other.authorId)
+ return false;
+ if (bookId != other.bookId)
+ return false;
+ if (title == null) {
+ if (other.title != null)
+ return false;
+ } else if (!title.equals(other.title))
+ return false;
+ return true;
+ }
+ }
+
+ public static class BookAuthor {
+
+ enum BookType {
+ book,
+ article,
+ journal
+ }
+
+ long authorId;
+
+ @Nullable
+ List<String> bookTitles;
+
+ @Nullable
+ List<Book> books;
+
+ String authorName;
+
+ BookType bookType;
+
+ public BookAuthor() {}
+
+ public BookAuthor(long authorId, List<String> bookTitles, String authorName) {
+ this.authorId = authorId;
+ this.bookTitles = bookTitles;
+ this.authorName = authorName;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (authorId ^ (authorId >>> 32));
+ result = prime * result + ((authorName == null) ? 0 : authorName.hashCode());
+ result = prime * result + ((bookTitles == null) ? 0 : bookTitles.hashCode());
+ result = prime * result + ((bookType == null) ? 0 : bookType.hashCode());
+ result = prime * result + ((books == null) ? 0 : books.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ BookAuthor other = (BookAuthor) obj;
+ if (authorId != other.authorId)
+ return false;
+ if (authorName == null) {
+ if (other.authorName != null)
+ return false;
+ } else if (!authorName.equals(other.authorName))
+ return false;
+ if (bookTitles == null) {
+ if (other.bookTitles != null)
+ return false;
+ } else if (!bookTitles.equals(other.bookTitles))
+ return false;
+ if (bookType != other.bookType)
+ return false;
+ if (books == null) {
+ if (other.books != null)
+ return false;
+ } else if (!books.equals(other.books))
+ return false;
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/CopyableValueComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/CopyableValueComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/CopyableValueComparatorTest.java
new file mode 100644
index 0000000..b317275
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/CopyableValueComparatorTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.apache.flink.types.StringValue;
+
+public class CopyableValueComparatorTest extends ComparatorTestBase<StringValue> {
+
+ StringValue[] data = new StringValue[]{
+ new StringValue(""),
+ new StringValue("Lorem Ipsum Dolor Omit Longer"),
+ new StringValue("aaaa"),
+ new StringValue("abcd"),
+ new StringValue("abce"),
+ new StringValue("abdd"),
+ new StringValue("accd"),
+ new StringValue("bbcd")
+ };
+
+ @Override
+ protected TypeComparator<StringValue> createComparator(boolean ascending) {
+ return new CopyableValueComparator<StringValue>(ascending, StringValue.class);
+ }
+
+ @Override
+ protected TypeSerializer<StringValue> createSerializer() {
+ return new CopyableValueSerializer<StringValue>(StringValue.class);
+ }
+
+ @Override
+ protected StringValue[] getSortedTestData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/EitherSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/EitherSerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/EitherSerializerTest.java
new file mode 100644
index 0000000..d636d5e
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/EitherSerializerTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.apache.flink.types.Either.Left;
+import static org.apache.flink.types.Either.Right;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeutils.SerializerTestInstance;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.types.Either;
+import org.apache.flink.api.java.typeutils.EitherTypeInfo;
+import org.apache.flink.api.java.typeutils.TupleTypeInfo;
+import org.junit.Test;
+
+public class EitherSerializerTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testStringDoubleEither() {
+
+ Either<String, Double>[] testData = new Either[] {
+ Left("banana"),
+ Left(""),
+ Right(32.0),
+ Right(Double.MIN_VALUE),
+ Right(Double.MAX_VALUE)};
+
+ EitherTypeInfo<String, Double> eitherTypeInfo = (EitherTypeInfo<String, Double>) new EitherTypeInfo<String, Double>(
+ BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.DOUBLE_TYPE_INFO);
+ EitherSerializer<String, Double> eitherSerializer =
+ (EitherSerializer<String, Double>) eitherTypeInfo.createSerializer(new ExecutionConfig());
+ SerializerTestInstance<Either<String, Double>> testInstance =
+ new EitherSerializerTestInstance<Either<String, Double>>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
+ testInstance.testAll();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testEitherWithTuple() {
+
+ Either<Tuple2<Long, Long>, Double>[] testData = new Either[] {
+ Either.Left(new Tuple2<>(2l, 9l)),
+ new Left<>(new Tuple2<>(Long.MIN_VALUE, Long.MAX_VALUE)),
+ new Right<>(32.0),
+ Right(Double.MIN_VALUE),
+ Right(Double.MAX_VALUE)};
+
+ EitherTypeInfo<Tuple2<Long, Long>, Double> eitherTypeInfo = (EitherTypeInfo<Tuple2<Long, Long>, Double>)
+ new EitherTypeInfo<Tuple2<Long, Long>, Double>(
+ new TupleTypeInfo<Tuple2<Long, Long>>(BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO),
+ BasicTypeInfo.DOUBLE_TYPE_INFO);
+ EitherSerializer<Tuple2<Long, Long>, Double> eitherSerializer =
+ (EitherSerializer<Tuple2<Long, Long>, Double>) eitherTypeInfo.createSerializer(new ExecutionConfig());
+ SerializerTestInstance<Either<Tuple2<Long, Long>, Double>> testInstance =
+ new EitherSerializerTestInstance<Either<Tuple2<Long, Long>, Double>>(
+ eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
+ testInstance.testAll();
+ }
+
+ /**
+ * {@link org.apache.flink.api.common.typeutils.SerializerTestBase#testInstantiate()}
+ * checks that the type of the created instance is the same as the type class parameter.
+ * Since we arbitrarily create always create a Left instance we override this test.
+ */
+ private class EitherSerializerTestInstance<T> extends SerializerTestInstance<T> {
+
+ public EitherSerializerTestInstance(TypeSerializer<T> serializer,
+ Class<T> typeClass, int length, T[] testData) {
+ super(serializer, typeClass, length, testData);
+ }
+
+ @Override
+ @Test
+ public void testInstantiate() {
+ try {
+ TypeSerializer<T> serializer = getSerializer();
+
+ T instance = serializer.createInstance();
+ assertNotNull("The created instance must not be null.", instance);
+
+ Class<T> type = getTypeClass();
+ assertNotNull("The test is corrupt: type class is null.", type);
+ }
+ catch (Exception e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ fail("Exception in test: " + e.getMessage());
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/GenericPairComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/GenericPairComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/GenericPairComparatorTest.java
new file mode 100644
index 0000000..06330d3
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/GenericPairComparatorTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.GenericPairComparator;
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.base.DoubleComparator;
+import org.apache.flink.api.common.typeutils.base.DoubleSerializer;
+import org.apache.flink.api.common.typeutils.base.IntComparator;
+import org.apache.flink.api.common.typeutils.base.IntSerializer;
+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.apache.flink.api.java.typeutils.runtime.tuple.base.TuplePairComparatorTestBase;
+
+public class GenericPairComparatorTest extends TuplePairComparatorTestBase<Tuple3<Integer, String, Double>, Tuple4<Integer, Float, Long, Double>> {
+
+ @SuppressWarnings("unchecked")
+ private Tuple3<Integer, String, Double>[] dataISD = new Tuple3[]{
+ new Tuple3<Integer, String, Double>(4, "hello", 20.0),
+ new Tuple3<Integer, String, Double>(4, "world", 23.2),
+ new Tuple3<Integer, String, Double>(5, "hello", 18.0),
+ new Tuple3<Integer, String, Double>(5, "world", 19.2),
+ new Tuple3<Integer, String, Double>(6, "hello", 16.0),
+ new Tuple3<Integer, String, Double>(6, "world", 17.2),
+ new Tuple3<Integer, String, Double>(7, "hello", 14.0),
+ new Tuple3<Integer, String, Double>(7, "world", 15.2)
+ };
+
+ @SuppressWarnings("unchecked")
+ private Tuple4<Integer, Float, Long, Double>[] dataIDL = new Tuple4[]{
+ new Tuple4<Integer, Float, Long, Double>(4, 0.11f, 14L, 20.0),
+ new Tuple4<Integer, Float, Long, Double>(4, 0.221f, 15L, 23.2),
+ new Tuple4<Integer, Float, Long, Double>(5, 0.33f, 15L, 18.0),
+ new Tuple4<Integer, Float, Long, Double>(5, 0.44f, 20L, 19.2),
+ new Tuple4<Integer, Float, Long, Double>(6, 0.55f, 20L, 16.0),
+ new Tuple4<Integer, Float, Long, Double>(6, 0.66f, 29L, 17.2),
+ new Tuple4<Integer, Float, Long, Double>(7, 0.77f, 29L, 14.0),
+ new Tuple4<Integer, Float, Long, Double>(7, 0.88f, 34L, 15.2)
+ };
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected GenericPairComparator<Tuple3<Integer, String, Double>, Tuple4<Integer, Float, Long, Double>> createComparator(boolean ascending) {
+ int[] fields1 = new int[]{0, 2};
+ int[] fields2 = new int[]{0, 3};
+ TypeComparator[] comps1 = new TypeComparator[]{
+ new IntComparator(ascending),
+ new DoubleComparator(ascending)
+ };
+ TypeComparator[] comps2 = new TypeComparator[]{
+ new IntComparator(ascending),
+ new DoubleComparator(ascending)
+ };
+ TypeSerializer[] sers1 = new TypeSerializer[]{
+ IntSerializer.INSTANCE,
+ DoubleSerializer.INSTANCE
+ };
+ TypeSerializer[] sers2= new TypeSerializer[]{
+ IntSerializer.INSTANCE,
+ DoubleSerializer.INSTANCE
+ };
+ TypeComparator<Tuple3<Integer, String, Double>> comp1 = new TupleComparator<Tuple3<Integer, String, Double>>(fields1, comps1, sers1);
+ TypeComparator<Tuple4<Integer, Float, Long, Double>> comp2 = new TupleComparator<Tuple4<Integer, Float, Long, Double>>(fields2, comps2, sers2);
+ return new GenericPairComparator<Tuple3<Integer, String, Double>, Tuple4<Integer, Float, Long, Double>>(comp1, comp2);
+ }
+
+ @Override
+ protected Tuple2<Tuple3<Integer, String, Double>[], Tuple4<Integer, Float, Long, Double>[]> getSortedTestData() {
+ return new Tuple2<Tuple3<Integer, String, Double>[], Tuple4<Integer, Float, Long, Double>[]>(dataISD, dataIDL);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/MultidimensionalArraySerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/MultidimensionalArraySerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/MultidimensionalArraySerializerTest.java
new file mode 100644
index 0000000..1c97816
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/MultidimensionalArraySerializerTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.SerializerTestInstance;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.api.java.typeutils.TypeInfoParser;
+import org.junit.Test;
+
+
+/**
+ * A serialization test for multidimensional arrays.
+ */
+public class MultidimensionalArraySerializerTest {
+
+ @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();
+ }
+
+ public static class MyPojo {
+ public String field1;
+ public int field2;
+
+ public MyPojo(String field1, int field2) {
+ this.field1 = field1;
+ this.field2 = field2;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof MyPojo)) {
+ return false;
+ }
+ MyPojo other = (MyPojo) obj;
+ return ((field1 == null && other.field1 == null) || (field1 != null && field1.equals(other.field1)))
+ && field2 == other.field2;
+ }
+ }
+
+ @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();
+ }
+
+ public static class MyGenericPojo<T> {
+ public T[][] field;
+
+ public MyGenericPojo() {
+ // nothing to do
+ }
+
+ public MyGenericPojo(T[][] field) {
+ this.field = field;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof MyGenericPojo)) {
+ return false;
+ }
+ MyGenericPojo<?> other = (MyGenericPojo<?>) obj;
+ return (field == null && other.field == null) || (field != null && field.length == other.field.length);
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testGenericObjectArrays() {
+ MyGenericPojo<String>[][] array = (MyGenericPojo<String>[][]) new MyGenericPojo[][]{
+ { new MyGenericPojo<String>(new String[][]{{"a", "b"},{"c", "d"}}), null}
+ };
+ TypeInformation ti = TypeInfoParser.parse("org.apache.flink.api.java.typeutils.runtime.MultidimensionalArraySerializerTest$MyGenericPojo<field=String[][]>[][]");
+
+ SerializerTestInstance testInstance = new SerializerTestInstance(ti.createSerializer(new ExecutionConfig()), MyGenericPojo[][].class, -1, (Object) array);
+ testInstance.testAll();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoComparatorTest.java
new file mode 100644
index 0000000..26b03c6
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoComparatorTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.util.Arrays;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.ComparatorTestBase;
+import org.apache.flink.api.common.typeutils.CompositeType;
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.operators.Keys.ExpressionKeys;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.junit.Assert;
+
+
+public class PojoComparatorTest extends ComparatorTestBase<PojoContainingTuple> {
+ TypeInformation<PojoContainingTuple> type = TypeExtractor.getForClass(PojoContainingTuple.class);
+
+ PojoContainingTuple[] data = new PojoContainingTuple[]{
+ new PojoContainingTuple(1, 1L, 1L),
+ new PojoContainingTuple(2, 2L, 2L),
+ new PojoContainingTuple(8519, 85190L, 85190L),
+ new PojoContainingTuple(8520, 85191L, 85191L),
+ };
+
+ @Override
+ protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
+ Assert.assertTrue(type instanceof CompositeType);
+ CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
+ ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
+ boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
+ Arrays.fill(orders, ascending);
+ return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
+ }
+
+ @Override
+ protected TypeSerializer<PojoContainingTuple> createSerializer() {
+ return type.createSerializer(new ExecutionConfig());
+ }
+
+ @Override
+ protected PojoContainingTuple[] getSortedTestData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoContainingTuple.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoContainingTuple.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoContainingTuple.java
new file mode 100644
index 0000000..ca17ee0
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoContainingTuple.java
@@ -0,0 +1,44 @@
+/*
+ * 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.java.tuple.Tuple2;
+
+/**
+ * This file belongs to the PojoComparatorTest test
+ *
+ */
+public class PojoContainingTuple {
+ public int someInt;
+ public String someString = "abc";
+ public Tuple2<Long, Long> theTuple;
+ public PojoContainingTuple() {}
+ public PojoContainingTuple(int i, long l1, long l2) {
+ someInt = i;
+ theTuple = new Tuple2<Long, Long>(l1, l2);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj instanceof PojoContainingTuple) {
+ PojoContainingTuple other = (PojoContainingTuple) obj;
+ return someInt == other.someInt && theTuple.equals(other.theTuple);
+ }
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoGenericTypeSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoGenericTypeSerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoGenericTypeSerializerTest.java
new file mode 100644
index 0000000..d405412
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoGenericTypeSerializerTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+
+public class PojoGenericTypeSerializerTest extends AbstractGenericTypeSerializerTest {
+
+ @Override
+ protected <T> TypeSerializer<T> createSerializer(Class<T> type) {
+ TypeInformation<T> typeInfo = TypeExtractor.getForClass(type);
+ return typeInfo.createSerializer(new ExecutionConfig());
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializerTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializerTest.java
new file mode 100644
index 0000000..260f7e9
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializerTest.java
@@ -0,0 +1,243 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.SerializerTestBase;
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor;
+import org.apache.flink.api.common.operators.Keys.ExpressionKeys;
+import org.apache.flink.api.common.operators.Keys.IncompatibleKeysException;
+import org.apache.flink.api.java.tuple.Tuple1;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.api.java.typeutils.PojoTypeInfo;
+import org.apache.flink.api.java.typeutils.TupleTypeInfo;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.base.Objects;
+
+/**
+ * A test for the {@link PojoSerializer}.
+ */
+public class PojoSerializerTest extends SerializerTestBase<PojoSerializerTest.TestUserClass> {
+ private TypeInformation<TestUserClass> type = TypeExtractor.getForClass(TestUserClass.class);
+
+ @Override
+ protected TypeSerializer<TestUserClass> createSerializer() {
+ TypeSerializer<TestUserClass> serializer = type.createSerializer(new ExecutionConfig());
+ assert(serializer instanceof PojoSerializer);
+ return serializer;
+ }
+
+ @Override
+ protected int getLength() {
+ return -1;
+ }
+
+ @Override
+ protected Class<TestUserClass> getTypeClass() {
+ return TestUserClass.class;
+ }
+
+ @Override
+ protected TestUserClass[] getTestData() {
+ Random rnd = new Random(874597969123412341L);
+
+ return new TestUserClass[]{
+ new TestUserClass(rnd.nextInt(), "foo", rnd.nextDouble(), new int[]{1, 2, 3}, new Date(),
+ new NestedTestUserClass(rnd.nextInt(), "foo@boo", rnd.nextDouble(), new int[]{10, 11, 12})),
+ new TestUserClass(rnd.nextInt(), "bar", rnd.nextDouble(), new int[]{4, 5, 6}, null,
+ new NestedTestUserClass(rnd.nextInt(), "bar@bas", rnd.nextDouble(), new int[]{20, 21, 22})),
+ new TestUserClass(rnd.nextInt(), null, rnd.nextDouble(), null, null, null),
+ new TestUserClass(rnd.nextInt(), "bar", rnd.nextDouble(), new int[]{4, 5, 6}, new Date(),
+ new NestedTestUserClass(rnd.nextInt(), "bar@bas", rnd.nextDouble(), new int[]{20, 21, 22}))
+ };
+
+ }
+
+ // User code class for testing the serializer
+ public static class TestUserClass {
+ public int dumm1;
+ public String dumm2;
+ public double dumm3;
+ public int[] dumm4;
+ public Date dumm5;
+
+ public NestedTestUserClass nestedClass;
+
+ public TestUserClass() {
+ }
+
+ public TestUserClass(int dumm1, String dumm2, double dumm3, int[] dumm4, Date dumm5, NestedTestUserClass nestedClass) {
+ this.dumm1 = dumm1;
+ this.dumm2 = dumm2;
+ this.dumm3 = dumm3;
+ this.dumm4 = dumm4;
+ this.dumm5 = dumm5;
+ this.nestedClass = nestedClass;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(dumm1, dumm2, dumm3, dumm4, nestedClass);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TestUserClass)) {
+ return false;
+ }
+ TestUserClass otherTUC = (TestUserClass) other;
+ if (dumm1 != otherTUC.dumm1) {
+ return false;
+ }
+ if ((dumm2 == null && otherTUC.dumm2 != null)
+ || (dumm2 != null && !dumm2.equals(otherTUC.dumm2))) {
+ return false;
+ }
+ if (dumm3 != otherTUC.dumm3) {
+ return false;
+ }
+ if ((dumm4 != null && otherTUC.dumm4 == null)
+ || (dumm4 == null && otherTUC.dumm4 != null)
+ || (dumm4 != null && otherTUC.dumm4 != null && dumm4.length != otherTUC.dumm4.length)) {
+ return false;
+ }
+ if (dumm4 != null && otherTUC.dumm4 != null) {
+ for (int i = 0; i < dumm4.length; i++) {
+ if (dumm4[i] != otherTUC.dumm4[i]) {
+ return false;
+ }
+ }
+ }
+
+ if ((nestedClass == null && otherTUC.nestedClass != null)
+ || (nestedClass != null && !nestedClass.equals(otherTUC.nestedClass))) {
+ return false;
+ }
+ return true;
+ }
+ }
+
+ public static class NestedTestUserClass {
+ public int dumm1;
+ public String dumm2;
+ public double dumm3;
+ public int[] dumm4;
+
+ public NestedTestUserClass() {
+ }
+
+ public NestedTestUserClass(int dumm1, String dumm2, double dumm3, int[] dumm4) {
+ this.dumm1 = dumm1;
+ this.dumm2 = dumm2;
+ this.dumm3 = dumm3;
+ this.dumm4 = dumm4;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(dumm1, dumm2, dumm3, dumm4);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof NestedTestUserClass)) {
+ return false;
+ }
+ NestedTestUserClass otherTUC = (NestedTestUserClass) other;
+ if (dumm1 != otherTUC.dumm1) {
+ return false;
+ }
+ if (!dumm2.equals(otherTUC.dumm2)) {
+ return false;
+ }
+ if (dumm3 != otherTUC.dumm3) {
+ return false;
+ }
+ if (dumm4.length != otherTUC.dumm4.length) {
+ return false;
+ }
+ for (int i = 0; i < dumm4.length; i++) {
+ if (dumm4[i] != otherTUC.dumm4[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ /**
+ * This tests if the hashes returned by the pojo and tuple comparators are the same
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testTuplePojoTestEquality() {
+
+ // test with a simple, string-key first.
+ PojoTypeInfo<TestUserClass> pType = (PojoTypeInfo<TestUserClass>) type;
+ List<FlatFieldDescriptor> result = new ArrayList<FlatFieldDescriptor>();
+ pType.getFlatFields("nestedClass.dumm2", 0, result);
+ int[] fields = new int[1]; // see below
+ fields[0] = result.get(0).getPosition();
+ TypeComparator<TestUserClass> pojoComp = pType.createComparator( fields, new boolean[]{true}, 0, new ExecutionConfig());
+
+ TestUserClass pojoTestRecord = new TestUserClass(0, "abc", 3d, new int[] {1,2,3}, new Date(), new NestedTestUserClass(1, "haha", 4d, new int[] {5,4,3}));
+ int pHash = pojoComp.hash(pojoTestRecord);
+
+ Tuple1<String> tupleTest = new Tuple1<String>("haha");
+ TupleTypeInfo<Tuple1<String>> tType = (TupleTypeInfo<Tuple1<String>>)TypeExtractor.getForObject(tupleTest);
+ TypeComparator<Tuple1<String>> tupleComp = tType.createComparator(new int[] {0}, new boolean[] {true}, 0, new ExecutionConfig());
+
+ int tHash = tupleComp.hash(tupleTest);
+
+ Assert.assertTrue("The hashing for tuples and pojos must be the same, so that they are mixable", pHash == tHash);
+
+ Tuple3<Integer, String, Double> multiTupleTest = new Tuple3<Integer, String, Double>(1, "haha", 4d); // its important here to use the same values.
+ TupleTypeInfo<Tuple3<Integer, String, Double>> multiTupleType = (TupleTypeInfo<Tuple3<Integer, String, Double>>)TypeExtractor.getForObject(multiTupleTest);
+
+ ExpressionKeys fieldKey = new ExpressionKeys(new int[]{1,0,2}, multiTupleType);
+ ExpressionKeys expressKey = new ExpressionKeys(new String[] {"nestedClass.dumm2", "nestedClass.dumm1", "nestedClass.dumm3"}, pType);
+ try {
+ Assert.assertTrue("Expecting the keys to be compatible", fieldKey.areCompatible(expressKey));
+ } catch (IncompatibleKeysException e) {
+ e.printStackTrace();
+ Assert.fail("Keys must be compatible: "+e.getMessage());
+ }
+ TypeComparator<TestUserClass> multiPojoComp = pType.createComparator( expressKey.computeLogicalKeyPositions(), new boolean[]{true, true, true}, 0, new ExecutionConfig());
+ int multiPojoHash = multiPojoComp.hash(pojoTestRecord);
+
+
+ // pojo order is: dumm2 (str), dumm1 (int), dumm3 (double).
+ TypeComparator<Tuple3<Integer, String, Double>> multiTupleComp = multiTupleType.createComparator(fieldKey.computeLogicalKeyPositions(), new boolean[] {true, true,true}, 0, new ExecutionConfig());
+ int multiTupleHash = multiTupleComp.hash(multiTupleTest);
+
+ Assert.assertTrue("The hashing for tuples and pojos must be the same, so that they are mixable. Also for those with multiple key fields", multiPojoHash == multiTupleHash);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/21a71586/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSubclassComparatorTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSubclassComparatorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSubclassComparatorTest.java
new file mode 100644
index 0000000..40c5c8c
--- /dev/null
+++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/runtime/PojoSubclassComparatorTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.ExecutionConfig;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.ComparatorTestBase;
+import org.apache.flink.api.common.typeutils.CompositeType;
+import org.apache.flink.api.common.typeutils.TypeComparator;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.common.operators.Keys.ExpressionKeys;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.junit.Assert;
+
+import java.util.Arrays;
+
+
+public class PojoSubclassComparatorTest extends ComparatorTestBase<PojoContainingTuple> {
+ TypeInformation<PojoContainingTuple> type = TypeExtractor.getForClass(PojoContainingTuple.class);
+
+ PojoContainingTuple[] data = new PojoContainingTuple[]{
+ new Subclass(1, 1L, 1L, 17L),
+ new Subclass(2, 2L, 2L, 42L),
+ new Subclass(8519, 85190L, 85190L, 117L),
+ new Subclass(8520, 85191L, 85191L, 93L),
+ };
+
+ @Override
+ protected TypeComparator<PojoContainingTuple> createComparator(boolean ascending) {
+ Assert.assertTrue(type instanceof CompositeType);
+ CompositeType<PojoContainingTuple> cType = (CompositeType<PojoContainingTuple>) type;
+ ExpressionKeys<PojoContainingTuple> keys = new ExpressionKeys<PojoContainingTuple>(new String[] {"theTuple.*"}, cType);
+ boolean[] orders = new boolean[keys.getNumberOfKeyFields()];
+ Arrays.fill(orders, ascending);
+ return cType.createComparator(keys.computeLogicalKeyPositions(), orders, 0, new ExecutionConfig());
+ }
+
+ @Override
+ protected TypeSerializer<PojoContainingTuple> createSerializer() {
+ return type.createSerializer(new ExecutionConfig());
+ }
+
+ @Override
+ protected PojoContainingTuple[] getSortedTestData() {
+ return data;
+ }
+
+ public static class Subclass extends PojoContainingTuple {
+
+ public long additionalField;
+
+ public Subclass() {
+ }
+
+ public Subclass(int i, long l1, long l2, long additionalField) {
+ super(i, l1, l2);
+ this.additionalField = additionalField;
+ }
+ }
+}