ptupitsyn commented on code in PR #5983: URL: https://github.com/apache/ignite-3/pull/5983#discussion_r2144984033
########## modules/compatibility-tests/src/test/java/org/apache/ignite/internal/PersistenceTestBase.java: ########## @@ -0,0 +1,142 @@ +/* + * 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 static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIMEM_PROFILE_NAME; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_ROCKSDB_PROFILE_NAME; + +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.ignite.Ignite; +import org.apache.ignite.InitParametersBuilder; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.internal.IgniteVersions.Version; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.apache.ignite.internal.testframework.WorkDirectory; +import org.apache.ignite.internal.testframework.WorkDirectoryExtension; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.AfterParameterizedClassInvocation; +import org.junit.jupiter.params.BeforeParameterizedClassInvocation; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Base class for testing cluster upgrades. Starts a cluster on an old version, initializes it, stops it, then starts it in the + * embedded mode using current version. + */ +@ExtendWith(WorkDirectoryExtension.class) +@TestInstance(Lifecycle.PER_CLASS) +@ParameterizedClass +@MethodSource("baseVersions") +public abstract class PersistenceTestBase extends BaseIgniteAbstractTest { + /** Nodes bootstrap configuration pattern. */ + private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "ignite {\n" + + " network: {\n" + + " port: {},\n" + + " nodeFinder.netClusterNodes: [ {} ]\n" + + " },\n" + + " storage.profiles: {" + + " " + DEFAULT_AIPERSIST_PROFILE_NAME + ".engine: aipersist, " + + " " + DEFAULT_AIMEM_PROFILE_NAME + ".engine: aimem, " + + " " + DEFAULT_ROCKSDB_PROFILE_NAME + ".engine: rocksdb" + + " },\n" + + " clientConnector.port: {},\n" + + " clientConnector.sendServerExceptionStackTraceToClient: true,\n" + + " rest.port: {},\n" + + " failureHandler.dumpThreadsOnFailure: false\n" + + "}"; + + // If there are no fields annotated with @Parameter, constructor injection will be used, which is incompatible with the + // Lifecycle.PER_CLASS. + @SuppressWarnings("unused") + @Parameter + String baseVersion; + + @WorkDirectory + private static Path WORK_DIR; + + protected IgniteCluster cluster; + + @SuppressWarnings("unused") + @BeforeParameterizedClassInvocation + void startCluster(String baseVersion, TestInfo testInfo) { + ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder(testInfo, WORK_DIR) + .defaultNodeBootstrapConfigTemplate(NODE_BOOTSTRAP_CFG_TEMPLATE) + .build(); + + int nodesCount = nodesCount(); + + cluster = new IgniteCluster(clusterConfiguration); + cluster.start(baseVersion, nodesCount); + + cluster.init(this::configureInitParameters); + + try (IgniteClient client = cluster.createClient()) { + setupBaseVersion(client); + } + + cluster.stop(); + + cluster.startEmbedded(nodesCount); + } + + @SuppressWarnings("unused") + @AfterParameterizedClassInvocation + void stopCluster() { + if (cluster != null) { + cluster.stop(); + } + } + + protected String getNodeBootstrapConfigTemplate() { + return NODE_BOOTSTRAP_CFG_TEMPLATE; + } + + protected int nodesCount() { + return 3; + } + + /** + * This method can be overridden to add custom init parameters during cluster initialization. + */ + protected void configureInitParameters(InitParametersBuilder builder) { + } + + protected abstract void setupBaseVersion(Ignite baseIgnite); + + protected List<List<Object>> sql(String query) { + return ClusterPerClassIntegrationTest.sql(cluster.node(0), null, null, null, query); + } + + private static List<String> baseVersions() { + List<String> versions = IgniteVersions.INSTANCE.versions().stream().map(Version::version).collect(Collectors.toList()); + if (System.getProperty("testAllVersions") != null) { + return versions; + } else { + // Take at most two latest versions by default. + int fromIndex = Math.max(versions.size() - 2, 0); Review Comment: Can we make this overridable, so a derived class can decide which versions to use? ########## modules/compatibility-tests/src/test/java/org/apache/ignite/internal/PersistenceTestBase.java: ########## @@ -0,0 +1,142 @@ +/* + * 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 static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIMEM_PROFILE_NAME; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_AIPERSIST_PROFILE_NAME; +import static org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_ROCKSDB_PROFILE_NAME; + +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.ignite.Ignite; +import org.apache.ignite.InitParametersBuilder; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.internal.IgniteVersions.Version; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.apache.ignite.internal.testframework.WorkDirectory; +import org.apache.ignite.internal.testframework.WorkDirectoryExtension; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.AfterParameterizedClassInvocation; +import org.junit.jupiter.params.BeforeParameterizedClassInvocation; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Base class for testing cluster upgrades. Starts a cluster on an old version, initializes it, stops it, then starts it in the + * embedded mode using current version. + */ +@ExtendWith(WorkDirectoryExtension.class) +@TestInstance(Lifecycle.PER_CLASS) +@ParameterizedClass +@MethodSource("baseVersions") +public abstract class PersistenceTestBase extends BaseIgniteAbstractTest { Review Comment: ```suggestion public abstract class CompatibilityTestBase extends BaseIgniteAbstractTest { ``` I think this is not specific to persistence and can be used for thin client compat tests too, for example. -- 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