diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml
index b85da1476721..8e8e5f6e2325 100644
--- a/iotdb-core/datanode/pom.xml
+++ b/iotdb-core/datanode/pom.xml
@@ -378,6 +378,12 @@
awaitility
test
+
+ com.tngtech.archunit
+ archunit
+ 1.3.0
+ test
+
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 5b288d9120c8..942fe993c560 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -3133,7 +3133,6 @@ public int getCachedMNodeSizeInPBTreeMode() {
return cachedMNodeSizeInPBTreeMode;
}
- @TestOnly
public void setCachedMNodeSizeInPBTreeMode(int cachedMNodeSizeInPBTreeMode) {
this.cachedMNodeSizeInPBTreeMode = cachedMNodeSizeInPBTreeMode;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertNode.java
index 79c85994a0bf..aad396228e1d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertNode.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertNode.java
@@ -24,7 +24,6 @@
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -294,7 +293,6 @@ public TRegionReplicaSet getRegionReplicaSet() {
public abstract long getMinTime();
// region partial insert
- @TestOnly
public void markFailedMeasurement(int index) {
throw new UnsupportedOperationException();
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
index cdbe91f4e02d..8dc1c338a940 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
@@ -28,7 +28,6 @@
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.utils.FileUtils;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -444,7 +443,6 @@ public void updateAndFillSchemaCountMap(TDataNodeHeartbeatReq req, TDataNodeHear
}
}
- @TestOnly
public ISchemaEngineStatistics getSchemaEngineStatistics() {
return schemaEngineStatistics;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java
index a120443a086f..55d703a7b4a5 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java
@@ -25,7 +25,6 @@
import org.apache.iotdb.commons.path.MeasurementPath;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathPatternTree;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.exception.metadata.SchemaQuotaExceededException;
import org.apache.iotdb.db.queryengine.common.schematree.ClusterSchemaTree;
import org.apache.iotdb.db.queryengine.plan.relational.planner.node.schema.ConstructTableDevicesBlackListNode;
@@ -94,7 +93,6 @@ public interface ISchemaRegion {
void forceMlog();
- @TestOnly
ISchemaRegionStatistics getSchemaRegionStatistics();
ISchemaRegionMetric getSchemaRegionMetric();
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/WrappedSegment.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/WrappedSegment.java
index e46f1aea0251..8d9d4032883f 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/WrappedSegment.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/schemafile/WrappedSegment.java
@@ -902,7 +902,6 @@ public ByteBuffer getRecord(String key) {
return null;
}
- @TestOnly
public List> getKeyOffsetList() {
short[] offsets = getOffsets();
List> res = new ArrayList<>();
@@ -917,7 +916,6 @@ public List> getKeyOffsetList() {
return res;
}
- @TestOnly
public short[] getOffsets() {
ByteBuffer buf = this.buffer.asReadOnlyBuffer();
short[] ofs = new short[recordNum];
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/template/ClusterTemplateManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/template/ClusterTemplateManager.java
index 4459f29ed6bb..18229858ceb1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/template/ClusterTemplateManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/template/ClusterTemplateManager.java
@@ -651,7 +651,6 @@ public void putTemplate(Template template) {
templateNameMap.put(template.getName(), template.getId());
}
- @TestOnly
public void clear() {
templateIdMap.clear();
templateNameMap.clear();
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
index c73d93de5dad..fddac6d76034 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java
@@ -3940,7 +3940,6 @@ public ILastFlushTimeMap getLastFlushTimeMap() {
return lastFlushTimeMap;
}
- @TestOnly
public TsFileManager getTsFileManager() {
return tsFileManager;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
index f1dde34972f0..249d6f3d04a7 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
@@ -2328,7 +2328,6 @@ public boolean isEmpty() {
&& (workMemTable == null || workMemTable.getTotalPointsNum() == 0);
}
- @TestOnly
public IMemTable getWorkMemTable() {
return workMemTable;
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/WALManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/WALManager.java
index 42f79ea310ab..a048438f0056 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/WALManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/WALManager.java
@@ -26,7 +26,6 @@
import org.apache.iotdb.commons.exception.StartupException;
import org.apache.iotdb.commons.service.IService;
import org.apache.iotdb.commons.service.ServiceType;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -309,7 +308,6 @@ public void syncDeleteOutdatedFilesInWALNodes() {
}
}
- @TestOnly
public void clear() {
totalDiskUsage.set(0);
walNodesManager.clear();
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/NodeAllocationStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/NodeAllocationStrategy.java
index 3824bf3efd88..514f99dffdc4 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/NodeAllocationStrategy.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/NodeAllocationStrategy.java
@@ -19,7 +19,6 @@
package org.apache.iotdb.db.storageengine.dataregion.wal.allocation;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.storageengine.dataregion.wal.node.IWALNode;
import org.apache.iotdb.db.storageengine.dataregion.wal.node.WALNode;
@@ -37,6 +36,5 @@ public interface NodeAllocationStrategy {
/** Get all wal nodes num. Not thread-safe, used for metrics only. */
int getNodesNum();
- @TestOnly
void clear();
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/utils/TsFileValidationScan.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/utils/TsFileValidationScan.java
index 1e6c6e2268e3..d4fd2356ea67 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/utils/TsFileValidationScan.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/utils/TsFileValidationScan.java
@@ -18,7 +18,6 @@
*/
package org.apache.iotdb.db.tools.utils;
-import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
import org.apache.tsfile.common.conf.TSFileDescriptor;
@@ -352,7 +351,6 @@ public int getBadFileNum() {
return badFileNum;
}
- @TestOnly
public void setBadFileNum(int badFileNum) {
this.badFileNum = badFileNum;
}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
new file mode 100644
index 000000000000..335a4959f933
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.db.utils;
+
+import org.apache.iotdb.commons.utils.TestOnly;
+
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.core.domain.JavaClasses;
+import com.tngtech.archunit.core.domain.properties.CanBeAnnotated;
+import com.tngtech.archunit.core.importer.ClassFileImporter;
+import com.tngtech.archunit.core.importer.ImportOption;
+import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests;
+import com.tngtech.archunit.lang.ArchRule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
+
+public class AnnotationTest {
+
+ @Test
+ public void checkTestOnly() {
+ JavaClasses productionClasses =
+ new ClassFileImporter()
+ .withImportOption(new DoNotIncludeTests())
+ .importPackages("org.apache.iotdb");
+ JavaClasses testClasses =
+ new ClassFileImporter()
+ .withImportOption(new ImportOption.OnlyIncludeTests())
+ .importPackages("org.apache.iotdb");
+
+ List testReflectedClasses = new ArrayList<>();
+ for (JavaClass testClass : testClasses) {
+ testReflectedClasses.add(testClass.reflect());
+ }
+
+ ArchRule rule =
+ methods()
+ .that()
+ .areAnnotatedWith(TestOnly.class)
+ .should()
+ .onlyBeCalled()
+ .byClassesThat()
+ .belongToAnyOf(testReflectedClasses.toArray(new Class[0]))
+ .orShould()
+ .onlyBeCalled()
+ .byMethodsThat(
+ CanBeAnnotated.Predicates.annotatedWith(TestOnly.class)); // see next section
+
+ rule.check(productionClasses);
+ }
+}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TestOnly.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TestOnly.java
index d31cbc831951..77c723deec52 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TestOnly.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/TestOnly.java
@@ -30,5 +30,5 @@
* functionality is not guaranteed and may interfere with the normal code.
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
-@Retention(RetentionPolicy.SOURCE)
+@Retention(RetentionPolicy.CLASS)
public @interface TestOnly {}