JackieTien97 commented on code in PR #19234:
URL: https://github.com/apache/iotdb/pull/19234#discussion_r4558425425


##########
integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQExecIT.java:
##########
@@ -52,6 +61,105 @@ public static void tearDown() throws Exception {
     EnvFactory.getEnv().cleanClusterEnvironment();
   }
 
+  @Test
+  public void testCQExecutionWithReadDataPermission() throws Exception {
+    testCQExecutionWithReadDataPermission(false);
+  }
+
+  @Test
+  public void testCQExecutionWithReadDataPermissionAlignByDevice() throws 
Exception {
+    testCQExecutionWithReadDataPermission(true);
+  }
+
+  private void testCQExecutionWithReadDataPermission(boolean alignByDevice) 
throws Exception {
+    String cqId = alignByDevice ? "cq_read_auth_aligned" : "cq_read_auth";
+    String database = "root." + cqId;
+    String username = cqId + "_user";
+    String password = "CQRead!Test2026";
+    String queryBody =
+        "SELECT * INTO "
+            + database
+            + ".target(::) FROM "
+            + database
+            + ".source"
+            + (alignByDevice ? " ALIGN BY DEVICE" : "");
+    String resultQuery = "SELECT s1, s2 FROM " + database + ".target";
+    String resultHeader = "Time," + database + ".target.s1," + database + 
".target.s2,";
+
+    IClientManager<TEndPoint, SyncDataNodeInternalServiceClient> clients =
+        new IClientManager.Factory<TEndPoint, 
SyncDataNodeInternalServiceClient>()
+            .createClientManager(
+                new 
ClientPoolFactory.SyncDataNodeInternalServiceClientPoolFactory());
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE USER " + username + " '" + password + "'");

Review Comment:
   Fixed in 17d1fefc56: setup now registers each cleanup statement right after 
the resource is created, and `CQTestCleanup` runs every registered statement in 
reverse order on close. Because it is a try-with-resources resource, cleanup 
failures are added as suppressed exceptions instead of replacing the original 
test failure.



##########
integration-test/src/test/java/org/apache/iotdb/db/it/cq/IoTDBCQExecIT.java:
##########
@@ -52,6 +61,105 @@ public static void tearDown() throws Exception {
     EnvFactory.getEnv().cleanClusterEnvironment();
   }
 
+  @Test
+  public void testCQExecutionWithReadDataPermission() throws Exception {
+    testCQExecutionWithReadDataPermission(false);
+  }
+
+  @Test
+  public void testCQExecutionWithReadDataPermissionAlignByDevice() throws 
Exception {
+    testCQExecutionWithReadDataPermission(true);
+  }
+
+  private void testCQExecutionWithReadDataPermission(boolean alignByDevice) 
throws Exception {
+    String cqId = alignByDevice ? "cq_read_auth_aligned" : "cq_read_auth";
+    String database = "root." + cqId;
+    String username = cqId + "_user";
+    String password = "CQRead!Test2026";
+    String queryBody =
+        "SELECT * INTO "
+            + database
+            + ".target(::) FROM "
+            + database
+            + ".source"
+            + (alignByDevice ? " ALIGN BY DEVICE" : "");
+    String resultQuery = "SELECT s1, s2 FROM " + database + ".target";
+    String resultHeader = "Time," + database + ".target.s1," + database + 
".target.s2,";
+
+    IClientManager<TEndPoint, SyncDataNodeInternalServiceClient> clients =
+        new IClientManager.Factory<TEndPoint, 
SyncDataNodeInternalServiceClient>()
+            .createClientManager(
+                new 
ClientPoolFactory.SyncDataNodeInternalServiceClientPoolFactory());
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE USER " + username + " '" + password + "'");
+      statement.execute("CREATE DATABASE " + database);
+      try {
+        statement.execute("CREATE TIMESERIES " + database + ".source.s1 WITH 
DATATYPE=INT64");
+        statement.execute("CREATE TIMESERIES " + database + ".source.s2 WITH 
DATATYPE=INT64");
+        statement.execute("CREATE TIMESERIES " + database + ".target.s1 WITH 
DATATYPE=INT64");
+        statement.execute("CREATE TIMESERIES " + database + ".target.s2 WITH 
DATATYPE=INT64");
+        statement.execute(
+            "INSERT INTO "
+                + database
+                + ".source(time, s1, s2) VALUES (1, 11, 21), (1001, 12, 22), 
(2001, 13, 23)");
+        statement.execute("GRANT SYSTEM ON root.** TO USER " + username);
+        statement.execute("GRANT WRITE_DATA ON " + database + ".target.** TO 
USER " + username);
+        statement.execute("GRANT READ_DATA ON " + database + ".source.s1 TO 
USER " + username);
+
+        try (Connection userConnection = 
EnvFactory.getEnv().getConnection(username, password);
+            Statement userStatement = userConnection.createStatement()) {
+          // Keep the scheduler idle and execute deterministic windows through 
its DataNode RPC.
+          userStatement.execute(
+              "CREATE CQ "
+                  + cqId
+                  + " RESAMPLE EVERY 1s BOUNDARY "
+                  + (System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1))
+                  + " BEGIN "
+                  + queryBody
+                  + " END");
+        }
+        try {
+          TExecuteCQ request = new TExecuteCQ(queryBody, 0, 1000, 10000, 
"UTC", cqId, username);
+          executeCQOnAllDataNodes(clients, request);

Review Comment:
   Fixed in 17d1fefc56: the IT now covers explicit-target CQs (ordinary and 
ALIGN BY DEVICE) under partial authorization, revocation, and re-granting, plus 
a deleted owner for every variant, which exercises the new failure branch. 
`DataNodeInternalRPCServiceImplCQTest` also checks that a failed authorization 
returns before schema analysis and that the session and query executions are 
cleaned up. On 17d1fefc56, CI ran all 9 `IoTDBCQExecIT` cases in Cluster IT - 
1C3D, and both datanode unit-test jobs ran the new unit tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to