Repository: ignite Updated Branches: refs/heads/master ea05dc509 -> f427b9d86
IGNITE-4939 Receive event before cache initialized. - Fixes #4226. Signed-off-by: Dmitriy Pavlov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f427b9d8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f427b9d8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f427b9d8 Branch: refs/heads/master Commit: f427b9d86777800e9c701ebef28714e805e032a3 Parents: ea05dc5 Author: ezhuravl <[email protected]> Authored: Fri Jun 22 20:38:45 2018 +0300 Committer: Dmitriy Pavlov <[email protected]> Committed: Fri Jun 22 20:38:45 2018 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheProcessor.java | 7 + .../service/SystemCacheNotConfiguredTest.java | 172 +++++++++++++++++++ .../testsuites/IgniteKernalSelfTestSuite.java | 2 + 3 files changed, 181 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f427b9d8/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java ---------------------------------------------------------------------- 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 ae79ef0..ad986f6 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 @@ -3996,6 +3996,13 @@ public class GridCacheProcessor extends GridProcessorAdapter { IgniteCacheProxy<K, V> cache = (IgniteCacheProxy<K, V>) jCacheProxies.get(name); + if (cache == null) { + GridCacheAdapter<?, ?> cacheAdapter = caches.get(name); + + if (cacheAdapter != null) + cache = new IgniteCacheProxyImpl(cacheAdapter.context(), cacheAdapter, false); + } + if (cache == null) throw new IllegalArgumentException("Cache is not configured: " + name); http://git-wip-us.apache.org/repos/asf/ignite/blob/f427b9d8/modules/core/src/test/java/org/apache/ignite/internal/processors/service/SystemCacheNotConfiguredTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/SystemCacheNotConfiguredTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/SystemCacheNotConfiguredTest.java new file mode 100644 index 0000000..a76eb22 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/SystemCacheNotConfiguredTest.java @@ -0,0 +1,172 @@ +/* + * 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.service; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteServices; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.services.Service; +import org.apache.ignite.services.ServiceConfiguration; +import org.apache.ignite.services.ServiceContext; +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; + +/** + * Tests if system cache was started before deploying of service. + */ +public class SystemCacheNotConfiguredTest extends GridCommonAbstractTest { + /** */ + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + /** */ + private TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private final PrintStream originalErr = System.err; + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return 60 * 1000; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi(); + + discoverySpi.setIpFinder(ipFinder); + cfg.setDiscoverySpi(discoverySpi); + + if("server".equals(igniteInstanceName)) + cfg.setServiceConfiguration(serviceConfiguration()); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void test() throws Exception { + captureErr(); + + new Thread(this::startServer).start(); + + Ignite client = startGrid(getConfiguration("client").setClientMode(true)); + + IgniteServices services = client.services(); + + SimpleService srvc = services.serviceProxy("service", SimpleService.class, false); + + Thread.sleep(1000); + + srvc.isWorking(); + + assertFalse(getErr().contains("Cache is not configured:")); + } + + /** + * Start server node. + */ + private void startServer() { + try { + startGrid(getConfiguration("server")); + } + catch (Exception e) { + fail(); + } + } + + /** + * @return Service configuration. + */ + private ServiceConfiguration serviceConfiguration() { + ServiceConfiguration svcCfg = new ServiceConfiguration(); + + svcCfg.setName("service"); + svcCfg.setTotalCount(1); + svcCfg.setService(new SimpleServiceImpl()); + + return svcCfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + System.setErr(originalErr); + } + + /** + * Turns on stdErr output capture. + */ + private void captureErr() { + System.setErr(new PrintStream(errContent)); + } + + /** + * Turns off stdErr capture and returns the contents that have been captured. + * + * @return String of captured stdErr. + */ + private String getErr() { + return errContent.toString().replaceAll("\r", ""); + } + + /** + * Simple service implementation for test. + */ + public static class SimpleServiceImpl implements Service, SimpleService { + /** {@inheritDoc} */ + SimpleServiceImpl() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void cancel(ServiceContext ctx) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void init(ServiceContext ctx) throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void execute(ServiceContext ctx) throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void isWorking() { + // No-op. + } + } + + /** + * Simple service interface for test. + */ + public interface SimpleService { + /** */ + void isWorking(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f427b9d8/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java index 2a66833..f2fbe04 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteKernalSelfTestSuite.java @@ -72,6 +72,7 @@ import org.apache.ignite.internal.processors.service.IgniteServiceReassignmentTe import org.apache.ignite.internal.processors.service.ServiceDeploymentOnActivationTest; import org.apache.ignite.internal.processors.service.ServiceDeploymentOutsideBaselineTest; import org.apache.ignite.internal.processors.service.ServicePredicateAccessCacheTest; +import org.apache.ignite.internal.processors.service.SystemCacheNotConfiguredTest; import org.apache.ignite.internal.util.GridStartupWithUndefinedIgniteHomeSelfTest; import org.apache.ignite.services.ServiceThreadPoolSelfTest; import org.apache.ignite.spi.communication.GridCacheMessageSelfTest; @@ -152,6 +153,7 @@ public class IgniteKernalSelfTestSuite extends TestSuite { suite.addTestSuite(GridServiceDeploymentCompoundFutureSelfTest.class); suite.addTestSuite(ServiceDeploymentOnActivationTest.class); suite.addTestSuite(ServiceDeploymentOutsideBaselineTest.class); + suite.addTestSuite(SystemCacheNotConfiguredTest.class); suite.addTestSuite(IgniteServiceDeploymentClassLoadingDefaultMarshallerTest.class); suite.addTestSuite(IgniteServiceDeploymentClassLoadingJdkMarshallerTest.class);
