avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1656749 - in /avro/trunk: CHANGES.txt lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
Date Tue, 03 Feb 2015 15:00:21 GMT
Author: tomwhite
Date: Tue Feb  3 15:00:21 2015
New Revision: 1656749

URL: http://svn.apache.org/r1656749
Log:
AVRO-1630. Java: Creating Builder from instance loses data. Contributed by Niels Basjes.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1656749&r1=1656748&r2=1656749&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Feb  3 15:00:21 2015
@@ -119,6 +119,9 @@ Trunk (not yet released)
     AVRO-1624. Java. Surefire forkMode is deprecated. (Niels Basjes via
     tomwhite)
 
+    AVRO-1630. Java: Creating Builder from instance loses data. (Niels Basjes
+    via tomwhite)
+
 Avro 1.7.7 (23 July 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm?rev=1656749&r1=1656748&r2=1656749&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
(original)
+++ avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
Tue Feb  3 15:00:21 2015
@@ -260,7 +260,11 @@ public class ${this.mangle($schema.getNa
      */
     public ${this.javaType($field.schema())}.Builder ${this.generateGetBuilderMethod($schema,
$field)}() {
       if (${this.mangle($field.name(), $schema.isError())}Builder == null) {
-        ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder());
+        if (${this.generateHasMethod($schema, $field)}()) {
+          ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder(${this.mangle($field.name(),
$schema.isError())}));
+        } else {
+          ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder());
+        }
       }
       return ${this.mangle($field.name(), $schema.isError())}Builder;
     }

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java?rev=1656749&r1=1656748&r2=1656749&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
Tue Feb  3 15:00:21 2015
@@ -116,6 +116,58 @@ public class TestSpecificBuilderTree {
     assertEquals("Bar",             request2.getHttpRequest().getURI().getParameters().get(0).getValue());
   }
 
+  @Test
+  public void createBuilderFromInstance(){
+    Request.Builder requestBuilder1 = createPartialBuilder();
+    requestBuilder1
+      .getConnectionBuilder()
+        .setNetworkAddress("1.1.1.1");
+
+    Request request1 = requestBuilder1.build();
+
+    Request.Builder requestBuilder2 = Request.newBuilder(request1);
+
+    requestBuilder2
+      .getConnectionBuilder()
+        .setNetworkAddress("2.2.2.2");
+
+    requestBuilder2
+      .getHttpRequestBuilder()
+        .getUserAgentBuilder()
+          .setId("Bar");
+
+    requestBuilder2
+      .getHttpRequestBuilder()
+        .getURIBuilder()
+          .setMethod(HttpMethod.POST);
+
+    requestBuilder2
+      .getHttpRequestBuilder()
+        .getUserAgentBuilder()
+          .setUseragent("Firefox 456");
+
+    Request request2 = requestBuilder2.build();
+
+    assertEquals(NetworkType.IPv4,  request1.getConnection().getNetworkType());
+    assertEquals("1.1.1.1",         request1.getConnection().getNetworkAddress());
+    assertEquals("Chrome 123",      request1.getHttpRequest().getUserAgent().getUseragent());
+    assertEquals("Foo",             request1.getHttpRequest().getUserAgent().getId());
+    assertEquals(HttpMethod.GET,    request1.getHttpRequest().getURI().getMethod());
+    assertEquals("/index.html",     request1.getHttpRequest().getURI().getPath());
+    assertEquals(1,                 request1.getHttpRequest().getURI().getParameters().size());
+    assertEquals("Foo",             request1.getHttpRequest().getURI().getParameters().get(0).getName());
+    assertEquals("Bar",             request1.getHttpRequest().getURI().getParameters().get(0).getValue());
+
+    assertEquals(NetworkType.IPv4,  request2.getConnection().getNetworkType());
+    assertEquals("2.2.2.2",         request2.getConnection().getNetworkAddress());
+    assertEquals("Firefox 456",     request2.getHttpRequest().getUserAgent().getUseragent());
+    assertEquals("Bar",             request2.getHttpRequest().getUserAgent().getId());
+    assertEquals(HttpMethod.POST,   request2.getHttpRequest().getURI().getMethod());
+    assertEquals("/index.html",     request2.getHttpRequest().getURI().getPath());
+    assertEquals(1,                 request2.getHttpRequest().getURI().getParameters().size());
+    assertEquals("Foo",             request2.getHttpRequest().getURI().getParameters().get(0).getName());
+    assertEquals("Bar",             request2.getHttpRequest().getURI().getParameters().get(0).getValue());
+  }
 
   private Request.Builder createLastOneTestsBuilder() {
     Request.Builder requestBuilder = Request.newBuilder();



Mime
View raw message