avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1055215 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/specific/ lang/java/ipc/src/test/java/org/apache/avro/specific/ share/test/schemas/
Date Tue, 04 Jan 2011 22:28:36 GMT
Author: cutting
Date: Tue Jan  4 22:28:36 2011
New Revision: 1055215

URL: http://svn.apache.org/viewvc?rev=1055215&view=rev
Log:
AVRO-717. Java: Fix SpecificDatumWriter default constructor to correctly reference SpecificData.
 Contributed by Joe Crobak.

Added:
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumWriter.java
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumWriter.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
    avro/trunk/share/test/schemas/simple.avpr

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1055215&r1=1055214&r2=1055215&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Jan  4 22:28:36 2011
@@ -155,6 +155,9 @@ Avro 1.4.1 (13 October 2010)
     AVRO-667. GenericArray fails to compare with List. SpecificRecord
     compare gets ClassCastException. (scottcarey & cutting)
 
+    AVRO-717. Java: Fix SpecificDatumWriter default constructor to
+    correctly reference SpecificData.  (Joe Crobak via cutting)
+
 Avro 1.4.0 (31 August 2010)
 
   INCOMPATIBLE CHANGES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumWriter.java?rev=1055215&r1=1055214&r2=1055215&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumWriter.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumWriter.java
Tue Jan  4 22:28:36 2011
@@ -25,7 +25,9 @@ import org.apache.avro.io.Encoder;
 
 /** {@link org.apache.avro.io.DatumWriter DatumWriter} for generated Java classes. */
 public class SpecificDatumWriter<T> extends GenericDatumWriter<T> {
-  public SpecificDatumWriter() {}
+  public SpecificDatumWriter() {
+    super(SpecificData.get());
+  }
 
   public SpecificDatumWriter(Class<T> c) {
     super(SpecificData.get().getSchema(c), SpecificData.get());

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java?rev=1055215&r1=1055214&r2=1055215&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificCompiler.java
Tue Jan  4 22:28:36 2011
@@ -177,7 +177,7 @@ public class TestSpecificCompiler {
   public void testProtocolWithDocs() throws IOException {
     Protocol protocol = TestProtocolParsing.getSimpleProtocol();
     Collection<OutputFile> out = new SpecificCompiler(protocol).compile();
-    assertEquals(5, out.size());
+    assertEquals(6, out.size());
     int count = 0;
     for (OutputFile o : out) {
       if (o.path.endsWith("Simple.java")) {

Added: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumWriter.java?rev=1055215&view=auto
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumWriter.java
(added)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumWriter.java
Tue Jan  4 22:28:36 2011
@@ -0,0 +1,55 @@
+/**
+ * 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.specific;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.avro.Schema;
+import org.apache.avro.io.JsonEncoder;
+import org.apache.avro.test.Kind;
+import org.apache.avro.test.TestRecordWithUnion;
+import org.junit.Test;
+
+public class TestSpecificDatumWriter {
+  @Test
+  public void testResolveUnion() throws IOException {
+    final SpecificDatumWriter<TestRecordWithUnion> writer = new SpecificDatumWriter<TestRecordWithUnion>();
+    Schema schema = TestRecordWithUnion.SCHEMA$;
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    JsonEncoder encoder = new JsonEncoder(schema, out);
+
+    writer.setSchema(schema);
+
+    TestRecordWithUnion c = new TestRecordWithUnion();
+    c.kind = Kind.BAR;
+    c.value = "rab";
+    writer.write(c, encoder);
+    encoder.flush();
+    out.close();
+
+    String expectedJson = String.format(
+        "{'kind':{'Kind':'%s'},'value':{'string':'%s'}}", c.kind.toString(),
+        c.value).replace('\'', '"');
+
+    assertEquals(expectedJson, out.toString("UTF-8"));
+  }
+
+}

Modified: avro/trunk/share/test/schemas/simple.avpr
URL: http://svn.apache.org/viewvc/avro/trunk/share/test/schemas/simple.avpr?rev=1055215&r1=1055214&r2=1055215&view=diff
==============================================================================
--- avro/trunk/share/test/schemas/simple.avpr (original)
+++ avro/trunk/share/test/schemas/simple.avpr Tue Jan  4 22:28:36 2011
@@ -18,6 +18,13 @@
      {"name": "TestError", "type": "error", "fields": [
          {"name": "message", "type": "string"}
       ]
+     },
+
+     {"name": "TestRecordWithUnion", "type": "record",
+      "fields": [
+          {"name": "kind", "type": ["null", "Kind"]},
+          {"name": "value", "type": ["null", "string"]}
+      ]
      }
 
  ],



Mime
View raw message