You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ap...@apache.org on 2025/06/20 08:48:08 UTC
(ignite-3) branch main updated: IGNITE-25711 Fix compatibility test framework (#6075)
This is an automated email from the ASF dual-hosted git repository.
apkhmv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new bc79fcadee1 IGNITE-25711 Fix compatibility test framework (#6075)
bc79fcadee1 is described below
commit bc79fcadee19adc780a4d53fecedd688f88420ab
Author: Vadim Pakhnushev <86...@users.noreply.github.com>
AuthorDate: Fri Jun 20 11:48:02 2025 +0300
IGNITE-25711 Fix compatibility test framework (#6075)
---
.../ignite/internal/CompatibilityTestBase.java | 9 +--
.../org/apache/ignite/internal/IgniteCluster.java | 4 +-
.../org/apache/ignite/internal/IgniteVersions.java | 21 +++++-
.../org/apache/ignite/internal/RunnerNode.java | 35 +++++++++-
.../apache/ignite/internal/StreamGrabberTask.java | 59 +++++++++++++++++
.../ParameterizedClassNonStaticWorkDirTest.java | 77 ++++++++++++++++++++++
.../ParameterizedClassStaticWorkDirTest.java | 74 +++++++++++++++++++++
.../testframework/WorkDirectoryExtensionTest.java | 2 +
.../internal/testframework/WorkDirectory.java | 5 ++
.../testframework/WorkDirectoryExtension.java | 33 +++++++++-
10 files changed, 307 insertions(+), 12 deletions(-)
diff --git a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/CompatibilityTestBase.java b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/CompatibilityTestBase.java
index ae6ab49ac6e..055c38be4b3 100644
--- a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/CompatibilityTestBase.java
+++ b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/CompatibilityTestBase.java
@@ -71,17 +71,18 @@ public abstract class CompatibilityTestBase extends BaseIgniteAbstractTest {
// Lifecycle.PER_CLASS.
@SuppressWarnings("unused")
@Parameter
- String baseVersion;
+ private String baseVersion;
- @WorkDirectory
- private static Path WORK_DIR;
+ // Force per class template work directory so that non-static field doesn't get overwritten by the BeforeEach callback.
+ @WorkDirectory(forcePerClassTemplate = true)
+ private Path workDir;
protected IgniteCluster cluster;
@SuppressWarnings("unused")
@BeforeParameterizedClassInvocation
void startCluster(String baseVersion, TestInfo testInfo) {
- ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder(testInfo, WORK_DIR)
+ ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder(testInfo, workDir)
.defaultNodeBootstrapConfigTemplate(NODE_BOOTSTRAP_CFG_TEMPLATE)
.build();
diff --git a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteCluster.java b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteCluster.java
index d2faf591883..a935901fb85 100644
--- a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteCluster.java
+++ b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteCluster.java
@@ -111,6 +111,9 @@ public class IgniteCluster {
throw new IllegalStateException("The cluster is already started");
}
+ // Reset the flag before starting nodes.
+ stopped = false;
+
List<ServerRegistration> nodeRegistrations = new ArrayList<>();
for (int nodeIndex = 0; nodeIndex < nodesCount; nodeIndex++) {
nodeRegistrations.add(startEmbeddedNode(nodeIndex));
@@ -121,7 +124,6 @@ public class IgniteCluster {
}
started = true;
- stopped = false;
}
/**
diff --git a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteVersions.java b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteVersions.java
index 4f8064f0d8b..ba22291fd40 100644
--- a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteVersions.java
+++ b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/IgniteVersions.java
@@ -31,17 +31,30 @@ import org.apache.ignite.internal.logger.Loggers;
*/
@SuppressWarnings("unused")
public class IgniteVersions {
- public static IgniteVersions INSTANCE = readFromJson();
+ public static final IgniteVersions INSTANCE = readFromJson();
private List<String> artifacts;
+ private Map<String, String> configOverrides;
private List<Version> versions;
public IgniteVersions() {
}
+ /**
+ * Constructor.
+ *
+ * @param artifacts List of dependency notations.
+ * @param configOverrides Map of global node configuration overrides.
+ * @param versions List of version descriptors.
+ */
@JsonCreator
- public IgniteVersions(@JsonProperty("artifacts") List<String> artifacts, @JsonProperty("versions") List<Version> versions) {
+ public IgniteVersions(
+ @JsonProperty("artifacts") List<String> artifacts,
+ @JsonProperty("configOverrides") Map<String, String> configOverrides,
+ @JsonProperty("versions") List<Version> versions
+ ) {
this.artifacts = artifacts;
+ this.configOverrides = configOverrides;
this.versions = versions;
}
@@ -49,6 +62,10 @@ public class IgniteVersions {
return artifacts;
}
+ public Map<String, String> configOverrides() {
+ return configOverrides;
+ }
+
public List<Version> versions() {
return versions;
}
diff --git a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/RunnerNode.java b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/RunnerNode.java
index d10b9297822..606a6bef3a2 100644
--- a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/RunnerNode.java
+++ b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/RunnerNode.java
@@ -24,19 +24,24 @@ import static org.apache.ignite.internal.testframework.TestIgnitionManager.write
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.ignite.internal.IgniteVersions.Version;
import org.apache.ignite.internal.app.IgniteRunner;
import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
/**
* Represents the Ignite node running in the external process.
*/
public class RunnerNode {
+ private static final Map<String, String> DEFAULTS = IgniteVersions.INSTANCE.configOverrides();
private static final Map<String, Map<String, String>> DEFAULTS_PER_VERSION = getTestDefaultsPerVersion();
private final Process process;
@@ -74,15 +79,42 @@ public class RunnerNode {
boolean useTestDefaults = true;
if (useTestDefaults) {
- writeConfigurationFileApplyingTestDefaults(configStr, configPath, DEFAULTS_PER_VERSION.get(igniteVersion));
+ Map<String, String> defaultsPerVersion = DEFAULTS_PER_VERSION.get(igniteVersion);
+ writeConfigurationFileApplyingTestDefaults(
+ configStr,
+ configPath,
+ defaultsPerVersion != null ? defaultsPerVersion : DEFAULTS
+ );
} else {
writeConfigurationFile(configStr, configPath);
}
Process process = executeRunner(javaHome, argFile, configPath, workDir, nodeName);
+ IgniteLogger processLogger = Loggers.forName(nodeName);
+ createStreamGrabber(process, processLogger, process::getInputStream, "input");
+ createStreamGrabber(process, processLogger, process::getErrorStream, "error");
return new RunnerNode(process);
}
+ private static Thread createStreamGrabber(
+ Process process,
+ IgniteLogger processLogger,
+ Supplier<InputStream> streamSupplier,
+ String grabberType
+ ) {
+ Thread streamGrabber = new Thread(
+ new StreamGrabberTask(streamSupplier.get(), processLogger::info),
+ grabberThreadName(process.pid(), grabberType)
+ );
+ streamGrabber.setDaemon(true);
+ streamGrabber.start();
+ return streamGrabber;
+ }
+
+ private static String grabberThreadName(long pid, String grabberType) {
+ return "pid_" + pid + "_" + grabberType + "_grabber";
+ }
+
/**
* Stops the node by killing the process.
*/
@@ -133,7 +165,6 @@ public class RunnerNode {
"--work-dir", workDir.toString(),
"--config-path", configPath.toString()
);
- pb.inheritIO();
return pb.start();
}
}
diff --git a/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/StreamGrabberTask.java b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/StreamGrabberTask.java
new file mode 100644
index 00000000000..164f4fbbbd6
--- /dev/null
+++ b/modules/compatibility-tests/src/integrationTest/java/org/apache/ignite/internal/StreamGrabberTask.java
@@ -0,0 +1,59 @@
+/*
+ * 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.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+
+/**
+ * Task that reads provided input stream line by line and supplies these lines
+ * to specified consumer.
+ */
+class StreamGrabberTask implements Runnable {
+ private static final IgniteLogger LOG = Loggers.forClass(StreamGrabberTask.class);
+
+ private final InputStream streamToGrab;
+
+ private final Consumer<String> lineConsumer;
+
+ StreamGrabberTask(InputStream streamToGrab, Consumer<String> lineConsumer) {
+ this.streamToGrab = streamToGrab;
+ this.lineConsumer = lineConsumer;
+ }
+
+ @Override
+ public void run() {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(streamToGrab));
+
+ String line;
+
+ // noinspection NestedAssignment
+ while (!Thread.currentThread().isInterrupted() && (line = br.readLine()) != null) {
+ lineConsumer.accept(line);
+ }
+ } catch (IOException e) {
+ LOG.error("Caught IOException while grabbing stream", e);
+ }
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassNonStaticWorkDirTest.java b/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassNonStaticWorkDirTest.java
new file mode 100644
index 00000000000..f0430232f3e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassNonStaticWorkDirTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.nio.file.Path;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+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.BeforeParameterizedClassInvocation;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Tests work directory injection as a non-static field in a parameterized test class. In such a case forcing per class initialization is
+ * needed so that it doesn't initialized in the BeforeEachCallback.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+@ParameterizedClass
+@TestInstance(Lifecycle.PER_CLASS)
+@ValueSource(ints = {0, 1})
+class ParameterizedClassNonStaticWorkDirTest {
+ @WorkDirectory(forcePerClassTemplate = true)
+ private Path workDir;
+
+ private final Path[] savedWorkDirs = new Path[2];
+
+ @SuppressWarnings("unused")
+ @Parameter
+ private int index;
+
+ @BeforeAll
+ void beforeAll() {
+ assertThat(workDir, is(nullValue()));
+ }
+
+ @BeforeParameterizedClassInvocation
+ void beforeClassTemplate() {
+ assertThat(workDir, is(notNullValue()));
+ savedWorkDirs[index] = workDir;
+ }
+
+ @AfterAll
+ void afterAll() {
+ assertThat(savedWorkDirs[0], is(not(savedWorkDirs[1])));
+ }
+
+ @Test
+ void test() {
+ // Verify that the workDir was not overwritten by BeforeEachCallback
+ assertThat(workDir, is(savedWorkDirs[index]));
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassStaticWorkDirTest.java b/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassStaticWorkDirTest.java
new file mode 100644
index 00000000000..566fde04da9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/testframework/ParameterizedClassStaticWorkDirTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.nio.file.Path;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.BeforeParameterizedClassInvocation;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Tests work directory injection as a static field in a parameterized test class. In such a case forcing per class initialization is needed
+ * so that it doesn't initialized in the BeforeAllCallback.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+@ParameterizedClass
+@ValueSource(ints = {0, 1})
+class ParameterizedClassStaticWorkDirTest {
+ @WorkDirectory(forcePerClassTemplate = true)
+ private static Path workDir;
+
+ private static final Path[] savedWorkDirs = new Path[2];
+
+ @SuppressWarnings("unused")
+ @Parameter
+ private int index;
+
+ @BeforeAll
+ static void beforeAll() {
+ assertThat(workDir, is(nullValue()));
+ }
+
+ @BeforeParameterizedClassInvocation
+ static void beforeClassTemplate(int index) {
+ assertThat(workDir, is(notNullValue()));
+ savedWorkDirs[index] = workDir;
+ }
+
+ @AfterAll
+ static void afterAll() {
+ assertThat(savedWorkDirs[0], is(not(savedWorkDirs[1])));
+ }
+
+ @Test
+ void test() {
+ // Verify that the workDir was not overwritten by BeforeEachCallback
+ assertThat(workDir, is(savedWorkDirs[index]));
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/testframework/WorkDirectoryExtensionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/testframework/WorkDirectoryExtensionTest.java
index d41c80ac0cf..29d26d2e91f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/testframework/WorkDirectoryExtensionTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/testframework/WorkDirectoryExtensionTest.java
@@ -275,6 +275,7 @@ class WorkDirectoryExtensionTest {
assertTrue(Files.exists(file2));
IgniteUtils.deleteIfExists(file1.getParent());
+ IgniteUtils.deleteIfExists(file2.getParent());
}
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@@ -308,6 +309,7 @@ class WorkDirectoryExtensionTest {
assertTrue(Files.exists(file2));
IgniteUtils.deleteIfExists(file1.getParent());
+ IgniteUtils.deleteIfExists(file2.getParent());
}
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
diff --git a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectory.java b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectory.java
index d5d76877fa5..28926dc081b 100644
--- a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectory.java
+++ b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectory.java
@@ -33,4 +33,9 @@ import java.nio.file.Path;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface WorkDirectory {
+ /**
+ * If set to {@code true}, the annotated field will be initialized only in the BeforeParameterizedClassInvocation callback on each
+ * class template invocation.
+ */
+ boolean forcePerClassTemplate() default false;
}
diff --git a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectoryExtension.java b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectoryExtension.java
index c433b55c934..9072d948382 100644
--- a/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectoryExtension.java
+++ b/modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/WorkDirectoryExtension.java
@@ -42,8 +42,10 @@ import org.apache.ignite.internal.util.OperatingSystem;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.AfterClassTemplateInvocationCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeClassTemplateInvocationCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
@@ -73,7 +75,8 @@ import org.junit.platform.commons.support.HierarchyTraversalMode;
* for more information.
*/
public class WorkDirectoryExtension
- implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, ParameterResolver {
+ implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, BeforeClassTemplateInvocationCallback,
+ AfterClassTemplateInvocationCallback, ParameterResolver {
/** JUnit namespace for the extension. */
private static final Namespace NAMESPACE = Namespace.create(WorkDirectoryExtension.class);
@@ -109,7 +112,7 @@ public class WorkDirectoryExtension
public void beforeAll(ExtensionContext context) throws Exception {
Field workDirField = getWorkDirField(context);
- if (workDirField == null || !Modifier.isStatic(workDirField.getModifiers())) {
+ if (workDirField == null || !Modifier.isStatic(workDirField.getModifiers()) || isForcePerClassTemplate(workDirField)) {
return;
}
@@ -143,7 +146,7 @@ public class WorkDirectoryExtension
public void beforeEach(ExtensionContext context) throws Exception {
Field workDirField = getWorkDirField(context);
- if (workDirField == null || Modifier.isStatic(workDirField.getModifiers())) {
+ if (workDirField == null || Modifier.isStatic(workDirField.getModifiers()) || isForcePerClassTemplate(workDirField)) {
return;
}
@@ -158,6 +161,30 @@ public class WorkDirectoryExtension
cleanupWorkDir(context);
}
+ @Override
+ public void beforeClassTemplateInvocation(ExtensionContext context) throws Exception {
+ Field workDirField = getWorkDirField(context);
+
+ if (workDirField == null || !isForcePerClassTemplate(workDirField)) {
+ return;
+ }
+
+ workDirField.setAccessible(true);
+
+ workDirField.set(Modifier.isStatic(workDirField.getModifiers()) ? null : context.getRequiredTestInstance(), createWorkDir(context));
+ }
+
+ @Override
+ public void afterClassTemplateInvocation(ExtensionContext context) throws Exception {
+ cleanupWorkDir(context);
+ }
+
+ private static boolean isForcePerClassTemplate(Field field) {
+ WorkDirectory workDirectory = field.getAnnotation(WorkDirectory.class);
+ assert workDirectory != null;
+ return workDirectory.forcePerClassTemplate();
+ }
+
/** {@inheritDoc} */
@Override
public boolean supportsParameter(