You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2016/12/29 09:37:44 UTC

[40/50] [abbrv] ignite git commit: IGNITE-4109 - BinaryType.isEnum() throws an exception if typeId==0

IGNITE-4109 - BinaryType.isEnum() throws an exception if typeId==0

(cherry picked from commit 2ccae40)


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

Branch: refs/heads/ignite-3477
Commit: 8070da317fec537b130164cac03a0b56e2bf388f
Parents: 7677f5f
Author: dkarachentsev <dk...@gridgain.com>
Authored: Fri Dec 23 17:51:49 2016 +0300
Committer: dkarachentsev <dk...@gridgain.com>
Committed: Mon Dec 26 13:21:52 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java     |  4 ++--
 .../ignite/internal/binary/BinaryTypeProxy.java   | 15 ++++++++++++---
 .../ignite/internal/binary/BinaryUtils.java       |  4 +++-
 .../internal/binary/BinaryEnumsSelfTest.java      | 18 ++++++++++++++++++
 4 files changed, 35 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8070da31/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index b132db3..4616f11 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -923,7 +923,7 @@ public class BinaryContext {
      * @param typeId Type ID.
      * @return Instance of ID mapper.
      */
-    public BinaryInternalMapper userTypeMapper(int typeId) {
+    BinaryInternalMapper userTypeMapper(int typeId) {
         BinaryInternalMapper mapper = typeId2Mapper.get(typeId);
 
         return mapper != null ? mapper : SIMPLE_NAME_LOWER_CASE_MAPPER;
@@ -933,7 +933,7 @@ public class BinaryContext {
      * @param clsName Type name.
      * @return Instance of ID mapper.
      */
-    private BinaryInternalMapper userTypeMapper(String clsName) {
+    BinaryInternalMapper userTypeMapper(String clsName) {
         BinaryInternalMapper mapper = cls2Mappers.get(clsName);
 
         if (mapper != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/8070da31/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
index 17b0bc6..df9901e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 
 import java.util.Collection;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Binary type proxy. Is used to delay or completely avoid metadata lookup.
@@ -34,21 +35,26 @@ public class BinaryTypeProxy implements BinaryType {
     private final BinaryContext ctx;
 
     /** Type ID. */
-    private final int typeId;
+    private int typeId;
+
+    /** Raw data. */
+    private final String clsName;
 
     /** Target type. */
     @GridToStringExclude
     private volatile BinaryType target;
 
     /**
-     * Constrcutor.
+     * Constructor.
      *
      * @param ctx Context.
      * @param typeId Type ID.
+     * @param clsName Class name.
      */
-    public BinaryTypeProxy(BinaryContext ctx, int typeId) {
+    public BinaryTypeProxy(BinaryContext ctx, int typeId, @Nullable String clsName) {
         this.ctx = ctx;
         this.typeId = typeId;
+        this.clsName = clsName;
     }
 
     /** {@inheritDoc} */
@@ -93,6 +99,9 @@ public class BinaryTypeProxy implements BinaryType {
         if (target == null) {
             synchronized (this) {
                 if (target == null) {
+                    if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID && clsName != null)
+                        typeId = ctx.typeId(clsName);
+
                     target = ctx.metadata(typeId);
 
                     if (target == null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/8070da31/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 cb6e641..bc4260f 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
@@ -2222,7 +2222,9 @@ public class BinaryUtils {
         if (ctx == null)
             throw new BinaryObjectException("BinaryContext is not set for the object.");
 
-        return new BinaryTypeProxy(ctx, obj.typeId());
+        String clsName = obj instanceof BinaryEnumObjectImpl ? ((BinaryEnumObjectImpl)obj).className() : null;
+
+        return new BinaryTypeProxy(ctx, obj.typeId(), clsName);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/8070da31/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
index fb7e618..91add0d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
@@ -28,6 +28,7 @@ import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.marshaller.Marshaller;
@@ -389,6 +390,23 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Check ability to resolve typeId from class name.
+     *
+     * @throws Exception If failed.
+     */
+    public void testZeroTypeId() throws Exception {
+        startUp(true);
+
+        final BinaryContext ctx =
+            ((CacheObjectBinaryProcessorImpl)((IgniteEx)node1).context().cacheObjects()).binaryContext();
+
+        final BinaryObject enumObj =
+            new BinaryEnumObjectImpl(ctx, 0, EnumType.class.getName(), EnumType.ONE.ordinal());
+
+        assert enumObj.type().isEnum();
+    }
+
+    /**
      * Validate simple array.
      *
      * @param registered Registered flag.