ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-2947: improving support of OSGi like environments at the level of binary marshalling
Date Fri, 06 May 2016 20:56:14 GMT
Repository: ignite
Updated Branches:
  refs/heads/master e5aed699d -> 388ffefd8


IGNITE-2947: improving support of OSGi like environments at the level of binary marshalling


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

Branch: refs/heads/master
Commit: 388ffefd858040690e63a3825024f5aa5446189a
Parents: e5aed69
Author: Denis Magda <dmagda@gridgain.com>
Authored: Fri May 6 23:56:03 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Fri May 6 23:56:03 2016 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryClassDescriptor.java  |  43 ++-
 .../ignite/internal/binary/BinaryContext.java   |  90 +++---
 .../internal/binary/BinaryReaderExImpl.java     |  15 +-
 .../binary/GridBinaryWildcardsSelfTest.java     |  53 ++--
 ...acheBinaryObjectUserClassloaderSelfTest.java | 274 +++++++++++++++++++
 .../marshaller/MarshallerContextTestImpl.java   |   7 +
 .../testframework/junits/GridAbstractTest.java  |   3 +-
 .../IgniteBinaryObjectsTestSuite.java           |   3 +
 8 files changed, 421 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index d32b99a..d2d715b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -62,6 +62,9 @@ public class BinaryClassDescriptor {
     /** Configured serializer. */
     private final BinarySerializer serializer;
 
+    /** Serializer that is passed during BinaryClassDescriptor construction. Can differ from
{@link #serializer}. */
+    private final BinarySerializer initialSerializer;
+
     /** ID mapper. */
     private final BinaryInternalMapper mapper;
 
@@ -142,6 +145,8 @@ public class BinaryClassDescriptor {
         assert cls != null;
         assert mapper != null;
 
+        initialSerializer = serializer;
+
         // If serializer is not defined at this point, then we have to user OptimizedMarshaller.
         useOptMarshaller = serializer == null;
 
@@ -383,9 +388,45 @@ public class BinaryClassDescriptor {
     }
 
     /**
+     * @return Type name.
+     */
+    String typeName() {
+        return typeName;
+    }
+
+    /**
+     * @return Type mapper.
+     */
+    BinaryInternalMapper mapper() {
+        return mapper;
+    }
+
+    /**
+     * @return Serializer.
+     */
+    BinarySerializer serializer() {
+        return serializer;
+    }
+
+    /**
+     * @return Initial serializer that is passed during BinaryClassDescriptor construction.
+     * Can differ from {@link #serializer}.
+     */
+    BinarySerializer initialSerializer() {
+        return initialSerializer;
+    }
+
+    /**
+     * @return Affinity field key name.
+     */
+    String affFieldKeyName() {
+        return affKeyFieldName;
+    }
+
+    /**
      * @return User type flag.
      */
-    public boolean userType() {
+    boolean userType() {
         return userType;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/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 8754795..daf34ad 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
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.binary;
 
-import java.io.Externalizable;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Field;
@@ -99,8 +98,8 @@ import org.jsr166.ConcurrentHashMap8;
  * Binary context.
  */
 public class BinaryContext {
-    /** */
-    private static final ClassLoader dfltLdr = U.gridClassLoader();
+    /** System loader.*/
+    private static final ClassLoader sysLdr = U.gridClassLoader();
 
     /** */
     private static final BinaryInternalMapper DFLT_MAPPER =
@@ -154,9 +153,6 @@ public class BinaryContext {
     /** */
     private final ConcurrentMap<Class<?>, BinaryClassDescriptor> descByCls =
new ConcurrentHashMap8<>();
 
-    /** Holds classes loaded by default class loader only. */
-    private final ConcurrentMap<Integer, BinaryClassDescriptor> userTypes = new ConcurrentHashMap8<>();
-
     /** */
     private final Map<Integer, BinaryClassDescriptor> predefinedTypes = new HashMap<>();
 
@@ -203,13 +199,6 @@ public class BinaryContext {
     private volatile Map<Integer, BinarySchemaRegistry> schemas;
 
     /**
-     * For {@link Externalizable}.
-     */
-    public BinaryContext() {
-        // No-op.
-    }
-
-    /**
      * @param metaHnd Meta data handler.
      * @param igniteCfg Ignite configuration.
      * @param log Logger.
@@ -570,8 +559,13 @@ public class BinaryContext {
 
         BinaryClassDescriptor desc = descByCls.get(cls);
 
-        if (desc == null || !desc.registered())
+        if (desc == null)
             desc = registerClassDescriptor(cls, deserialize);
+        else if (!desc.registered()) {
+            assert desc.userType();
+
+            desc = registerUserClassDescriptor(desc);
+        }
 
         return desc;
     }
@@ -597,16 +591,7 @@ public class BinaryContext {
             return desc;
 
         if (ldr == null)
-            ldr = dfltLdr;
-
-        // If the type hasn't been loaded by default class loader then we mustn't return
the descriptor from here
-        // giving a chance to a custom class loader to reload type's class.
-        if (userType && ldr.equals(dfltLdr)) {
-            desc = userTypes.get(typeId);
-
-            if (desc != null)
-                return desc;
-        }
+            ldr = sysLdr;
 
         Class cls;
 
@@ -617,14 +602,14 @@ public class BinaryContext {
         }
         catch (ClassNotFoundException e) {
             // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true,
typeId, dfltLdr, deserialize)) != null)
+            if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true,
typeId, sysLdr, deserialize)) != null)
                 return desc;
 
             throw new BinaryInvalidTypeException(e);
         }
         catch (IgniteCheckedException e) {
             // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true,
typeId, dfltLdr, deserialize)) != null)
+            if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true,
typeId, sysLdr, deserialize)) != null)
                 return desc;
 
             throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
@@ -727,11 +712,6 @@ public class BinaryContext {
                 new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas,
desc.isEnum()).wrap(this));
         }
 
-        // perform put() instead of putIfAbsent() because "registered" flag might have been
changed or class loader
-        // might have reloaded described class.
-        if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-            userTypes.put(typeId, desc);
-
         descByCls.put(cls, desc);
 
         typeId2Mapper.putIfAbsent(typeId, mapper);
@@ -740,6 +720,47 @@ public class BinaryContext {
     }
 
     /**
+     * Creates and registers {@link BinaryClassDescriptor} for the given user {@code class}.
+     *
+     * @param desc Old descriptor that should be re-registered.
+     * @return Class descriptor.
+     */
+    private BinaryClassDescriptor registerUserClassDescriptor(BinaryClassDescriptor desc)
{
+        boolean registered;
+
+        try {
+            registered = marshCtx.registerClass(desc.typeId(), desc.describedClass());
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to register class.", e);
+        }
+
+        if (registered) {
+            BinarySerializer serializer = desc.initialSerializer();
+
+            if (serializer == null)
+                serializer = serializerForClass(desc.describedClass());
+
+            desc = new BinaryClassDescriptor(
+                this,
+                desc.describedClass(),
+                true,
+                desc.typeId(),
+                desc.typeName(),
+                desc.affFieldKeyName(),
+                desc.mapper(),
+                serializer,
+                true,
+                true
+            );
+
+            descByCls.put(desc.describedClass(), desc);
+        }
+
+        return desc;
+    }
+
+    /**
      * Get serializer for class taking in count default one.
      *
      * @param cls Class.
@@ -996,7 +1017,7 @@ public class BinaryContext {
         Class<?> cls = null;
 
         try {
-            cls = Class.forName(clsName);
+            cls = U.resolveClassLoader(configuration()).loadClass(clsName);
         }
         catch (ClassNotFoundException | NoClassDefFoundError ignored) {
             // No-op.
@@ -1042,15 +1063,12 @@ public class BinaryContext {
                 mapper,
                 serializer,
                 true,
-                true /* registered */
+                false
             );
 
             fieldsMeta = desc.fieldsMeta();
             schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
 
-            if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-                userTypes.put(id, desc);
-
             descByCls.put(cls, desc);
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
index 69aecbf..194b1be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -114,6 +114,9 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
     /** Footer end. */
     private final int footerLen;
 
+    /** Class descriptor. */
+    private BinaryClassDescriptor desc;
+
     /** Mapper. */
     private final BinaryInternalMapper mapper;
 
@@ -254,7 +257,9 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
 
                 if (forUnmarshal) {
                     // Registers class by type ID, at least locally if the cache is not ready
yet.
-                    typeId = ctx.descriptorForClass(BinaryUtils.doReadClass(in, ctx, ldr,
typeId0), false).typeId();
+                    desc = ctx.descriptorForClass(BinaryUtils.doReadClass(in, ctx, ldr, typeId0),
false);
+
+                    typeId = desc.typeId();
                 }
                 else
                     typeId = ctx.typeId(BinaryUtils.doReadClassName(in));
@@ -300,7 +305,10 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
      * @return Descriptor.
      */
     BinaryClassDescriptor descriptor() {
-        return ctx.descriptorForTypeId(userType, typeId, ldr, true);
+        if (desc == null)
+            desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
+
+        return desc;
     }
 
     /**
@@ -1462,7 +1470,8 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
                 break;
 
             case OBJ:
-                BinaryClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId, ldr,
true);
+                if (desc == null)
+                    desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
 
                 streamPosition(dataStart);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
index d0d63b3..f69cea4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.binary;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryBasicIdMapper;
 import org.apache.ignite.binary.BinaryIdMapper;
@@ -84,13 +85,13 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
-        assertTrue(typeIds.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, mapper)));
-        assertTrue(typeIds.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
+        assertTrue(types.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, mapper)));
+        assertTrue(types.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
     }
 
     /**
@@ -157,13 +158,13 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
-        assertTrue(typeIds.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
-        assertTrue(typeIds.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, idMapper)));
     }
 
     /**
@@ -346,13 +347,13 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
-        assertTrue(typeIds.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
-        assertTrue(typeIds.containsKey("type2".hashCode()));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, mapper)));
+        assertTrue(types.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, mapper)));
+        assertTrue(types.containsKey("type2".hashCode()));
 
         Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers
= U.field(ctx, "cls2Mappers");
 
@@ -387,12 +388,12 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
-        assertTrue(typeIds.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
     }
 
     /**
@@ -460,12 +461,12 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
-        assertTrue(typeIds.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper)));
     }
 
     /**
@@ -580,11 +581,11 @@ public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest
{
 
         BinaryContext ctx = binaryContext(marsh);
 
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+        ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper");
 
-        assertEquals(3, typeIds.size());
+        assertEquals(3, types.size());
 
-        assertTrue(typeIds.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
+        assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper)));
 
         Map<String, org.apache.ignite.internal.binary.BinaryInternalMapper> typeMappers
= U.field(ctx, "cls2Mappers");
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectUserClassloaderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectUserClassloaderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectUserClassloaderSelfTest.java
new file mode 100644
index 0000000..4355796
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectUserClassloaderSelfTest.java
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.binary;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.util.typedef.internal.S;
+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.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectUserClassloaderSelfTest extends GridCommonAbstractTest
{
+    /** */
+    private static volatile boolean customBinaryConf = false;
+
+    /** */
+    private static volatile boolean deserialized = false;
+
+    /** */
+    private static volatile boolean useWrappingLoader = false;
+
+    /** */
+    private TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(disco);
+
+        cfg.setCacheConfiguration(cacheConfiguration(gridName));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        cfg.setClassLoader(useWrappingLoader ? new WrappingClassLoader(getExternalClassLoader())
:
+            getExternalClassLoader());
+
+        if (customBinaryConf) {
+            BinarySerializer bs = new BinarySerializer() {
+                /** {@inheritDoc} */
+                @Override public void writeBinary(Object obj, BinaryWriter writer) throws
BinaryObjectException {
+                    //No-op.
+                }
+
+                /** {@inheritDoc} */
+                @Override public void readBinary(Object obj, BinaryReader reader) throws
BinaryObjectException {
+                    deserialized = true;
+                }
+            };
+
+            BinaryTypeConfiguration btcfg1 = new BinaryTypeConfiguration();
+
+            btcfg1.setTypeName("org.apache.ignite.tests.p2p.CacheDeploymentTestValue");
+
+            btcfg1.setSerializer(bs);
+
+            BinaryTypeConfiguration btcfg2 = new BinaryTypeConfiguration();
+
+            btcfg2.setTypeName("org.apache.ignite.internal.processors.cache.binary." +
+                "GridCacheBinaryObjectUserClassloaderSelfTest$TestValue1");
+
+            btcfg2.setSerializer(bs);
+
+            BinaryConfiguration bcfg = new BinaryConfiguration();
+
+            Set<BinaryTypeConfiguration> set = new HashSet<>();
+
+            set.add(btcfg1);
+            set.add(btcfg2);
+
+            bcfg.setTypeConfigurations(set);
+
+            cfg.setBinaryConfiguration(bcfg);
+        }
+
+        return cfg;
+    }
+
+    /**
+     * Gets cache configuration for grid with specified name.
+     *
+     * @param gridName Grid name.
+     * @return Cache configuration.
+     */
+    CacheConfiguration cacheConfiguration(String gridName) {
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setCacheMode(REPLICATED);
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        return cacheCfg;
+    }
+
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testConfigurationRegistration() throws Exception {
+        useWrappingLoader = false;
+
+        doTestConfigurationRegistration();
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testConfigurationRegistrationWithWrappingLoader() throws Exception {
+        useWrappingLoader = true;
+
+        doTestConfigurationRegistration();
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    private void doTestConfigurationRegistration() throws Exception {
+        try {
+            customBinaryConf = true;
+
+            Ignite i1 = startGrid(1);
+            Ignite i2 = startGrid(2);
+
+            IgniteCache<Integer, Object> cache1 = i1.cache(null);
+            IgniteCache<Integer, Object> cache2 = i2.cache(null);
+
+            ClassLoader ldr = useWrappingLoader ?
+                ((WrappingClassLoader)i1.configuration().getClassLoader()).getParent() :
+                i1.configuration().getClassLoader();
+
+            Object v1 = ldr.loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestValue").newInstance();
+            Object v2 = ldr.loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestValue2").newInstance();
+
+            cache1.put(1, v1);
+            cache1.put(2, v2);
+            cache1.put(3, new TestValue1(123));
+            cache1.put(4, new TestValue2(123));
+
+            deserialized = false;
+
+            cache2.get(1);
+
+            assertTrue(deserialized);
+
+            deserialized = false;
+
+            cache2.get(2);
+
+            assertFalse(deserialized);
+
+            deserialized = false;
+
+            cache2.get(3);
+
+            assertTrue(deserialized);
+
+            deserialized = false;
+
+            cache2.get(4);
+
+            assertFalse(deserialized);
+        }
+        finally {
+            customBinaryConf = false;
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestValue1 implements Serializable {
+        /** */
+        private int val;
+
+        /**
+         * @param val Value.
+         */
+        public TestValue1(int val) {
+            this.val = val;
+        }
+
+        /**
+         * @return Value.
+         */
+        public int value() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(TestValue1.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestValue2 implements Serializable {
+        /** */
+        private int val;
+
+        /**
+         * @param val Value.
+         */
+        public TestValue2(int val) {
+            this.val = val;
+        }
+
+        /**
+         * @return Value.
+         */
+        public int value() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(TestValue2.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class WrappingClassLoader extends ClassLoader {
+        public WrappingClassLoader(ClassLoader parent) {
+            super(parent);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
index e4921f4..c600ca4 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
@@ -62,4 +62,11 @@ public class MarshallerContextTestImpl extends MarshallerContextAdapter
{
     @Override protected String className(int id) {
         return map.get(id);
     }
+
+    /**
+     * @return Internal map.
+     */
+    public ConcurrentMap<Integer, String> internalMap() {
+        return map;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 170e9cf..3910ce4 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -484,7 +484,8 @@ public abstract class GridAbstractTest extends TestCase {
      * @throws Exception If failed. {@link #afterTestsStopped()} will be called in this case.
      */
     protected void beforeTestsStarted() throws Exception {
-        // No-op.
+        // Will clean and re-create marshaller directory from scratch.
+        U.resolveWorkDirectory("marshaller", true);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/388ffefd/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
index 73c22e4..cedf9a7 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompac
 import org.apache.ignite.internal.binary.streams.BinaryHeapStreamByteOrderSelfTest;
 import org.apache.ignite.internal.binary.streams.BinaryOffheapStreamByteOrderSelfTest;
 import org.apache.ignite.internal.processors.cache.BinaryObjectOffHeapUnswapTemporaryTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectUserClassloaderSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreBinariesDefaultMappersSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreBinariesSimpleNameMappersSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreObjectsSelfTest;
@@ -140,6 +141,8 @@ public class IgniteBinaryObjectsTestSuite extends TestSuite {
         suite.addTestSuite(BinaryHeapStreamByteOrderSelfTest.class);
         suite.addTestSuite(BinaryOffheapStreamByteOrderSelfTest.class);
 
+        suite.addTestSuite(GridCacheBinaryObjectUserClassloaderSelfTest.class);
+
         return suite;
     }
 }


Mime
View raw message