This is an automated email from the ASF dual-hosted git repository.

Caideyipi pushed a commit to branch codex/metadata-fuzzy-it
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 21ec00488db69d518c168aa9ec72675a3bec85a9
Author: Caideyipi <[email protected]>
AuthorDate: Thu Dec 3 11:32:16 2026 +0800

    Add metadata fuzzy integration test
---
 .../iotdb/db/it/schema/IoTDBMetadataFuzzyIT.java   | 153 +++++++++++++++++++++
 1 file changed, 153 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBMetadataFuzzyIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBMetadataFuzzyIT.java
new file mode 100644
index 00000000000..203caf723d5
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBMetadataFuzzyIT.java
@@ -0,0 +1,153 @@
+/*
+ * 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.it.schema;
+
+import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBMetadataFuzzyIT {
+
+  private static final int ITERATION_COUNT = 100;
+
+  private static final String SEED_PROPERTY = "iotdb.it.metadataFuzzy.seed";
+
+  private static final String[] DATA_TYPES = {
+    "BOOLEAN", "INT32", "INT64", "FLOAT", "DOUBLE", "TEXT", "TIMESTAMP", 
"DATE", "BLOB", "STRING"
+  };
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testRandomizedTimeseriesMetadataConsistency() throws Exception {
+    long seed = Long.getLong(SEED_PROPERTY, new Random().nextLong());
+    Random random = new Random(seed);
+    String database = "root.fuzzy_" + Long.toUnsignedString(seed, 
Character.MAX_RADIX);
+    Map<String, String> expected = new HashMap<>();
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE DATABASE " + database);
+      try {
+        for (int iteration = 0; iteration < ITERATION_COUNT; iteration++) {
+          boolean create = expected.isEmpty() || random.nextInt(100) < 65;
+          String sql;
+          String timeseries = null;
+          String dataType = null;
+          if (create) {
+            timeseries = generateTimeseriesPath(database, random, iteration);
+            dataType = DATA_TYPES[random.nextInt(DATA_TYPES.length)];
+            sql = "CREATE TIMESERIES " + timeseries + " " + dataType;
+          } else {
+            ArrayList<String> existingTimeseries = new 
ArrayList<>(expected.keySet());
+            timeseries = 
existingTimeseries.get(random.nextInt(existingTimeseries.size()));
+            sql = "DELETE TIMESERIES " + timeseries;
+          }
+
+          try {
+            statement.execute(sql);
+          } catch (SQLException e) {
+            throw new AssertionError(
+                "Metadata fuzz failed with seed "
+                    + seed
+                    + " at iteration "
+                    + iteration
+                    + ": "
+                    + sql,
+                e);
+          }
+
+          if (create) {
+            expected.put(timeseries, dataType);
+          } else {
+            expected.remove(timeseries);
+          }
+
+          Map<String, String> actual = readTimeseriesMetadata(statement, 
database, seed, iteration);
+          assertEquals(
+              "Metadata mismatch with seed " + seed + " at iteration " + 
iteration,
+              expected,
+              actual);
+        }
+      } finally {
+        statement.execute("DROP DATABASE " + database);
+      }
+    }
+  }
+
+  private static String generateTimeseriesPath(String database, Random random, 
int iteration) {
+    StringBuilder path = new 
StringBuilder(database).append(".d").append(random.nextInt(8));
+    int additionalDepth = random.nextInt(3);
+    for (int depth = 0; depth < additionalDepth; depth++) {
+      path.append(".n").append(random.nextInt(8));
+    }
+    return path.append(".s").append(iteration).toString();
+  }
+
+  private static Map<String, String> readTimeseriesMetadata(
+      Statement statement, String database, long seed, int iteration) throws 
SQLException {
+    Map<String, String> metadata = new HashMap<>();
+    try (ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES " + 
database + ".**")) {
+      while (resultSet.next()) {
+        String timeseries = 
resultSet.getString(ColumnHeaderConstant.TIMESERIES);
+        String previousDataType =
+            metadata.put(timeseries, 
resultSet.getString(ColumnHeaderConstant.DATATYPE));
+        assertNull(
+            "Duplicate metadata row for "
+                + timeseries
+                + " with seed "
+                + seed
+                + " at iteration "
+                + iteration,
+            previousDataType);
+      }
+    }
+    return metadata;
+  }
+}

Reply via email to