This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 921d9e24804 Subscription IT: intro retry rule for flaky tests (#15698)
921d9e24804 is described below
commit 921d9e2480401be2a136d385b890cf919d58c973
Author: VGalaxies <[email protected]>
AuthorDate: Mon Jun 16 15:03:33 2025 +0800
Subscription IT: intro retry rule for flaky tests (#15698)
---
.../org/apache/iotdb/subscription/it/Retry.java | 33 +++++++++++
.../apache/iotdb/subscription/it/RetryRule.java | 69 ++++++++++++++++++++++
...oTDBSnapshotTSPatternDatasetPushConsumerIT.java | 8 +++
...IoTDBSnapshotTSPatternTsfilePushConsumerIT.java | 8 +++
.../multi/IoTDBOneConsumerMultiTopicsTsfileIT.java | 7 +++
5 files changed, 125 insertions(+)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/Retry.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/Retry.java
new file mode 100644
index 00000000000..0d748b019ab
--- /dev/null
+++ b/integration-test/src/test/java/org/apache/iotdb/subscription/it/Retry.java
@@ -0,0 +1,33 @@
+/*
+ * 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.iotdb.subscription.it;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** Marks a test method to specify how many times it should be retried (first
run + retries). */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Retry {
+ /** Total execution count = 1 (initial run) + number of retries */
+ int times() default 3;
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/RetryRule.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/RetryRule.java
new file mode 100644
index 00000000000..5a577c21f36
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/RetryRule.java
@@ -0,0 +1,69 @@
+/*
+ * 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.iotdb.subscription.it;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/** Controls retry logic for test failures based on the {@link Retry}
annotation. */
+public class RetryRule implements TestRule {
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ // Read the annotation on the method; if absent, do not retry (times = 1)
+ final Retry retry = description.getAnnotation(Retry.class);
+ final int times = (retry != null ? retry.times() : 1);
+ return new RetryStatement(base, description, times);
+ }
+
+ private static class RetryStatement extends Statement {
+ private final Statement base;
+ private final Description description;
+ private final int times;
+
+ RetryStatement(final Statement base, final Description description, final
int times) {
+ this.base = base;
+ this.description = description;
+ this.times = times;
+ }
+
+ @Override
+ public void evaluate() throws Throwable {
+ Throwable lastThrowable;
+ for (int i = 1; i <= times; i++) {
+ try {
+ base.evaluate();
+ return; // Return immediately on success
+ } catch (final Throwable t) {
+ lastThrowable = t;
+ System.err.printf(
+ "[%s] run %d/%d failed: %s%n",
+ description.getDisplayName(), i, times, t.getMessage());
+ if (i == times) {
+ // If it's the last attempt, and it still fails, throw the
exception
+ throw lastThrowable;
+ }
+ // Otherwise, continue to the next retry
+ }
+ }
+ }
+ }
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternDatasetPushConsumerIT.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternDatasetPushConsumerIT.java
index b90b46a3e2d..21c705d6de2 100644
---
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternDatasetPushConsumerIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternDatasetPushConsumerIT.java
@@ -29,6 +29,8 @@ import
org.apache.iotdb.session.subscription.consumer.ConsumeResult;
import
org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePushConsumer;
import
org.apache.iotdb.session.subscription.payload.SubscriptionSessionDataSet;
import org.apache.iotdb.subscription.it.IoTDBSubscriptionITConstant;
+import org.apache.iotdb.subscription.it.Retry;
+import org.apache.iotdb.subscription.it.RetryRule;
import
org.apache.iotdb.subscription.it.triple.treemodel.regression.AbstractSubscriptionTreeRegressionIT;
import org.apache.thrift.TException;
@@ -40,6 +42,7 @@ import org.apache.tsfile.write.schema.IMeasurementSchema;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -59,6 +62,9 @@ import static
org.apache.iotdb.subscription.it.IoTDBSubscriptionITConstant.AWAIT
@Category({MultiClusterIT2SubscriptionTreeRegressionConsumer.class})
public class IoTDBSnapshotTSPatternDatasetPushConsumerIT
extends AbstractSubscriptionTreeRegressionIT {
+
+ @Rule public RetryRule retryRule = new RetryRule();
+
private static final String database =
"root.test.SnapshotTSPatternDatasetPushConsumer";
private static final String database2 =
"root.SnapshotTSPatternDatasetPushConsumer";
private static final String device = database + ".d_0";
@@ -121,6 +127,7 @@ public class IoTDBSnapshotTSPatternDatasetPushConsumerIT
subs.dropTopic(topicName);
dropDB(database);
dropDB(database2);
+ schemaList.clear();
super.tearDown();
}
@@ -140,6 +147,7 @@ public class IoTDBSnapshotTSPatternDatasetPushConsumerIT
}
@Test
+ @Retry
public void do_test()
throws InterruptedException,
TException,
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternTsfilePushConsumerIT.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternTsfilePushConsumerIT.java
index 2b34045e463..24bb905054b 100644
---
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternTsfilePushConsumerIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/mode/IoTDBSnapshotTSPatternTsfilePushConsumerIT.java
@@ -27,6 +27,8 @@ import org.apache.iotdb.rpc.subscription.config.TopicConstant;
import org.apache.iotdb.session.subscription.consumer.AckStrategy;
import org.apache.iotdb.session.subscription.consumer.ConsumeResult;
import
org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePushConsumer;
+import org.apache.iotdb.subscription.it.Retry;
+import org.apache.iotdb.subscription.it.RetryRule;
import
org.apache.iotdb.subscription.it.triple.treemodel.regression.AbstractSubscriptionTreeRegressionIT;
import org.apache.thrift.TException;
@@ -43,6 +45,7 @@ import org.apache.tsfile.write.schema.IMeasurementSchema;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -65,6 +68,9 @@ import static
org.apache.iotdb.subscription.it.IoTDBSubscriptionITConstant.AWAIT
@Category({MultiClusterIT2SubscriptionTreeRegressionConsumer.class})
public class IoTDBSnapshotTSPatternTsfilePushConsumerIT
extends AbstractSubscriptionTreeRegressionIT {
+
+ @Rule public RetryRule retryRule = new RetryRule();
+
private static final String database =
"root.test.SnapshotTSPatternTsfilePushConsumer";
private static final String database2 =
"root.SnapshotTSPatternTsfilePushConsumer";
private static final String device = database + ".d_0";
@@ -124,6 +130,7 @@ public class IoTDBSnapshotTSPatternTsfilePushConsumerIT
subs.dropTopic(topicName);
dropDB(database);
dropDB(database2);
+ schemaList.clear();
super.tearDown();
}
@@ -143,6 +150,7 @@ public class IoTDBSnapshotTSPatternTsfilePushConsumerIT
}
@Test
+ @Retry
public void do_test()
throws InterruptedException,
TException,
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/multi/IoTDBOneConsumerMultiTopicsTsfileIT.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/multi/IoTDBOneConsumerMultiTopicsTsfileIT.java
index f3be9db507d..3147a7ed5b6 100644
---
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/multi/IoTDBOneConsumerMultiTopicsTsfileIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/treemodel/regression/pushconsumer/multi/IoTDBOneConsumerMultiTopicsTsfileIT.java
@@ -26,6 +26,8 @@ import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.subscription.consumer.AckStrategy;
import org.apache.iotdb.session.subscription.consumer.ConsumeResult;
import
org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePushConsumer;
+import org.apache.iotdb.subscription.it.Retry;
+import org.apache.iotdb.subscription.it.RetryRule;
import
org.apache.iotdb.subscription.it.triple.treemodel.regression.AbstractSubscriptionTreeRegressionIT;
import org.apache.thrift.TException;
@@ -42,6 +44,7 @@ import org.apache.tsfile.write.schema.IMeasurementSchema;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -61,6 +64,9 @@ import static
org.apache.iotdb.subscription.it.IoTDBSubscriptionITConstant.AWAIT
@RunWith(IoTDBTestRunner.class)
@Category({MultiClusterIT2SubscriptionTreeRegressionConsumer.class})
public class IoTDBOneConsumerMultiTopicsTsfileIT extends
AbstractSubscriptionTreeRegressionIT {
+
+ @Rule public RetryRule retryRule = new RetryRule();
+
private static final String database =
"root.test.OneConsumerMultiTopicsTsfile";
private static final String database2 = "root.OneConsumerMultiTopicsTsfile";
private static final String device = database + ".d_0";
@@ -123,6 +129,7 @@ public class IoTDBOneConsumerMultiTopicsTsfileIT extends
AbstractSubscriptionTre
}
@Test
+ @Retry
public void do_test()
throws InterruptedException,
TException,