ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [13/55] [abbrv] ignite git commit: ignite-1353: predefined ID is now properly determined during serialization/deserialization
Date Fri, 04 Sep 2015 16:27:27 GMT
ignite-1353: predefined ID is now properly determined during serialization/deserialization


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

Branch: refs/heads/ignite-1093-2
Commit: 4d3c1f07b850a6519908c6d4383ec81310bbab40
Parents: 58a665a
Author: Denis Magda <dmagda@gridgain.com>
Authored: Fri Sep 4 13:34:58 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Fri Sep 4 13:34:58 2015 +0300

----------------------------------------------------------------------
 .../portable/PortableClassDescriptor.java       |  79 ++++++++-----
 .../internal/portable/PortableContext.java      | 113 +++++++++----------
 .../internal/portable/PortableWriterExImpl.java |  92 ++++-----------
 .../GridPortableMarshallerSelfTest.java         |  68 +++++++----
 .../portable/GridPortableWildcardsSelfTest.java |  60 +++++-----
 5 files changed, 208 insertions(+), 204 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4d3c1f07/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index 24ad5ce..a2b4b74 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -19,10 +19,13 @@ package org.apache.ignite.internal.portable;
 
 import java.io.Externalizable;
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -36,6 +39,8 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
 import org.apache.ignite.portable.PortableException;
 import org.apache.ignite.portable.PortableIdMapper;
 import org.apache.ignite.portable.PortableMarshalAware;
