ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject [17/17] ignite git commit: IGNITE-2849: disallowed to build a BinaryObject if old field's metadata is Object and the new one is different from it
Date Mon, 21 Mar 2016 12:43:38 GMT
IGNITE-2849: disallowed to build a BinaryObject if old field's metadata is Object and the new
one is different from it


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4846b21f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4846b21f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4846b21f

Branch: refs/heads/ignite-2849
Commit: 4846b21f5ebfa2b1cc8ea1cd02a811d168168ce8
Parents: 9d5dbd3
Author: Denis Magda <dmagda@gridgain.com>
Authored: Mon Mar 21 15:43:16 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Mon Mar 21 15:43:16 2016 +0300

----------------------------------------------------------------------
 .../binary/builder/BinaryObjectBuilderImpl.java |  9 +++--
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 36 +++++++++++++-------
 ...naryObjectBuilderDefaultMappersSelfTest.java |  2 +-
 3 files changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4846b21f/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 3477dc1..16c51b0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -383,18 +383,17 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder
{
         else
             newFldTypeId = BinaryUtils.typeByClass(newVal.getClass());
 
-        String newFldTypeName = BinaryUtils.fieldTypeName(newFldTypeId);
-
         if (oldFldTypeName == null) {
             // It's a new field, we have to add it to metadata.
             if (fieldsMeta == null)
                 fieldsMeta = new HashMap<>();
 
-            fieldsMeta.put(name, BinaryUtils.fieldTypeId(newFldTypeName));
+            fieldsMeta.put(name, newFldTypeId);
         }
         else if (!nullFieldVal) {
-            if (!oldFldTypeName.equals(newFldTypeName) &&
-                BinaryUtils.fieldTypeId(oldFldTypeName) != GridBinaryMarshaller.OBJ) {
+            String newFldTypeName = BinaryUtils.fieldTypeName(newFldTypeId);
+
+            if (!F.eq(newFldTypeName, oldFldTypeName)) {
                 throw new BinaryObjectException(
                     "Wrong value has been set [" +
                         "typeName=" + (typeName == null ? meta.typeName() : typeName) +

http://git-wip-us.apache.org/repos/asf/ignite/blob/4846b21f/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index e7988cf..e3e538b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -499,7 +499,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2},
new UUID(3, 0)};
 
-        mutObj.setField("foo", createdArr.clone());
+        mutObj.setField("foo", createdArr.clone(), Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
@@ -556,7 +556,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1,
2));
 
-        mutObj.setField("foo", list);
+        mutObj.setField("foo", list, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
@@ -654,7 +654,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1,
2))));
 
-        mutObj.setField("foo", list);
+        mutObj.setField("foo", list, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
@@ -737,7 +737,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
 
-        mutObj.setField("foo", c);
+        mutObj.setField("foo", c, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
@@ -816,7 +816,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b",
mutObj));
 
-        mutObj.setField("foo", map);
+        mutObj.setField("foo", map, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
@@ -1005,11 +1005,16 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         builder.build();
 
-        builder = binaries().builder("SomeType");
+        try {
+            builder = binaries().builder("SomeType");
 
-        builder.setField("dateField", new Date());
+            builder.setField("dateField", new Date());
 
-        builder.build();
+            builder.build();
+        }
+        catch (BinaryObjectException ex) {
+            assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
+        }
 
         builder = binaries().builder("SomeType");
 
@@ -1037,11 +1042,16 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObject obj = builder.build();
 
-        builder = binaries().builder(obj);
+        try {
+            builder = binaries().builder(obj);
 
-        builder.setField("dateField", new Date());
+            builder.setField("dateField", new Date());
 
-        builder.build();
+            builder.build();
+        }
+        catch (BinaryObjectException ex) {
+            assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
+        }
 
         builder = binaries().builder(obj);
 
@@ -1163,7 +1173,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         Date[] arr = {new Date()};
 
-        mutableObj.setField("foo", arr);
+        mutableObj.setField("foo", arr, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
 
@@ -1182,7 +1192,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         Timestamp[] arr = {new Timestamp(100020003)};
 
-        mutableObj.setField("foo", arr);
+        mutableObj.setField("foo", arr, Object.class);
 
         GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4846b21f/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
index 9659c39..4fc5c6c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderDefaultMappersSelfTest.java
@@ -146,7 +146,7 @@ public class BinaryObjectBuilderDefaultMappersSelfTest extends GridCommonAbstrac
 
         builder = builder(obj);
 
-        builder.setField("objField", "value");
+        builder.setField("objField", "value", Object.class);
         builder.setField("otherField", (Object)null);
 
         obj = builder.build();


Mime
View raw message