diqiu50 commented on code in PR #9776:
URL: https://github.com/apache/gravitino/pull/9776#discussion_r2757778846


##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/ClickHouseContainer.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.gravitino.integration.test.container;
+
+import static java.lang.String.format;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.rnorth.ducttape.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Network;
+
+public class ClickHouseContainer extends BaseContainer {
+  public static final Logger LOG = 
LoggerFactory.getLogger(ClickHouseContainer.class);
+
+  public static final String DEFAULT_IMAGE = "clickhouse:24.8.14";
+  public static final String HOST_NAME = "gravitino-ci-clickhouse";
+  public static final int CLICKHOUSE_PORT = 8123;
+  public static final String USER_NAME = "default";
+  public static final String PASSWORD = "default";
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  protected ClickHouseContainer(
+      String image,
+      String hostName,
+      Set<Integer> ports,
+      Map<String, String> extraHosts,
+      Map<String, String> filesToMount,
+      Map<String, String> envVars,
+      Optional<Network> network) {
+    super(image, hostName, ports, extraHosts, filesToMount, envVars, network);
+  }
+
+  @Override
+  protected void setupContainer() {
+    super.setupContainer();
+    withLogConsumer(new PrintingContainerLog(format("%-14s| ", 
"clickHouseContainer")));
+  }
+
+  @Override
+  public void start() {
+    super.start();
+    Preconditions.check("clickHouse container startup failed!", 
checkContainerStatus(5));
+  }
+
+  @Override
+  protected boolean checkContainerStatus(int retryLimit) {
+    for (int attempt = 1; attempt <= retryLimit; attempt++) {
+      try (Connection connection =
+              DriverManager.getConnection(getJdbcUrl(), USER_NAME, 
getPassword());
+          Statement statement = connection.createStatement()) {
+        // Simple health check query; ClickHouse should respond if it is ready.
+        statement.execute("SELECT 1");
+        LOG.info("clickHouse container is healthy after {} attempt(s)", 
attempt);
+        return true;
+      } catch (SQLException e) {
+        LOG.warn(
+            "Failed to connect to clickHouse container on attempt {}/{}: {}",
+            attempt,
+            retryLimit,
+            e.getMessage(),
+            e);
+        if (attempt < retryLimit) {
+          try {
+            Thread.sleep(1000L);
+          } catch (InterruptedException interruptedException) {

Review Comment:
   Using awaitility



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