You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2014/09/19 20:27:13 UTC

git commit: Perform a deep copy of mutable thrift objects in generated FROM_BUILDER functions.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 012aca3d2 -> 1fd13473c


Perform a deep copy of mutable thrift objects in generated FROM_BUILDER functions.

Bugs closed: AURORA-729

Reviewed at https://reviews.apache.org/r/25840/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/1fd13473
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/1fd13473
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/1fd13473

Branch: refs/heads/master
Commit: 1fd13473cda4facd614b9df43c54099eb29275d9
Parents: 012aca3
Author: Bill Farner <wf...@apache.org>
Authored: Fri Sep 19 11:24:10 2014 -0700
Committer: Bill Farner <wf...@apache.org>
Committed: Fri Sep 19 11:24:10 2014 -0700

----------------------------------------------------------------------
 .../aurora/tools/java/thrift_wrapper_codegen.py |  2 +-
 .../storage/entities/IHostAttributesTest.java   | 43 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/1fd13473/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py b/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
index 95fbd89..c4ca3a2 100644
--- a/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
+++ b/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
@@ -176,7 +176,7 @@ public final class %(name)s {
       new Function<%(wrapped)s, %(name)s>() {
         @Override
         public %(name)s apply(%(wrapped)s input) {
-          return new %(name)s(input);
+          return %(name)s.build(input);
         }
       };
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/1fd13473/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java b/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
new file mode 100644
index 0000000..05b31c2
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed 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.aurora.scheduler.storage.entities;
+
+import com.google.common.collect.ImmutableSet;
+
+import org.apache.aurora.gen.Attribute;
+import org.apache.aurora.gen.HostAttributes;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class IHostAttributesTest {
+
+  @Test
+  public void testObjectDetachment() {
+    // AURORA-729: Immutable wrapper objects are not always immutable.
+    Attribute attribute = new Attribute()
+        .setName("attr")
+        .setValues(ImmutableSet.of("a", "b", "c"));
+    HostAttributes mutable = new HostAttributes()
+        .setHost("a")
+        .setAttributes(ImmutableSet.of(attribute));
+    IHostAttributes immutable1 = IHostAttributes.FROM_BUILDER.apply(mutable);
+    IHostAttributes immutable2 = IHostAttributes.build(mutable);
+    assertEquals(immutable1, immutable2);
+    assertEquals(immutable2, immutable1);
+    attribute.setValues(ImmutableSet.of("a"));
+    assertEquals(immutable1, immutable2);
+    assertEquals(immutable2, immutable1);
+  }
+}