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 6b4ed99 IGNITE-14490 Test for scenario where cache.invoke() triggers failure handler - Fixes #8976. 6b4ed99 is described below commit 6b4ed99d99cfda870cddb9c22ccbd4aa73fbad65 Author: Ilya Kasnacheev <ilya.kasnach...@gmail.com> AuthorDate: Thu May 13 12:56:39 2021 +0300 IGNITE-14490 Test for scenario where cache.invoke() triggers failure handler - Fixes #8976. --- .../tests/p2p/compute/ExternalEntryProcessor.java | 44 ++++++++ .../UriDeploymentAbsentProcessorClassTest.java | 117 +++++++++++++++++++++ .../testsuites/IgniteUriDeploymentTestSuite.java | 4 +- 3 files changed, 164 insertions(+), 1 deletion(-) diff --git a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/compute/ExternalEntryProcessor.java b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/compute/ExternalEntryProcessor.java new file mode 100644 index 0000000..e5cdb27 --- /dev/null +++ b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/compute/ExternalEntryProcessor.java @@ -0,0 +1,44 @@ +/* + * 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.tests.p2p.compute; + +import javax.cache.processor.EntryProcessor; +import javax.cache.processor.EntryProcessorException; +import javax.cache.processor.MutableEntry; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.resources.LoggerResource; + +/** */ +public class ExternalEntryProcessor implements EntryProcessor<Object, Object, Object> { + /** */ + @IgniteInstanceResource + Ignite ignite; + + /** Logger. */ + @LoggerResource + private IgniteLogger log; + + /** */ + @Override public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException { + log.info("!!!!! I am entry processor " + entry.getKey() + " on " + ignite.name()); + + return 42; + } +} diff --git a/modules/urideploy/src/test/java/org/apache/ignite/internal/UriDeploymentAbsentProcessorClassTest.java b/modules/urideploy/src/test/java/org/apache/ignite/internal/UriDeploymentAbsentProcessorClassTest.java new file mode 100644 index 0000000..a63946a --- /dev/null +++ b/modules/urideploy/src/test/java/org/apache/ignite/internal/UriDeploymentAbsentProcessorClassTest.java @@ -0,0 +1,117 @@ +/* + * 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; + +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import javax.cache.processor.EntryProcessor; +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.DeploymentMode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerInaccessibleClassException; +import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.spi.deployment.uri.UriDeploymentSpi; +import org.apache.ignite.testframework.GridTestExternalClassLoader; +import org.apache.ignite.testframework.config.GridTestProperties; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** */ +public class UriDeploymentAbsentProcessorClassTest extends GridCommonAbstractTest { + /** */ + private static final String RUN_CLS = "org.apache.ignite.tests.p2p.compute.ExternalEntryProcessor"; + + /** */ + private Path file; + + /** */ + private Object retVal; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + UriDeploymentSpi spi = new UriDeploymentSpi(); + + file = Files.createTempDirectory(getClass().getName()); + + spi.setUriList(Collections.singletonList(file.toUri().toString())); + + return super.getConfiguration(igniteInstanceName) + .setPeerClassLoadingEnabled(false) + .setDeploymentSpi(spi) + .setDeploymentMode(DeploymentMode.SHARED); + } + + /** + * Starts server node with URI deployment of empty directory. + * Starts client node. + * In a separate thread, load entry processor from p2p class loader. + * Try to invoke it on server node, catch expected exception. + * Check that server node is operational after. + * + * @throws Exception if failed. + */ + @Test + public void test() throws Exception { + try { + startGrid(1); + + final Ignite ignite2 = startClientGrid(2); + + Thread thread = new Thread(() -> { + try { + ClassLoader cl = new GridTestExternalClassLoader(new URL[] { + new URL(GridTestProperties.getProperty("p2p.uri.cls")) }); + + Thread.currentThread().setContextClassLoader(cl); + + Class cls = cl.loadClass(RUN_CLS); + + EntryProcessor proc = (EntryProcessor)cls.newInstance(); + + retVal = ignite2.getOrCreateCache(DEFAULT_CACHE_NAME).invoke(0, proc); + } + catch (Exception ex) { + if (X.hasCause(ex, "Failed to find class with given class loader for unmarshalling", + OptimizedMarshallerInaccessibleClassException.class)) { + ignite2.log().warning("Caught expected exception", ex); + + retVal = 0; + } + else + throw new RuntimeException(ex); + } + }); + + thread.start(); + + thread.join(); + + assertEquals(0, retVal); + + assertEquals(0, grid(1).cache(DEFAULT_CACHE_NAME).size()); + } + finally { + stopAllGrids(); + + if (file != null) + file.toFile().delete(); + } + } +} diff --git a/modules/urideploy/src/test/java/org/apache/ignite/testsuites/IgniteUriDeploymentTestSuite.java b/modules/urideploy/src/test/java/org/apache/ignite/testsuites/IgniteUriDeploymentTestSuite.java index 3f4216a..7f975ce 100644 --- a/modules/urideploy/src/test/java/org/apache/ignite/testsuites/IgniteUriDeploymentTestSuite.java +++ b/modules/urideploy/src/test/java/org/apache/ignite/testsuites/IgniteUriDeploymentTestSuite.java @@ -18,6 +18,7 @@ package org.apache.ignite.testsuites; import org.apache.ignite.internal.GridTaskUriDeploymentDeadlockSelfTest; +import org.apache.ignite.internal.UriDeploymentAbsentProcessorClassTest; import org.apache.ignite.p2p.ClassLoadingProblemExceptionTest; import org.apache.ignite.p2p.GridP2PDisabledSelfTest; import org.apache.ignite.spi.deployment.uri.GridUriDeploymentClassLoaderMultiThreadedSelfTest; @@ -61,7 +62,8 @@ import org.junit.runners.Suite; GridTaskUriDeploymentDeadlockSelfTest.class, GridP2PDisabledSelfTest.class, - ClassLoadingProblemExceptionTest.class + ClassLoadingProblemExceptionTest.class, + UriDeploymentAbsentProcessorClassTest.class }) public class IgniteUriDeploymentTestSuite { }