This is an automated email from the ASF dual-hosted git repository. ilyak pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new 2acae6e IGNITE-11406 Fix NullPointerException on client start - Fixes #8604. 2acae6e is described below commit 2acae6e99c78d62b2cf006bde6b6d633278e5422 Author: pvinokurov <vinokurov.pa...@gmail.com> AuthorDate: Mon Dec 28 14:25:32 2020 +0300 IGNITE-11406 Fix NullPointerException on client start - Fixes #8604. Signed-off-by: Ilya Kasnacheev <ilya.kasnach...@gmail.com> --- .../processors/cache/GridCacheProcessor.java | 7 ++ .../cache/CacheReadBeforeActivationTest.java | 106 +++++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite9.java | 3 + 3 files changed, 116 insertions(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java index 7b3f9c1..ca5a5a2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java @@ -4416,6 +4416,13 @@ public class GridCacheProcessor extends GridProcessorAdapter { * @return Cache. */ private <K, V> IgniteInternalCache<K, V> internalCacheEx(String name) { + try { + awaitStarted(); + } + catch (IgniteCheckedException e) { + throw U.convertException(e); + } + if (ctx.discovery().localNode().isClient()) { IgniteCacheProxy<K, V> proxy = (IgniteCacheProxy<K, V>)jcacheProxy(name, true); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java new file mode 100644 index 0000000..0059940 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadBeforeActivationTest.java @@ -0,0 +1,106 @@ +/* + * 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; + +import java.io.Serializable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.Ignition; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteCallable; +import org.apache.ignite.plugin.AbstractTestPluginProvider; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** + * Tests that caches could not be accessed before activation. + */ +public class CacheReadBeforeActivationTest extends GridCommonAbstractTest { + /** Activation latch.*/ + private CountDownLatch latch; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + final IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setPluginProviders(new DelayedActivationPluginProvider()); + + return cfg; + } + + /** + * Tests that reading from the utility system cache waits until activation finished. + * Scenario: + * <ul> + * <li>Start a server node.</li> + * <li>Start a client node with the plugin provider delaying activation.</li> + * <li>Run a job on the client node that reads from the utility cache.</li> + * </ul> + * + * @throws Exception If failed. + */ + @Test + public void readUtilityCacheBeforeActivationFinished() throws Exception { + IgniteEx ignite = startGrid(0); + + latch = new CountDownLatch(1); + + multithreadedAsync(() -> startClientGrid(1), 1); + + latch.await(1, TimeUnit.MINUTES); + + // try to access the utility cache before activation finished and starting exchange on the client node. + ignite.compute(ignite.cluster().forClients()).call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return ((IgniteEx)Ignition.localIgnite()).context().cache().utilityCache().get("1"); + } + }); + } + + /** + * Plugin provider delaying activation. + */ + private class DelayedActivationPluginProvider extends AbstractTestPluginProvider implements IgniteChangeGlobalStateSupport { + /** {@inheritDoc} */ + @Override public String name() { + return "testPlugin"; + } + + /** {@inheritDoc} */ + @Override public void validateNewNode(ClusterNode node, Serializable data) { + } + + /** {@inheritDoc} */ + @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException { + if (latch != null) + latch.countDown(); + + U.sleep(2_000); + } + + /** {@inheritDoc} */ + @Override public void onDeActivate(GridKernalContext kctx) { + } + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java index 1923e5f..1cd4977 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite9.java @@ -33,6 +33,7 @@ import org.apache.ignite.internal.metric.ReadMetricsOnNodeStartupTest; import org.apache.ignite.internal.metric.SystemViewComputeJobTest; import org.apache.ignite.internal.metric.SystemViewSelfTest; import org.apache.ignite.internal.processors.cache.CachePutIfAbsentTest; +import org.apache.ignite.internal.processors.cache.CacheReadBeforeActivationTest; import org.apache.ignite.internal.processors.cache.GridCacheDataTypesCoverageTest; import org.apache.ignite.internal.processors.cache.GridCacheLongRunningTransactionDiagnosticsTest; import org.apache.ignite.internal.processors.cache.GridCacheVersionGenerationWithCacheStorageTest; @@ -143,6 +144,8 @@ public class IgniteCacheTestSuite9 { GridTestUtils.addTestIfNeeded(suite, RebalanceStatisticsTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, TxRecoveryOnCoordniatorFailTest.class, ignoredTests); + GridTestUtils.addTestIfNeeded(suite, CacheReadBeforeActivationTest.class, ignoredTests); + return suite; } }