rpuch commented on code in PR #1709: URL: https://github.com/apache/ignite-3/pull/1709#discussion_r1121476809
########## modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/junit/StopAllIgnitesAfterTests.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.testframework.junit; + +import java.lang.reflect.Method; +import java.util.ServiceLoader; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * This extension tries to do it best to stop all Ignite instances that were started in this JVM after a test + * suite finishes running (after-all). + * + * <p>This extension is designed to be + * <a href="https://junit.org/junit5/docs/current/user-guide/#extensions-registration-automatic">automatically registered</a> + * via META-INF/services/org.junit.jupiter.api.extension.Extension. + * For this to work, system property {@code junit.jupiter.extensions.autodetection.enabled} must be set to {@code true}. + * If the property is set (currently, this is done via Gradle build scripts), it is enough to add this module as a dependency + * to make tests automatically register this extension, like this: + * + * <pre> + * integrationTestImplementation(testFixtures(project(':ignite-core'))) + * </pre> + */ +public class StopAllIgnitesAfterTests implements AfterAllCallback { + private static final String IGNITION_MANAGER_CLASS_NAME = "org.apache.ignite.IgnitionManager"; + + private static final String IGNITION_CLASS_NAME = "org.apache.ignite.Ignition"; + + private static final String IGNITION_IMPL_CLASS_NAME = "org.apache.ignite.internal.app.IgnitionImpl"; + + private static final IgniteLogger LOG = Loggers.forClass(StopAllIgnitesAfterTests.class); + + @Override + public void afterAll(ExtensionContext context) throws Exception { + // Try to stop all Ignite nodes via reflection to make sure that this extension does not break anything Review Comment: For now, we only need it for `runner`, but we might have other modules that will start `Ignite`s in their tests in the future. The idea was to build the extension once and just use it when needed, so I didn't want to implement it in the `runner` module. But `core` does not seem right either. How about creating a special module for just this extension? We could use it from `runner` tests now; if other modules like `runner` are added, we can just reference the module in their `build` scripts. Extension ordering (between the auto-registered extensions) seemed to be important when the work was started, but now I think it's not true. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
