avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [1/2] avro git commit: AVRO-1933: Add more specific error details to SchemaCompatibility class
Date Thu, 07 Sep 2017 12:23:26 GMT
Repository: avro
Updated Branches:
  refs/heads/master 189368ed4 -> db8ed216e


http://git-wip-us.apache.org/repos/asf/avro/blob/db8ed216/lang/java/avro/src/test/java/org/apache/avro/TestSchemas.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemas.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemas.java
new file mode 100644
index 0000000..264e7e6
--- /dev/null
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemas.java
@@ -0,0 +1,139 @@
+/**
+ * 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.avro;
+
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.Collections;
+import org.apache.avro.Schema.Field;
+
+/** Schemas used by other tests in this package. Therefore package protected. */
+public class TestSchemas {
+
+  static final Schema NULL_SCHEMA = Schema.create(Schema.Type.NULL);
+  static final Schema BOOLEAN_SCHEMA = Schema.create(Schema.Type.BOOLEAN);
+  static final Schema INT_SCHEMA = Schema.create(Schema.Type.INT);
+  static final Schema LONG_SCHEMA = Schema.create(Schema.Type.LONG);
+  static final Schema FLOAT_SCHEMA = Schema.create(Schema.Type.FLOAT);
+  static final Schema DOUBLE_SCHEMA = Schema.create(Schema.Type.DOUBLE);
+  static final Schema STRING_SCHEMA = Schema.create(Schema.Type.STRING);
+  static final Schema BYTES_SCHEMA = Schema.create(Schema.Type.BYTES);
+
+  static final Schema INT_ARRAY_SCHEMA = Schema.createArray(INT_SCHEMA);
+  static final Schema LONG_ARRAY_SCHEMA = Schema.createArray(LONG_SCHEMA);
+  static final Schema STRING_ARRAY_SCHEMA = Schema.createArray(STRING_SCHEMA);
+
+  static final Schema INT_MAP_SCHEMA = Schema.createMap(INT_SCHEMA);
+  static final Schema LONG_MAP_SCHEMA = Schema.createMap(LONG_SCHEMA);
+  static final Schema STRING_MAP_SCHEMA = Schema.createMap(STRING_SCHEMA);
+
+  static final Schema ENUM1_AB_SCHEMA = Schema.createEnum("Enum1", null, null, list("A",
"B"));
+  static final Schema ENUM1_ABC_SCHEMA = Schema.createEnum("Enum1", null, null,
+      list("A", "B", "C"));
+  static final Schema ENUM1_BC_SCHEMA = Schema.createEnum("Enum1", null, null, list("B",
"C"));
+  static final Schema ENUM2_AB_SCHEMA = Schema.createEnum("Enum2", null, null, list("A",
"B"));
+
+  static final Schema EMPTY_UNION_SCHEMA = Schema.createUnion(new ArrayList<Schema>());
+  static final Schema NULL_UNION_SCHEMA = Schema.createUnion(list(NULL_SCHEMA));
+  static final Schema INT_UNION_SCHEMA = Schema.createUnion(list(INT_SCHEMA));
+  static final Schema LONG_UNION_SCHEMA = Schema.createUnion(list(LONG_SCHEMA));
+  static final Schema FLOAT_UNION_SCHEMA = Schema.createUnion(list(FLOAT_SCHEMA));
+  static final Schema DOUBLE_UNION_SCHEMA = Schema.createUnion(list(DOUBLE_SCHEMA));
+  static final Schema STRING_UNION_SCHEMA = Schema.createUnion(list(STRING_SCHEMA));
+  static final Schema BYTES_UNION_SCHEMA = Schema.createUnion(list(BYTES_SCHEMA));
+  static final Schema INT_STRING_UNION_SCHEMA = Schema.createUnion(list(INT_SCHEMA, STRING_SCHEMA));
+  static final Schema STRING_INT_UNION_SCHEMA = Schema.createUnion(list(STRING_SCHEMA, INT_SCHEMA));
+  static final Schema INT_FLOAT_UNION_SCHEMA = Schema.createUnion(list(INT_SCHEMA, FLOAT_SCHEMA));
+  static final Schema INT_LONG_UNION_SCHEMA = Schema.createUnion(list(INT_SCHEMA, LONG_SCHEMA));
+  static final Schema INT_LONG_FLOAT_DOUBLE_UNION_SCHEMA = Schema
+      .createUnion(list(INT_SCHEMA, LONG_SCHEMA, FLOAT_SCHEMA, DOUBLE_SCHEMA));
+
+  // Non recursive records:
+  static final Schema EMPTY_RECORD1 = Schema.createRecord("Record1", null, null, false);
+  static final Schema EMPTY_RECORD2 = Schema.createRecord("Record2", null, null, false);
+  static final Schema A_INT_RECORD1 = Schema.createRecord("Record1", null, null, false);
+  static final Schema A_LONG_RECORD1 = Schema.createRecord("Record1", null, null, false);
+  static final Schema A_INT_B_INT_RECORD1 = Schema.createRecord("Record1", null, null, false);
+  static final Schema A_DINT_RECORD1 = // DTYPE means TYPE with default value
+      Schema.createRecord("Record1", null, null, false);
+  static final Schema A_INT_B_DINT_RECORD1 = Schema.createRecord("Record1", null, null, false);
+  static final Schema A_DINT_B_DINT_RECORD1 = Schema.createRecord("Record1", null, null,
false);
+
+  static final Schema FIXED_4_BYTES = Schema.createFixed("Fixed", null, null, 4);
+  static final Schema FIXED_8_BYTES = Schema.createFixed("Fixed", null, null, 8);
+
+  static {
+    EMPTY_RECORD1.setFields(Collections.<Field>emptyList());
+    EMPTY_RECORD2.setFields(Collections.<Field>emptyList());
+    A_INT_RECORD1.setFields(list(new Field("a", INT_SCHEMA, null, null)));
+    A_LONG_RECORD1.setFields(list(new Field("a", LONG_SCHEMA, null, null)));
+    A_INT_B_INT_RECORD1.setFields(
+        list(new Field("a", INT_SCHEMA, null, null), new Field("b", INT_SCHEMA, null, null)));
+    A_DINT_RECORD1.setFields(list(new Field("a", INT_SCHEMA, null, 0)));
+    A_INT_B_DINT_RECORD1.setFields(
+        list(new Field("a", INT_SCHEMA, null, null), new Field("b", INT_SCHEMA, null, 0)));
+    A_DINT_B_DINT_RECORD1
+        .setFields(list(new Field("a", INT_SCHEMA, null, 0), new Field("b", INT_SCHEMA, null,
0)));
+  }
+
+  // Recursive records
+  static final Schema INT_LIST_RECORD = Schema.createRecord("List", null, null, false);
+  static final Schema LONG_LIST_RECORD = Schema.createRecord("List", null, null, false);
+  static {
+    INT_LIST_RECORD.setFields(list(new Field("head", INT_SCHEMA, null, null),
+        new Field("tail", INT_LIST_RECORD, null, null)));
+    LONG_LIST_RECORD.setFields(list(new Field("head", LONG_SCHEMA, null, null),
+        new Field("tail", LONG_LIST_RECORD, null, null)));
+  }
+
+  // -----------------------------------------------------------------------------------------------
+
+  /** Reader/writer schema pair. */
+  static final class ReaderWriter {
+    private final Schema mReader;
+    private final Schema mWriter;
+
+    public ReaderWriter(final Schema reader, final Schema writer) {
+      mReader = reader;
+      mWriter = writer;
+    }
+
+    public Schema getReader() {
+      return mReader;
+    }
+
+    public Schema getWriter() {
+      return mWriter;
+    }
+  }
+
+  /** Borrowed from the Guava library. */
+  static <E> ArrayList<E> list(E... elements) {
+    final ArrayList<E> list = new ArrayList<>();
+    Collections.addAll(list, elements);
+    return list;
+  }
+
+  static void assertSchemaContains(Schema schemaSubset, Schema original) {
+    String subset = schemaSubset.toString(false);
+    String whole = original.toString(false);
+    assertTrue(String.format("Subset '%s' not found in '%s'", subset, whole),
+        whole.contains(subset));
+  }
+
+}


Mime
View raw message