nizhikov commented on code in PR #11634: URL: https://github.com/apache/ignite/pull/11634#discussion_r1836693322
########## modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceDeploymentFailureTest.java: ########## @@ -0,0 +1,210 @@ +/* + * 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.util.Arrays; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.ignite.Ignition; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.failure.StopNodeFailureHandler; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.services.Service; +import org.apache.ignite.services.ServiceConfiguration; +import org.apache.ignite.services.ServiceDeploymentException; +import org.apache.ignite.services.ServiceDescriptor; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; + +/** + * Test class for verifying the behavior of Ignite service deployment when + * specified service classes are not found or when service initialization fails. + */ +public class IgniteServiceDeploymentFailureTest extends GridCommonAbstractTest { + /** */ + private static final String NOOP_SERVICE_CLS_NAME = "org.apache.ignite.tests.p2p.NoopService"; + + /** */ + public static final String NODE_FILTER_CLS_NAME = "org.apache.ignite.tests.p2p.ExcludeNodeFilter"; + + /** */ + private static final int SERVER_NODES_CNT = 5; + + /** */ + private static final int CLIENT_NODES_CNT = 4; + + /** */ + private static final int TIMEOUT = 10_000; + + /** */ + private static ClassLoader extClsLdr; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setPeerClassLoadingEnabled(false); + cfg.setFailureHandler(new StopNodeFailureHandler()); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + extClsLdr = getExternalClassLoader(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + + extClsLdr = null; + } + + /** + * Tests that deploying a service with a missing class causes a ServiceDeploymentException. + * + * @throws Exception If failed. + */ + @Test + public void testFailWhenClassNotFound() throws Exception { + IgniteEx srv = startGrid(getConfiguration("server")); + IgniteEx cli = startClientGrid(1); + + ServiceConfiguration svcCfg = new ServiceConfiguration() + .setName("TestDeploymentService") + .setService(((Class<Service>) extClsLdr.loadClass(NOOP_SERVICE_CLS_NAME)).getDeclaredConstructor().newInstance()) + .setNodeFilter(((Class<IgnitePredicate<ClusterNode>>) extClsLdr.loadClass(NODE_FILTER_CLS_NAME)) + .getConstructor(UUID.class) + .newInstance(cli.configuration().getNodeId())) + .setTotalCount(1); + + assertThrowsWithCause(() -> cli.services().deploy(svcCfg), ServiceDeploymentException.class); + + assertTrue(cli.services().serviceDescriptors().isEmpty()); Review Comment: Let's add the same check as we use in test below - `waitForCondition` all node doesn't have failed service in descriptors. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org