This is an automated email from the ASF dual-hosted git repository. Caideyipi pushed a commit to branch fix-it-log-test-class-name in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit de9d9f67bf96e9e27ac4fb08807778d80f875c44 Author: Caideyipi <[email protected]> AuthorDate: Tue Jul 7 10:44:35 2026 +0800 Fix IT log directory test class names --- .../java/org/apache/iotdb/it/env/MultiEnvFactory.java | 8 +++++++- .../org/apache/iotdb/it/env/cluster/env/AbstractEnv.java | 15 +++++++++++++++ .../apache/iotdb/it/env/cluster/env/MultiClusterEnv.java | 9 +++++++++ .../main/java/org/apache/iotdb/itbase/env/BaseEnv.java | 4 ++++ .../org/apache/iotdb/it/framework/IoTDBTestRunner.java | 8 ++++++++ .../iotdb/it/framework/IoTDBTestRunnerWithParameters.java | 15 ++++++++++++++- 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/MultiEnvFactory.java b/integration-test/src/main/java/org/apache/iotdb/it/env/MultiEnvFactory.java index f2e5f9c1f90..d9fafd1353a 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/MultiEnvFactory.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/MultiEnvFactory.java @@ -33,11 +33,17 @@ public class MultiEnvFactory { private static final List<BaseEnv> envList = new ArrayList<>(); private static final Logger logger = IoTDBTestLogger.logger; private static String currentMethodName; + private static String currentClassName; private MultiEnvFactory() { // Empty constructor } + public static void setTestClassName(final String testClassName) { + currentClassName = testClassName; + envList.forEach(baseEnv -> baseEnv.setTestClassName(testClassName)); + } + public static void setTestMethodName(final String testMethodName) { currentMethodName = testMethodName; envList.forEach(baseEnv -> baseEnv.setTestMethodName(testMethodName)); @@ -56,7 +62,7 @@ public class MultiEnvFactory { for (int i = 0; i < num; ++i) { try { Class.forName(Config.JDBC_DRIVER_NAME); - envList.add(new MultiClusterEnv(startTime, i, currentMethodName)); + envList.add(new MultiClusterEnv(startTime, i, currentClassName, currentMethodName)); } catch (final ClassNotFoundException e) { logger.error("Create env error", e); System.exit(-1); diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java index e5d4e19834d..ae724c7081d 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java @@ -104,6 +104,7 @@ public abstract class AbstractEnv implements BaseEnv { protected List<ConfigNodeWrapper> configNodeWrapperList = Collections.emptyList(); protected List<DataNodeWrapper> dataNodeWrapperList = Collections.emptyList(); protected List<AbstractNodeWrapper> extraNodeWrappers = Collections.emptyList(); + protected String testClassName = null; protected String testMethodName = null; protected int index = 0; protected long startTime; @@ -332,6 +333,9 @@ public abstract class AbstractEnv implements BaseEnv { } public String getTestClassName() { + if (testClassName != null) { + return testClassName; + } final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (final StackTraceElement stackTraceElement : stack) { final String className = stackTraceElement.getClassName(); @@ -1228,6 +1232,17 @@ public abstract class AbstractEnv implements BaseEnv { return testMethodName; } + @Override + public void setTestClassName(final String testClassName) { + if (testClassName == null || testClassName.isEmpty()) { + this.testClassName = null; + return; + } + final int lastDotIndex = testClassName.lastIndexOf("."); + this.testClassName = + lastDotIndex >= 0 ? testClassName.substring(lastDotIndex + 1) : testClassName; + } + @Override public void setTestMethodName(final String testMethodName) { this.testMethodName = testMethodName; diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/MultiClusterEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/MultiClusterEnv.java index d462b5a668b..554fc768586 100644 --- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/MultiClusterEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/MultiClusterEnv.java @@ -26,8 +26,17 @@ import org.apache.tsfile.utils.Pair; public class MultiClusterEnv extends AbstractEnv { public MultiClusterEnv(final long startTime, final int index, final String currentMethodName) { + this(startTime, index, null, currentMethodName); + } + + public MultiClusterEnv( + final long startTime, + final int index, + final String currentClassName, + final String currentMethodName) { super(startTime); this.index = index; + setTestClassName(currentClassName); this.testMethodName = currentMethodName; } diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java index 0aed2cfdf19..fb2196943e4 100644 --- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java +++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java @@ -205,6 +205,10 @@ public interface BaseEnv { Connection getConnectionWithSpecifiedDataNode( DataNodeWrapper dataNode, String username, String password) throws SQLException; + default void setTestClassName(String testClassName) { + // Default no-op for env implementations that do not create local node log directories. + } + void setTestMethodName(String testCaseName); void dumpTestJVMSnapshot(); diff --git a/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunner.java b/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunner.java index 31981f87270..fb512603481 100644 --- a/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunner.java +++ b/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunner.java @@ -44,6 +44,11 @@ public class IoTDBTestRunner extends BlockJUnit4ClassRunner { @Override public void run(final RunNotifier notifier) { TimeZone.setDefault(TimeZone.getTimeZone("UTC+08:00")); + final String testClassName = getTestClass().getJavaClass().getSimpleName(); + if (EnvType.getSystemEnvType() != EnvType.MultiCluster) { + EnvFactory.getEnv().setTestClassName(testClassName); + } + MultiEnvFactory.setTestClassName(testClassName); listener = new IoTDBTestListener(this.getName()); notifier.addListener(listener); super.run(notifier); @@ -54,9 +59,12 @@ public class IoTDBTestRunner extends BlockJUnit4ClassRunner { final Description description = describeChild(method); logger.info("Run {}", description.getMethodName()); final long currentTime = System.currentTimeMillis(); + final String testClassName = getTestClass().getJavaClass().getSimpleName(); if (EnvType.getSystemEnvType() != EnvType.MultiCluster) { + EnvFactory.getEnv().setTestClassName(testClassName); EnvFactory.getEnv().setTestMethodName(description.getMethodName()); } + MultiEnvFactory.setTestClassName(testClassName); MultiEnvFactory.setTestMethodName(description.getMethodName()); if (Thread.currentThread().getName().equals("main")) { Thread.currentThread().setName("main-" + description.getMethodName()); diff --git a/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunnerWithParameters.java b/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunnerWithParameters.java index e11a930f5ad..312e29bea77 100644 --- a/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunnerWithParameters.java +++ b/integration-test/src/test/java/org/apache/iotdb/it/framework/IoTDBTestRunnerWithParameters.java @@ -20,6 +20,8 @@ package org.apache.iotdb.it.framework; import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.env.EnvType; +import org.apache.iotdb.it.env.MultiEnvFactory; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; @@ -40,6 +42,11 @@ public class IoTDBTestRunnerWithParameters extends BlockJUnit4ClassRunnerWithPar @Override public void run(RunNotifier notifier) { + final String testClassName = getTestClass().getJavaClass().getSimpleName(); + if (EnvType.getSystemEnvType() != EnvType.MultiCluster) { + EnvFactory.getEnv().setTestClassName(testClassName); + } + MultiEnvFactory.setTestClassName(testClassName); listener = new IoTDBTestListener(this.getName()); notifier.addListener(listener); super.run(notifier); @@ -50,7 +57,13 @@ public class IoTDBTestRunnerWithParameters extends BlockJUnit4ClassRunnerWithPar Description description = describeChild(method); logger.info("Run {}", description.getMethodName()); long currentTime = System.currentTimeMillis(); - EnvFactory.getEnv().setTestMethodName(description.getMethodName()); + final String testClassName = getTestClass().getJavaClass().getSimpleName(); + if (EnvType.getSystemEnvType() != EnvType.MultiCluster) { + EnvFactory.getEnv().setTestClassName(testClassName); + EnvFactory.getEnv().setTestMethodName(description.getMethodName()); + } + MultiEnvFactory.setTestClassName(testClassName); + MultiEnvFactory.setTestMethodName(description.getMethodName()); super.runChild(method, notifier); double timeCost = (System.currentTimeMillis() - currentTime) / 1000.0; String testName = description.getClassName() + "." + description.getMethodName();
