Author: cutting
Date: Fri Sep 25 21:54:22 2009
New Revision: 819039
URL: http://svn.apache.org/viewvc?rev=819039&view=rev
Log:
AVRO-101. Add Java reflect API test case using nested classes. Contributed by
Eelco Hillenius.
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=819039&r1=819038&r2=819039&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Fri Sep 25 21:54:22 2009
@@ -68,6 +68,9 @@
AVRO-125. Fix sample protocol in specification document to use
the correct syntax. (cutting)
+ AVRO-101. Add Java reflect API test case using nested classes.
+ (Eelco Hillenius via cutting)
+
Avro 1.1.0 (8 September 2009)
INCOMPATIBLE CHANGES
Modified:
hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java?rev=819039&r1=819038&r2=819039&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
(original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
Fri Sep 25 21:54:22 2009
@@ -154,6 +154,35 @@
reader.close();
}
+ /*
+ * Test that writing out and reading in a nested class works
+ */
+ @Test
+ public void testNestedClass() throws IOException {
+ FileOutputStream fos = new FileOutputStream(FILE);
+
+ Schema schema = ReflectData.get().getSchema(BazRecord.class);
+ DataFileWriter<Object> writer = new DataFileWriter<Object>(schema, fos,
+ new ReflectDatumWriter(schema));
+
+ // test writing to a file
+ CheckList check = new CheckList();
+ write(writer, new BazRecord(10), check);
+ write(writer, new BazRecord(20), check);
+ writer.close();
+
+ ReflectDatumReader din = new ReflectDatumReader();
+ SeekableFileInput sin = new SeekableFileInput(FILE);
+ DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
+ Object datum = null;
+ long count = reader.getMetaLong("count");
+ for (int i = 0; i < count; i++) {
+ datum = reader.next(datum);
+ check.assertEquals(datum, i);
+ }
+ reader.close();
+ }
+
private void write(DataFileWriter<Object> writer, Object o, CheckList l)
throws IOException {
writer.append(l.addAndReturn(o));
@@ -173,4 +202,33 @@
Assert.assertEquals(toCheck, o);
}
}
+
+ private static class BazRecord {
+ private int nbr;
+
+ public BazRecord() {
+ }
+
+ public BazRecord(int nbr) {
+ this.nbr = nbr;
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (that instanceof BazRecord) {
+ return this.nbr == ((BazRecord) that).nbr;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return nbr;
+ }
+
+ @Override
+ public String toString() {
+ return BazRecord.class.getSimpleName() + "{cnt=" + nbr + "}";
+ }
+ }
}