Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -56,7 +62,7 @@ public static void createEnv(final int num) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -332,6 +333,9 @@ private DataNodeWrapper newDataNode() {
}

public String getTestClassName() {
if (testClassName != null) {
return testClassName;
}
final StackTraceElement[] stack = Thread.currentThread().getStackTrace();
for (final StackTraceElement stackTraceElement : stack) {
final String className = stackTraceElement.getClassName();
Expand Down Expand Up @@ -1228,6 +1232,17 @@ public String getTestMethodName() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ default Connection getConnectionWithSpecifiedDataNode(DataNodeWrapper dataNode)
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public IoTDBTestRunner(final Class<?> testClass) throws InitializationError {
@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);
Expand All @@ -54,9 +59,12 @@ protected void runChild(final FrameworkMethod method, final RunNotifier notifier
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +42,11 @@ public IoTDBTestRunnerWithParameters(TestWithParameters test) throws Initializat

@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);
Expand All @@ -50,7 +57,13 @@ protected synchronized void runChild(final FrameworkMethod method, RunNotifier n
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();
Expand Down
Loading