IGNITE-2947 BinaryContext doesn't honor custom loader set through IgniteConfiguration.classLoader
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7f94b2fc Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7f94b2fc Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7f94b2fc Branch: refs/heads/ignite-1786 Commit: 7f94b2fc31e797e7a55ee7ebb45ccd7ed80f2d5d Parents: fcfbf2c Author: Anton Vinogradov <[email protected]> Authored: Wed Apr 6 11:35:36 2016 +0300 Committer: Anton Vinogradov <[email protected]> Committed: Wed Apr 6 11:40:14 2016 +0300 ---------------------------------------------------------------------- .../ignite/internal/binary/BinaryContext.java | 2 +- ...acheBinaryObjectUserClassloaderSelfTest.java | 147 +++++++++++++++++++ .../IgniteBinaryObjectsTestSuite.java | 5 +- 3 files changed, 152 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/7f94b2fc/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 4d8c293..9a9ef10 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 @@ -992,7 +992,7 @@ public class BinaryContext { Class<?> cls = null; try { - cls = Class.forName(clsName); + cls = U.resolveClassLoader(configuration()).loadClass(clsName); } catch (ClassNotFoundException | NoClassDefFoundError ignored) { // No-op. http://git-wip-us.apache.org/repos/asf/ignite/blob/7f94b2fc/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..ca09e4c --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectUserClassloaderSelfTest.java @@ -0,0 +1,147 @@ +/* + * 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.util.Collections; +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.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 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(getExternalClassLoader()); + + if (customBinaryConf) { + BinaryTypeConfiguration btcfg = new BinaryTypeConfiguration(); + + btcfg.setTypeName("org.apache.ignite.tests.p2p.CacheDeploymentTestValue3"); + + btcfg.setSerializer(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; + } + }); + + BinaryConfiguration bcfg = new BinaryConfiguration(); + + bcfg.setTypeConfigurations(Collections.singletonList(btcfg)); + + 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 { + 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 = i1.configuration().getClassLoader(); + + Object v1 = ldr.loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestValue3").newInstance(); + + cache1.put(1, v1); + + deserialized = false; + + cache2.get(1); + + assertTrue(deserialized); + } + finally { + customBinaryConf = false; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/7f94b2fc/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 3ec55d0..043ea06 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 @@ -44,6 +44,7 @@ import org.apache.ignite.internal.binary.noncompact.BinaryMarshallerNonCompactSe import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderAdditionalNonCompactSelfTest; import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactDefaultMappersSelfTest; import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactSimpleNameLowerCaseMappersSelfTest; +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.binary.streams.BinaryHeapStreamByteOrderSelfTest; @@ -79,7 +80,7 @@ public class IgniteBinaryObjectsTestSuite extends TestSuite { TestSuite suite = new TestSuite("Ignite Binary Objects Test Suite"); suite.addTestSuite(BinarySimpleNameTestPropertySelfTest.class); - + suite.addTestSuite(BinaryBasicIdMapperSelfTest.class); suite.addTestSuite(BinaryBasicNameMapperSelfTest.class); @@ -138,6 +139,8 @@ public class IgniteBinaryObjectsTestSuite extends TestSuite { suite.addTestSuite(BinaryHeapStreamByteOrderSelfTest.class); suite.addTestSuite(BinaryOffheapStreamByteOrderSelfTest.class); + suite.addTestSuite(GridCacheBinaryObjectUserClassloaderSelfTest.class); + return suite; } }
