Repository: ignite
Updated Branches:
  refs/heads/ignite-3098 5f4a4398a -> 78e8a7be8


IGNITE-3098: fixes


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

Branch: refs/heads/ignite-3098
Commit: 78e8a7be8c2eb25c3ad7914770e76fa7ec2c657e
Parents: 5f4a439
Author: Denis Magda <[email protected]>
Authored: Tue May 17 15:44:25 2016 +0300
Committer: Denis Magda <[email protected]>
Committed: Tue May 17 15:44:25 2016 +0300

----------------------------------------------------------------------
 .../apache/ignite/IgniteSystemProperties.java   |  2 ++
 .../ignite/internal/binary/BinaryUtils.java     |  2 +-
 .../binary/BinaryMarshallerSelfTest.java        | 38 ++++++++++++++++++--
 3 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/78e8a7be/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java 
b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index b8cae3e..c28181e 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -395,6 +395,8 @@ public final class IgniteSystemProperties {
 
     /**
      * Manages type of serialization mechanism for {@link String} that is 
marshalled/unmarshalled by BinaryMarshaller.
+     * Should be used for cases when a String contains a surrogate symbol 
without its pair one. This is frequently used
+     * in algorithms that encrypts data in String format.
      */
     public static final String 
IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2 =
         "IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2";

http://git-wip-us.apache.org/repos/asf/ignite/blob/78e8a7be/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index 157d47b..f1a7759 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -79,7 +79,7 @@ public class BinaryUtils {
 
     /** */
     public static final boolean USE_STR_SERIALIZATION_VER_2 = 
IgniteSystemProperties.getBoolean(
-        IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2, true);
+        IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2, false);
 
     /** {@code true} if serialized value of this type cannot contain 
references to objects. */
     private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];

http://git-wip-us.apache.org/repos/asf/ignite/blob/78e8a7be/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index a45f13d..936b1e6 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -26,6 +26,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -89,6 +90,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 
+import static 
org.apache.ignite.IgniteSystemProperties.IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2;
 import static 
org.apache.ignite.internal.binary.streams.BinaryMemoryAllocator.INSTANCE;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotEquals;
@@ -181,7 +183,21 @@ public class BinaryMarshallerSelfTest extends 
GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    public void testString() throws Exception {
+    public void testStringVer1() throws Exception {
+        doTestString(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStringVer2() throws Exception {
+        doTestString(true);
+    }
+
+    /**
+     * @throws Exception If failed
+     */
+    private void doTestString(boolean ver2) throws Exception {
         // Ascii check.
         String str = "ascii0123456789";
         assertEquals(str, marshalUnmarshal(str));
@@ -204,16 +220,32 @@ public class BinaryMarshallerSelfTest extends 
GridCommonAbstractTest {
 
         // Special symbols check.
         str = new String(new char[] {0xD800, '的', 0xD800, 0xD800, 0xDC00, 
0xDFFF});
-        assertEquals(str, marshalUnmarshal(str));
+        if (ver2) {
+            bytes = BinaryUtils.strToUtf8Bytes(str);
+            assertEquals(str, BinaryUtils.utf8BytesToStr(bytes, 0, 
bytes.length));
+        }
+        else
+            assertNotEquals(str, marshalUnmarshal(str));
 
         str = new String(new char[] {55296});
-        assertEquals(str, marshalUnmarshal(str));
+        if (ver2) {
+            bytes = BinaryUtils.strToUtf8Bytes(str);
+            assertEquals(str, BinaryUtils.utf8BytesToStr(bytes, 0, 
bytes.length));
+        }
+        else
+            assertNotEquals(str, marshalUnmarshal(str));
+
+        bytes = str.getBytes(UTF_8);
+        assertNotEquals(str, new String(bytes, UTF_8));
 
         bytes = str.getBytes(UTF_8);
         assertNotEquals(str, BinaryUtils.utf8BytesToStr(bytes, 0, 
bytes.length));
 
         str = new String(new char[] {0xD801, 0xDC37});
         assertEquals(str, marshalUnmarshal(str));
+
+        bytes = str.getBytes(UTF_8);
+        assertEquals(str, new String(bytes, UTF_8));
     }
 
     /**

Reply via email to