ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [11/16] ignite git commit: IGNITE-3240: fixed serialization of String and other primitive arrays by CacheObjectBinaryProcessorImpl
Date Mon, 06 Jun 2016 13:06:58 GMT
IGNITE-3240: fixed serialization of String and other primitive arrays by CacheObjectBinaryProcessorImpl


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

Branch: refs/heads/ignite-3258
Commit: 9e9252c2e4ed7380b3933909ac297f6618708980
Parents: e409b67
Author: Denis Magda <dmagda@gridgain.com>
Authored: Mon Jun 6 10:20:13 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Mon Jun 6 10:20:13 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryUtils.java     | 16 ++++
 .../processors/cache/CacheObjectContext.java    |  3 +
 .../GridCacheBinaryObjectsAbstractSelfTest.java | 78 +++++++++++++++++++-
 3 files changed, 95 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9e9252c2/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 e431474..0250e3b 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
@@ -655,6 +655,22 @@ public class BinaryUtils {
     }
 
     /**
+     * @param arr Array to check.
+     * @return {@code true} if this array is of a known type.
+     */
+    public static boolean knownArray(Object arr) {
+        if (arr == null)
+            return false;
+
+        Class<?> cls =  arr.getClass();
+
+        return cls == byte[].class || cls == short[].class || cls == int[].class || cls ==
long[].class ||
+            cls == float[].class || cls == double[].class || cls == char[].class || cls ==
boolean[].class ||
+            cls == String[].class || cls == UUID[].class || cls == Date[].class || cls ==
Timestamp[].class ||
+            cls == BigDecimal[].class;
+    }
+
+    /**
      * Attempts to create a new collection of the same known type. Will return null if collection
type is unknown.
      *
      * @param col Collection.

http://git-wip-us.apache.org/repos/asf/ignite/blob/9e9252c2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index d22bc75..d7fdb83 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -199,6 +199,9 @@ import org.apache.ignite.internal.util.typedef.F;
      * @return Result.
      */
     public Object[] unwrapBinariesInArrayIfNeeded(Object[] arr, boolean keepBinary, boolean
cpy) {
+        if (BinaryUtils.knownArray(arr))
+            return arr;
+
         Object[] res = new Object[arr.length];
 
         for (int i = 0; i < arr.length; i++)

http://git-wip-us.apache.org/repos/asf/ignite/blob/9e9252c2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index f776146..56cca39 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -17,13 +17,17 @@
 
 package org.apache.ignite.internal.processors.cache.binary;
 
+import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 import javax.cache.Cache;
 import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.EntryProcessorException;
@@ -60,6 +64,7 @@ import org.apache.ignite.lang.IgniteBiInClosure;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -422,6 +427,75 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends
GridCommonA
     /**
      * @throws Exception If failed.
      */
+    public void testBasicArrays() throws Exception {
+        IgniteCache<Integer, Object> cache = jcache(0);
+
+        checkArrayClass(cache, new String[] {"abc"});
+
+        checkArrayClass(cache, new byte[] {1});
+
+        checkArrayClass(cache, new short[] {1});
+
+        checkArrayClass(cache, new int[] {1});
+
+        checkArrayClass(cache, new long[] {1});
+
+        checkArrayClass(cache, new float[] {1});
+
+        checkArrayClass(cache, new double[] {1});
+
+        checkArrayClass(cache, new char[] {'a'});
+
+        checkArrayClass(cache, new boolean[] {false});
+
+        checkArrayClass(cache, new UUID[] {UUID.randomUUID()});
+
+        checkArrayClass(cache, new Date[] {new Date()});
+
+        checkArrayClass(cache, new Timestamp[] {new Timestamp(System.currentTimeMillis())});
+
+        checkArrayClass(cache, new BigDecimal[] {new BigDecimal(100)});
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomArrays() throws Exception {
+        fail("https://issues.apache.org/jira/browse/IGNITE-3244");
+
+        IgniteCache<Integer, TestObject[]> cache = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            TestObject[] arr = new TestObject[] {new TestObject(i)};
+
+            cache.put(0, arr);
+        }
+
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            TestObject[] obj = cache.get(i);
+
+            assertEquals(1, obj.length);
+            assertEquals(i, obj[0].val);
+        }
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @param arr Array to check.
+     */
+    private void checkArrayClass(IgniteCache<Integer, Object> cache, Object arr) {
+        cache.put(0, arr);
+
+        Object res = cache.get(0);
+
+        assertEquals(arr.getClass(), res.getClass());
+        GridTestUtils.deepEquals(arr, res);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testGetTx1() throws Exception {
         checkGetTx(PESSIMISTIC, REPEATABLE_READ);
     }
@@ -651,7 +725,6 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
             for (int j = 0; j < 10; j++)
                 keys.add(i++);
 
-
             cacheBinaryAsync.getAll(keys);
 
             Map<Integer, BinaryObject> objs = cacheBinaryAsync.<Map<Integer,
BinaryObject>>future().get();
@@ -1045,7 +1118,8 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends
GridCommonA
      * No-op entry processor.
      */
     private static class ObjectEntryProcessor implements EntryProcessor<Integer, TestObject,
Boolean> {
-        @Override public Boolean process(MutableEntry<Integer, TestObject> entry, Object...
args) throws EntryProcessorException {
+        @Override
+        public Boolean process(MutableEntry<Integer, TestObject> entry, Object... args)
throws EntryProcessorException {
             TestObject obj = entry.getValue();
 
             entry.setValue(new TestObject(obj.val));


Mime
View raw message