jihoonson commented on a change in pull request #11643:
URL: https://github.com/apache/druid/pull/11643#discussion_r700615062



##########
File path: 
integration-tests/src/test/java/org/apache/druid/tests/query/ITSqlCancelTest.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.druid.tests.query;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Inject;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.RE;
+import org.apache.druid.java.util.http.client.response.StatusResponseHolder;
+import org.apache.druid.query.QueryException;
+import org.apache.druid.query.QueryInterruptedException;
+import org.apache.druid.sql.http.SqlQuery;
+import org.apache.druid.testing.IntegrationTestingConfig;
+import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
+import org.apache.druid.testing.clients.SqlResourceTestClient;
+import org.apache.druid.testing.guice.DruidTestModuleFactory;
+import org.apache.druid.testing.utils.ITRetryUtil;
+import org.apache.druid.testing.utils.SqlTestQueryHelper;
+import org.apache.druid.tests.TestNGGroup;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+@Test(groups = TestNGGroup.QUERY)
+@Guice(moduleFactory = DruidTestModuleFactory.class)
+public class ITSqlCancelTest
+{
+  private static final String WIKIPEDIA_DATA_SOURCE = "wikipedia_editstream";
+
+  private static final String QUERY
+      = "SELECT sleep(CASE WHEN added > 0 THEN 1 ELSE 0 END) FROM 
wikipedia_editstream LIMIT 15";
+
+  private static final int NUM_QUERIES = 3;
+
+  @Inject
+  private CoordinatorResourceTestClient coordinatorClient;
+  @Inject
+  private SqlTestQueryHelper sqlHelper;
+  @Inject
+  private SqlResourceTestClient sqlClient;
+  @Inject
+  private IntegrationTestingConfig config;
+  @Inject
+  private ObjectMapper jsonMapper;
+
+  @BeforeMethod
+  public void before()
+  {
+    // ensure that wikipedia segments are loaded completely
+    ITRetryUtil.retryUntilTrue(
+        () -> coordinatorClient.areSegmentsLoaded(WIKIPEDIA_DATA_SOURCE), 
"wikipedia segment load"
+    );
+  }
+
+  @Test
+  public void testCancelValidQuery() throws Exception
+  {
+    final String queryId = "sql-cancel-test";
+    final List<Future<StatusResponseHolder>> queryResponseFutures = new 
ArrayList<>();
+    for (int i = 0; i < NUM_QUERIES; i++) {
+      queryResponseFutures.add(
+          sqlClient.queryAsync(
+              sqlHelper.getQueryURL(config.getRouterUrl()),
+              new SqlQuery(QUERY, null, false, ImmutableMap.of("sqlQueryId", 
queryId), null)
+          )
+      );
+    }
+
+    // Wait until the sqlLifecycle is authorized and registered
+    Thread.sleep(1000);

Review comment:
       One case it could be flaky is that the test query finishes in less than 
one second. I changed the query to run exactly for 15 seconds and added a 
comment about it.




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to