Example #1
0
 @Test
 /**
  * Test that equals() and hashCode() don't require exponential time on certain pathological
  * schemas.
  */
 public void testSchemaExplosion() throws Exception {
   for (int i = 1; i < 15; i++) { // 15 is big enough to trigger
     // create a list of records, each with a single field whose type is a
     // union of all of the records.
     List<Schema> recs = new ArrayList<Schema>();
     for (int j = 0; j < i; j++)
       recs.add(Schema.createRecord("" + (char) ('A' + j), null, null, false));
     for (Schema s : recs) {
       Schema union = Schema.createUnion(recs);
       Field f = new Field("x", union, null, null);
       List<Field> fields = new ArrayList<Field>();
       fields.add(f);
       s.setFields(fields);
     }
     // check that equals and hashcode are correct and complete in a
     // reasonable amount of time
     for (Schema s1 : recs) {
       Schema s2 = Schema.parse(s1.toString());
       assertEquals(s1.hashCode(), s2.hashCode());
       assertEquals(s1, s2);
     }
   }
 }
Example #2
0
 private static void checkUnionError(Schema[] branches) {
   List<Schema> branchList = Arrays.asList(branches);
   try {
     Schema.createUnion(branchList);
     fail("Union should not have constructed from: " + branchList);
   } catch (AvroRuntimeException are) {
     return;
   }
 }
Example #3
0
 @Test
 public void testNestedNullNamespaceReferencingWithUnion() {
   Schema inner = Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
   Schema innerUnion = Schema.createUnion(Arrays.asList(inner, Schema.create(Type.NULL)));
   Schema outer = Schema.createRecord("Outer", null, "space", false);
   outer.setFields(
       Arrays.asList(
           new Field("f1", innerUnion, null, null), new Field("f2", innerUnion, null, null)));
   assertEquals(outer, Schema.parse(outer.toString()));
 }
Example #4
0
 private static Schema buildUnion(Schema[] branches) {
   List<Schema> branchList = Arrays.asList(branches);
   return Schema.createUnion(branchList);
 }