You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2009/11/13 01:34:15 UTC
svn commit: r835670 - in /hadoop/avro/trunk: CHANGES.txt build.xml
src/java/org/apache/avro/Protocol.java src/java/org/apache/avro/Schema.java
src/test/java/org/apache/avro/TestReflect.java
Author: cutting
Date: Fri Nov 13 00:34:15 2009
New Revision: 835670
URL: http://svn.apache.org/viewvc?rev=835670&view=rev
Log:
AVRO-171. Fix Java's Protocol#toString() to correctly handle forward-references.
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/build.xml
hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java
hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java
Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=835670&r1=835669&r2=835670&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Fri Nov 13 00:34:15 2009
@@ -93,6 +93,9 @@
equals() and hashCode() to be consistent with compareTo().
(cutting)
+ AVRO-171. Fix Java's Protocol#toString() to correctly handle
+ forward-references. (cutting)
+
Avro 1.2.0 (14 October 2009)
INCOMPATIBLE CHANGES
Modified: hadoop/avro/trunk/build.xml
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/build.xml?rev=835670&r1=835669&r2=835670&view=diff
==============================================================================
--- hadoop/avro/trunk/build.xml (original)
+++ hadoop/avro/trunk/build.xml Fri Nov 13 00:34:15 2009
@@ -244,6 +244,8 @@
</taskdef>
<paranamer sourceDirectory="${test.java.generated.dir}"
outputDirectory="${test.java.generated.classes}"/>
+ <paranamer sourceDirectory="${test.java.src.dir}"
+ outputDirectory="${test.java.classes}"/>
</target>
<macrodef name="java-avro-compiler">
Modified: hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java?rev=835670&r1=835669&r2=835670&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/Protocol.java Fri Nov 13 00:34:15 2009
@@ -212,8 +212,10 @@
gen.writeStringField("namespace", namespace);
gen.writeArrayFieldStart("types");
+ Schema.Names resolved = new Schema.Names(namespace);
for (Schema type : types.values())
- type.toJson(types.except(type), gen);
+ if (!resolved.contains(type))
+ type.toJson(resolved, gen);
gen.writeEndArray();
gen.writeObjectFieldStart("messages");
Modified: hadoop/avro/trunk/src/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/Schema.java?rev=835670&r1=835669&r2=835670&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/Schema.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/Schema.java Fri Nov 13 00:34:15 2009
@@ -670,6 +670,9 @@
}
return super.get(name);
}
+ public boolean contains(Schema schema) {
+ return get(((NamedSchema)schema).name) != null;
+ }
public void add(Schema schema) {
put(((NamedSchema)schema).name, schema);
}
@@ -679,16 +682,6 @@
throw new SchemaParseException("Can't redefine: "+name);
return super.put(name, schema);
}
- public Names except(final Schema schema) {
- final Names parent = this;
- return new Names(space) {
- public Schema get(Object o) {
- if (this.containsKey(o)) return this.get(o);
- if (((NamedSchema)schema).name.equals(o)) return null;
- return parent.get(o);
- }
- };
- }
}
/** @see #parse(String) */
Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java?rev=835670&r1=835669&r2=835670&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java Fri Nov 13 00:34:15 2009
@@ -149,4 +149,23 @@
}
}
}
+
+ public static class X { int i; }
+ public static class B1 { X x; }
+ public static class B2 { X x; }
+ public static class A { B1 b1; B2 b2; }
+ public static interface C { void foo(A a); }
+
+ @Test
+ public void testForwardReference() {
+ ReflectData data = ReflectData.get();
+ Protocol reflected = data.getProtocol(C.class);
+ Protocol reparsed = Protocol.parse(reflected.toString());
+ assertEquals(reflected, reparsed);
+ assert(reparsed.getTypes().contains(data.getSchema(A.class)));
+ assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
+ assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
+ assert(reparsed.getTypes().contains(data.getSchema(X.class)));
+ }
+
}