@@ -95,36 +100,10 @@ public class PortableClassDescriptor {
     private final boolean registered;
 
     /** */
-    private final boolean excluded;
+    private final boolean useOptMarshaller;
 
-    /**
-     * @param ctx Context.
-     * @param cls Class.
-     * @param userType User type flag.
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param idMapper ID mapper.
-     * @param serializer Serializer.
-     * @param useTs Use timestamp flag.
-     * @param metaDataEnabled Metadata enabled flag.
-     * @param keepDeserialized Keep deserialized flag.
-     * @throws PortableException In case of error.
-     */
-    PortableClassDescriptor(
-        PortableContext ctx,
-        Class<?> cls,
-        boolean userType,
-        int typeId,
-        String typeName,
-        @Nullable PortableIdMapper idMapper,
-        @Nullable PortableSerializer serializer,
-        boolean useTs,
-        boolean metaDataEnabled,
-        boolean keepDeserialized
-    ) throws PortableException {
-        this(ctx, cls, userType, typeId, typeName, idMapper, serializer, useTs, metaDataEnabled,
keepDeserialized,
-            true);
-    }
+    /** */
+    private final boolean excluded;
 
     /**
      * @param ctx Context.
@@ -138,6 +117,7 @@ public class PortableClassDescriptor {
      * @param metaDataEnabled Metadata enabled flag.
      * @param keepDeserialized Keep deserialized flag.
      * @param registered Whether typeId has been successfully registered by MarshallerContext
or not.
+     * @param predefined Whether the class is predefined or not.
      * @throws PortableException In case of error.
      */
     PortableClassDescriptor(
@@ -151,7 +131,8 @@ public class PortableClassDescriptor {
         boolean useTs,
         boolean metaDataEnabled,
         boolean keepDeserialized,
-        boolean registered
+        boolean registered,
+        boolean predefined
     ) throws PortableException {
         assert ctx != null;
         assert cls != null;
@@ -168,6 +149,8 @@ public class PortableClassDescriptor {
 
         excluded = MarshallerExclusions.isExcluded(cls);
 
+        useOptMarshaller = !predefined && initUseOptimizedMarshallerFlag();
+
         if (excluded)
             mode = Mode.EXCLUSION;
         else
@@ -313,11 +296,19 @@ public class PortableClassDescriptor {
     /**
      * @return Whether typeId has been successfully registered by MarshallerContext or not.
      */
-    public boolean isRegistered() {
+    public boolean registered() {
         return registered;
     }
 
     /**
+     * @return {@code true} if {@link OptimizedMarshaller} must be used instead of {@link
PortableMarshaller}
+     * for object serialization and deserialization.
+     */
+    public boolean useOptimizedMarshaller() {
+        return useOptMarshaller;
+    }
+
+    /**
      * Checks whether the class values are explicitly excluded from marshalling.
      *
      * @return {@code true} if excluded, {@code false} otherwise.
@@ -720,6 +711,32 @@ public class PortableClassDescriptor {
     }
 
     /**
+     * Determines whether to use {@link OptimizedMarshaller} for serialization or
+     * not.
+     *
+     * @return {@code true} if to use, {@code false} otherwise.
+     */
+    private boolean initUseOptimizedMarshallerFlag() {
+       boolean use;
+
+        try {
+            Method writeObj = cls.getDeclaredMethod("writeObject", ObjectOutputStream.class);
+            Method readObj = cls.getDeclaredMethod("readObject", ObjectInputStream.class);
+
+            if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers())
&&
+                writeObj.getReturnType() == void.class && readObj.getReturnType()
== void.class)
+                use = true;
+            else
+                use = false;
+        }
+        catch (NoSuchMethodException e) {
+            use = false;
+        }
+
+        return use;
+    }
+
+    /**
      * @param cls Class.
      * @return Mode.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d3c1f07/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index db7e41e..33a105b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -112,7 +112,7 @@ public class PortableContext implements Externalizable {
     private final Map<Integer, PortableClassDescriptor> predefinedTypes = new HashMap<>();
 
     /** */
-    private final Set<Class> predefinedClasses = new HashSet<>();
+    private final Map<String, Integer> predefinedTypeNames = new HashMap<>();
 
     /** */
     private final Map<Class<? extends Collection>, Byte> colTypes = new HashMap<>();
@@ -432,7 +432,7 @@ public class PortableContext implements Externalizable {
 
         PortableClassDescriptor desc = descByCls.get(cls);
 
-        if (desc == null || !desc.isRegistered())
+        if (desc == null || !desc.registered())
             desc = registerClassDescriptor(cls);
 
         return desc;
@@ -447,11 +447,22 @@ public class PortableContext implements Externalizable {
     public PortableClassDescriptor descriptorForTypeId(boolean userType, int typeId, ClassLoader
ldr) {
         assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID;
 
-        PortableClassDescriptor desc = userType ? userTypes.get(typeId) : predefinedTypes.get(typeId);
+        //TODO: IGNITE-1358 (uncomment when fixed)
+        //PortableClassDescriptor desc = userType ? userTypes.get(typeId) : predefinedTypes.get(typeId);
+
+        // As a workaround for IGNITE-1358 we always check the predefined map before.
+        PortableClassDescriptor desc = predefinedTypes.get(typeId);
 
         if (desc != null)
             return desc;
 
+        if (userType) {
+            desc = userTypes.get(typeId);
+
+            if (desc != null)
+                return desc;
+        }
+
         Class cls;
 
         try {
@@ -496,7 +507,10 @@ public class PortableContext implements Externalizable {
                 null,
                 useTs,
                 metaDataEnabled,
-                keepDeserialized);
+                keepDeserialized,
+                true, /* registered */
+                false /* predefined */
+            );
 
             PortableClassDescriptor old = descByCls.putIfAbsent(cls, desc);
 
@@ -529,7 +543,8 @@ public class PortableContext implements Externalizable {
         try {
             registered = marshCtx.registerClass(typeId, cls);
 
-        } catch (IgniteCheckedException e) {
+        }
+        catch (IgniteCheckedException e) {
             throw new PortableException("Failed to register class.", e);
         }
 
@@ -543,7 +558,9 @@ public class PortableContext implements Externalizable {
             useTs,
             metaDataEnabled,
             keepDeserialized,
-            registered);
+            registered,
+            false /* predefined */
+        );
 
         // perform put() instead of putIfAbsent() because "registered" flag may have been
changed.
         userTypes.put(typeId, desc);
@@ -584,43 +601,17 @@ public class PortableContext implements Externalizable {
      * @return Type ID.
      */
     public int typeId(String typeName) {
-        int id;
-
-        if (marshCtx.isSystemType(typeName))
-            id = typeName.hashCode();
-
-        else {
-            typeName = typeName(typeName);
-
-            id = idMapper(typeName).typeId(typeName);
-        }
-
-        return id;
-    }
-
-    /**
-     * @param cls Class.
-     * @return Type ID.
-     * @throws PortableException In case of error.
-     */
-    public Type typeId(Class cls) throws PortableException {
-        String clsName = cls.getName();
-
-        if (marshCtx.isSystemType(clsName))
-            return new Type(clsName.hashCode(), true);
-
-        if (predefinedClasses.contains(cls))
-            return new Type(DFLT_ID_MAPPER.typeId(typeName(clsName)), true);
+        String shortTypeName = typeName(typeName);
 
-        PortableClassDescriptor desc = descByCls.get(cls);
+        Integer id = predefinedTypeNames.get(shortTypeName);
 
-        boolean registered = desc != null && desc.isRegistered();
+        if (id != null)
+            return id;
 
-        if (!registered)
-            // forces to register the class and fill up all required data structures
-            desc = registerUserClassDescriptor(cls);
+        if (marshCtx.isSystemType(typeName))
+            return typeName.hashCode();
 
-        return new Type(desc.typeId(), desc.isRegistered());
+        return idMapper(shortTypeName).typeId(shortTypeName);
     }
 
     /**
@@ -692,22 +683,26 @@ public class PortableContext implements Externalizable {
      * @return GridPortableClassDescriptor.
      */
     public PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
+        String typeName = typeName(cls.getName());
+
         PortableClassDescriptor desc = new PortableClassDescriptor(
             this,
             cls,
             false,
             id,
-            typeName(cls.getName()),
+            typeName,
             DFLT_ID_MAPPER,
             null,
             false,
             false,
-            false
+            false,
+            true, /* registered */
+            true /* predefined */
         );
 
-        predefinedClasses.add(cls);
-
+        predefinedTypeNames.put(typeName, id);
         predefinedTypes.put(id, desc);
+
         descByCls.put(cls, desc);
 
         return desc;
@@ -745,6 +740,10 @@ public class PortableContext implements Externalizable {
 
         int id = idMapper.typeId(clsName);
 
+        //Workaround for IGNITE-1358
+        if (predefinedTypes.get(id) != null)
+            throw new PortableException("Duplicate type ID [clsName=" + clsName + ", id="
+ id + ']');
+
         if (mappers.put(id, idMapper) != null)
             throw new PortableException("Duplicate type ID [clsName=" + clsName + ", id="
+ id + ']');
 
@@ -770,7 +769,10 @@ public class PortableContext implements Externalizable {
                 serializer,
                 useTs,
                 metaDataEnabled,
-                keepDeserialized);
+                keepDeserialized,
+                true, /* registered */
+                false /* predefined */
+            );
 
             fieldsMeta = desc.fieldsMeta();
 
@@ -863,16 +865,6 @@ public class PortableContext implements Externalizable {
     }
 
     /**
-     * Returns whether {@code cls} is predefined in the context or not.
-     *
-     * @param cls Class.
-     * @return {@code true} if predefined, {@code false} otherwise.
-     */
-    public boolean isPredefinedClass(Class<?> cls) {
-        return predefinedClasses.contains(cls);
-    }
-
-    /**
      * Returns instance of {@link OptimizedMarshaller}.
      *
      * @return Optimized marshaller.
@@ -977,6 +969,7 @@ public class PortableContext implements Externalizable {
             return lowerCaseHashCode(fieldName);
         }
     }
+
     /**
      * Type descriptors.
      */
@@ -1113,21 +1106,27 @@ public class PortableContext implements Externalizable {
      * Type id wrapper.
      */
     static class Type {
-        /** Type id*/
-        private int id;
+        /** Type id */
+        private final int id;
 
         /** Whether the following type is registered in a cache or not */
-        private boolean registered;
+        private final boolean registered;
 
         public Type(int id, boolean registered) {
             this.id = id;
             this.registered = registered;
         }
 
+        /**
+         * @return Type ID.
+         */
         public int id() {
             return id;
         }
 
+        /**
+         * @return Registered flag value.
+         */
         public boolean registered() {
             return registered;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d3c1f07/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index 364d5f8..3152c4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -93,9 +93,6 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
     private static final int INIT_CAP = 1024;
 
     /** */
-    private static final ConcurrentHashMap<Class<?>, Boolean> useOptMarshCache
= new ConcurrentHashMap<>();
-
-    /** */
     private final PortableContext ctx;
 
     /** */
@@ -197,7 +194,19 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
     void marshal(Object obj, boolean detached) throws PortableException {
         assert obj != null;
 
-        if (useOptimizedMarshaller(obj)) {
+        cls = obj.getClass();
+
+        PortableClassDescriptor desc = ctx.descriptorForClass(cls);
+
+        if (desc == null)
+            throw new PortableException("Object is not portable: [class=" + cls + ']');
+
+        if (desc.excluded()) {
+            doWriteByte(NULL);
+            return;
+        }
+
+        if (desc.useOptimizedMarshaller()) {
             writeByte(OPTM_MARSH);
 
             try {
@@ -214,18 +223,6 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
             return;
         }
 
-        cls = obj.getClass();
-
-        PortableClassDescriptor desc = ctx.descriptorForClass(cls);
-
-        if (desc == null)
-            throw new PortableException("Object is not portable: [class=" + cls + ']');
-
-        if (desc.excluded()) {
-            doWriteByte(NULL);
-            return;
-        }
-
         if (desc.getWriteReplaceMethod() != null) {
             Object replace;
 
@@ -269,44 +266,6 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
         desc.write(obj, this);
     }
 
-     /**
-      * Determines whether to use {@link org.apache.ignite.marshaller.optimized.OptimizedMarshaller}
for serialization
-      * or not.
-      *
-      * @param obj Object to serialize.
-      * @return {@code true} if to use, {@code false} otherwise.
-      */
-     private boolean useOptimizedMarshaller(Object obj) {
-         Class<?> cls = obj.getClass();
-
-         Boolean use = useOptMarshCache.get(cls);
-
-         if (use != null)
-             return use;
-
-         if (ctx.isPredefinedClass(cls))
-             use = false;
-         else {
-             try {
-                 Method writeObj = cls.getDeclaredMethod("writeObject", ObjectOutputStream.class);
-                 Method readObj = cls.getDeclaredMethod("readObject", ObjectInputStream.class);
-
-                 if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers())
&&
-                     writeObj.getReturnType() == void.class && readObj.getReturnType()
== void.class)
-                     use = true;
-                 else
-                     use = false;
-
-             } catch (NoSuchMethodException e) {
-                 use = false;
-             }
-         }
-
-         useOptMarshCache.putIfAbsent(cls, use);
-
-         return use;
-     }
-
     /**
      * @param obj Object.
      * @return Handle.
@@ -803,12 +762,12 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
             if (tryWriteAsHandle(val))
                 return;
 
-            PortableContext.Type type = ctx.typeId(val.getClass().getComponentType());
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
 
             doWriteByte(OBJ_ARR);
 
-            if (type.registered())
-                doWriteInt(type.id());
+            if (desc.registered())
+                doWriteInt(desc.typeId());
             else {
                 doWriteInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getComponentType().getName());
@@ -887,12 +846,12 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
         if (val == null)
             doWriteByte(NULL);
         else {
-            PortableContext.Type type = ctx.typeId(val.getClass());
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass());
 
             doWriteByte(ENUM);
 
-            if (type.registered())
-                doWriteInt(type.id());
+            if (desc.registered())
+                doWriteInt(desc.typeId());
             else {
                 doWriteInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getName());
@@ -911,12 +870,11 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
         if (val == null)
             doWriteByte(NULL);
         else {
-            PortableContext.Type type = ctx.typeId(val.getClass().getComponentType());
-
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
             doWriteByte(ENUM_ARR);
 
-            if (type.registered())
-                doWriteInt(type.id());
+            if (desc.registered())
+                doWriteInt(desc.typeId());
             else {
                 doWriteInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getComponentType().getName());
@@ -937,12 +895,12 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
         if (val == null)
             doWriteByte(NULL);
         else {
-            PortableContext.Type type = ctx.typeId(val);
+            PortableClassDescriptor desc = ctx.descriptorForClass(val);
 
             doWriteByte(CLASS);
 
-            if (type.registered())
-                doWriteInt(type.id());
+            if (desc.registered())
+                doWriteInt(desc.typeId());
             else {
                 doWriteInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getName());

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d3c1f07/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
index c8287a0..4545a58 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.portable;
 
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
@@ -33,6 +34,7 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
@@ -69,7 +71,6 @@ import sun.misc.Unsafe;
 
 import static org.apache.ignite.internal.portable.PortableThreadLocalMemoryAllocator.THREAD_LOCAL_ALLOC;
 import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
 
 /**
  * Portable marshaller tests.
@@ -1185,7 +1186,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
 
         customType1.setIdMapper(new PortableIdMapper() {
             @Override public int typeId(String clsName) {
-                return 100;
+                return 300;
             }
 
             @Override public int fieldId(int typeId, String fieldName) {
@@ -1197,7 +1198,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
 
         customType2.setIdMapper(new PortableIdMapper() {
             @Override public int typeId(String clsName) {
-                return 200;
+                return 400;
             }
 
             @Override public int fieldId(int typeId, String fieldName) {
@@ -1209,7 +1210,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
 
         customType3.setIdMapper(new PortableIdMapper() {
             @Override public int typeId(String clsName) {
-                return 300;
+                return 500;
             }
 
             @Override public int fieldId(int typeId, String fieldName) {
@@ -1245,9 +1246,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
         assertEquals("key".hashCode(), ctx.typeId("Key"));
         assertEquals("nonexistentclass3".hashCode(), ctx.typeId("NonExistentClass3"));
         assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
-        assertEquals(100, ctx.typeId(getClass().getSimpleName() + "$Value"));
-        assertEquals(200, ctx.typeId("NonExistentClass1"));
-        assertEquals(300, ctx.typeId("NonExistentClass2"));
+        assertEquals(300, ctx.typeId(getClass().getSimpleName() + "$Value"));
+        assertEquals(400, ctx.typeId("NonExistentClass1"));
+        assertEquals(500, ctx.typeId("NonExistentClass2"));
         assertEquals("nonexistentclass5".hashCode(), ctx.typeId("NonExistentClass5"));
     }
 
@@ -1261,16 +1262,16 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
 
         customType1.setIdMapper(new PortableIdMapper() {
             @Override public int typeId(String clsName) {
-                return 100;
+                return 300;
             }
 
             @Override public int fieldId(int typeId, String fieldName) {
                 switch (fieldName) {
                     case "val1":
-                        return 101;
+                        return 301;
 
                     case "val2":
-                        return 102;
+                        return 302;
 
                     default:
                         return 0;
@@ -1282,16 +1283,16 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
 
         customType2.setIdMapper(new PortableIdMapper() {
             @Override public int typeId(String clsName) {
-                return 200;
+                return 400;
             }
 
             @Override public int fieldId(int typeId, String fieldName) {
                 switch (fieldName) {
                     case "val1":
-                        return 201;
+                        return 401;
 
                     case "val2":
-                        return 202;
+                        return 402;
 
                     default:
                         return 0;
@@ -1309,12 +1310,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
         assertEquals("val".hashCode(), ctx.fieldId("key".hashCode(), "val"));
         assertEquals("val".hashCode(), ctx.fieldId("nonexistentclass2".hashCode(), "val"));
         assertEquals("val".hashCode(), ctx.fieldId("notconfiguredclass".hashCode(), "val"));
-        assertEquals(101, ctx.fieldId(100, "val1"));
-        assertEquals(102, ctx.fieldId(100, "val2"));
-        assertEquals("val3".hashCode(), ctx.fieldId(100, "val3"));
-        assertEquals(201, ctx.fieldId(200, "val1"));
-        assertEquals(202, ctx.fieldId(200, "val2"));
-        assertEquals("val3".hashCode(), ctx.fieldId(200, "val3"));
+        assertEquals(301, ctx.fieldId(300, "val1"));
+        assertEquals(302, ctx.fieldId(300, "val2"));
+        assertEquals("val3".hashCode(), ctx.fieldId(300, "val3"));
+        assertEquals(401, ctx.fieldId(400, "val1"));
+        assertEquals(402, ctx.fieldId(400, "val2"));
+        assertEquals("val3".hashCode(), ctx.fieldId(400, "val3"));
     }
 
     /**
@@ -2243,6 +2244,35 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest
{
     /**
      * @throws Exception If failed.
      */
+    public void testPredefinedTypeIds() throws Exception {
+        PortableMarshaller marsh = new PortableMarshaller();
+
+        PortableContext pCtx = initPortableContext(marsh);
+
+        Field field = pCtx.getClass().getDeclaredField("predefinedTypeNames");
+
+        field.setAccessible(true);
+
+        Map<String, Integer> map = (Map<String, Integer>)field.get(pCtx);
+
+        assertTrue(map.size() > 0);
+
+        for (Map.Entry<String, Integer> entry : map.entrySet()) {
+            int id = entry.getValue();
+
+            if (id == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+                continue;
+
+            PortableClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(),
null);
+
+            assertEquals(desc.typeId(), pCtx.typeId(desc.describedClass().getName()));
+            assertEquals(desc.typeId(), pCtx.typeId(pCtx.typeName(desc.describedClass().getName())));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testCyclicReferencesMarshalling() throws Exception {
         PortableMarshaller marsh = new PortableMarshaller();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d3c1f07/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
index 95dfbe8..349f152 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
@@ -95,11 +95,11 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else if (clsName.endsWith("InnerClass"))
-                    return 300;
+                    return 500;
                 else
                     return -500;
             }
@@ -120,9 +120,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(300, typeMappers.get("InnerClass").typeId("InnerClass"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
     }
 
     /**
@@ -161,11 +161,11 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else if (clsName.endsWith("InnerClass"))
-                    return 300;
+                    return 500;
                 else
                     return -500;
             }
@@ -186,9 +186,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(300, typeMappers.get("InnerClass").typeId("InnerClass"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
     }
 
     /**
@@ -203,11 +203,11 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else if (clsName.endsWith("InnerClass"))
-                    return 300;
+                    return 500;
                 else
                     return -500;
             }
@@ -228,9 +228,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(300, typeMappers.get("InnerClass").typeId("InnerClass"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
     }
 
     /**
@@ -310,9 +310,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else
                     return -500;
             }
@@ -333,8 +333,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
     }
 
     /**
@@ -372,9 +372,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else
                     return -500;
             }
@@ -395,8 +395,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
     }
 
     /**
@@ -411,9 +411,9 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
             @SuppressWarnings("IfMayBeConditional")
             @Override public int typeId(String clsName) {
                 if (clsName.endsWith("1"))
-                    return 100;
+                    return 300;
                 else if (clsName.endsWith("2"))
-                    return 200;
+                    return 400;
                 else
                     return -500;
             }
@@ -434,8 +434,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest
{
 
         assertEquals(3, typeMappers.size());
 
-        assertEquals(100, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(200, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
     }
 
     /**


Mime
View raw message