Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription: skip on setup and cluster failure when running subscription restart IT & fix some bugs in SubscriptionExecutorServiceManager #12710

Merged
merged 16 commits into from
Jun 12, 2024
Prev Previous commit
add checker for before annotation
VGalaxies committed Jun 12, 2024
commit 2df42406e8b5390896e26ef01489234c788be52f
Original file line number Diff line number Diff line change
@@ -25,19 +25,17 @@
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.lang.reflect.Method;

public class SkipOnSetUpFailure implements TestRule {

private final String setUpMethodName;
private final String declaringClassName;

/**
* @param setUpMethodName Should be exactly the same as the method name decorated with @Before.
* @param declaringClassName The name of the test class.
*/
public SkipOnSetUpFailure(
@NonNull final String setUpMethodName, @NonNull final String declaringClassName) {
public SkipOnSetUpFailure(@NonNull final String setUpMethodName) {
this.setUpMethodName = setUpMethodName;
this.declaringClassName = declaringClassName;
}

@Override
@@ -52,7 +50,8 @@ public void evaluate() throws Throwable {
// setUp phase.
for (final StackTraceElement stackTraceElement : e.getStackTrace()) {
if (setUpMethodName.equals(stackTraceElement.getMethodName())
&& declaringClassName.equals(stackTraceElement.getClassName())) {
&& description.getClassName().equals(stackTraceElement.getClassName())
&& isMethodAnnotationWithBefore(stackTraceElement.getMethodName())) {
e.printStackTrace();
// Skip this test.
throw new AssumptionViolatedException(
@@ -69,6 +68,15 @@ public void evaluate() throws Throwable {
// executed.
}
}

private boolean isMethodAnnotationWithBefore(final String methodName) {
try {
final Method method = description.getTestClass().getDeclaredMethod(methodName);
return method.isAnnotationPresent(org.junit.Before.class);
} catch (final Throwable ignored) {
return false;
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -66,9 +66,7 @@ public class IoTDBSubscriptionRestartIT {

private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBSubscriptionRestartIT.class);

@Rule
public final TestRule skipOnSetUpFailure =
new SkipOnSetUpFailure("setUp", IoTDBSubscriptionRestartIT.class.getName());
@Rule public final TestRule skipOnSetUpFailure = new SkipOnSetUpFailure("setUp");

@Before
public void setUp() throws Exception {