-
Notifications
You must be signed in to change notification settings - Fork 1
Clickhouse support for tests #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f0e889
Added ClickHouse Server tests support.
mzitnik a049568
Added ClickHouse Server tests support.
mzitnik 74001a2
Update env variables
mzitnik 4464984
Fix port retrival
mzitnik 8357c3d
Fix wakeup logic
mzitnik 63e9da7
Adjust cloud config
mzitnik 3226918
Change ping logic & create database on init
mzitnik 7354a7b
Upload error report to artifact
mzitnik 4b72f14
Fix reports filename
mzitnik 55df666
Adding timeout
mzitnik c018cbf
Remove redundant code
mzitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ctor-clickhouse-base/src/test/java/org/apache/flink/connector/test/FlinkClusterTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.apache.flink.connector.test; | ||
|
|
||
| import org.apache.flink.connector.test.embedded.clickhouse.ClickHouseServerForTests; | ||
| import org.apache.flink.connector.test.embedded.flink.EmbeddedFlinkClusterForTests; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
|
|
||
| public class FlinkClusterTests { | ||
| @BeforeAll | ||
| static void setUp() throws Exception { | ||
| EmbeddedFlinkClusterForTests.setUp(); | ||
| ClickHouseServerForTests.setUp(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void tearDown() { | ||
| EmbeddedFlinkClusterForTests.tearDown(); | ||
| ClickHouseServerForTests.tearDown(); | ||
| } | ||
|
|
||
| } |
91 changes: 91 additions & 0 deletions
91
...st/java/org/apache/flink/connector/test/embedded/clickhouse/ClickHouseServerForTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.apache.flink.connector.test.embedded.clickhouse; | ||
|
|
||
| import com.clickhouse.client.api.Client; | ||
| import com.clickhouse.client.api.query.GenericRecord; | ||
| import org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| import org.testcontainers.clickhouse.ClickHouseContainer; | ||
|
|
||
| public class ClickHouseServerForTests { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(ClickHouseServerForTests.class); | ||
|
|
||
| protected static boolean isCloud = ClickHouseTestHelpers.isCloud(); | ||
| protected static String database = null; | ||
| protected static ClickHouseContainer db = null; | ||
|
|
||
| protected static String host = null; | ||
| protected static int port = 0; | ||
| protected static String username = null; | ||
| protected static String password = null; | ||
| protected static boolean isSSL = false; | ||
|
|
||
|
|
||
| public static void initConfiguration() { | ||
| if (isCloud) { | ||
| LOG.info("Init ClickHouse Cloud Configuration"); | ||
| host = System.getenv("CLICKHOUSE_CLOUD_HOST"); | ||
| port = Integer.parseInt(ClickHouseTestHelpers.HTTPS_PORT); | ||
| database = String.format("flink_connector_test_%s", System.currentTimeMillis()); | ||
| username = ClickHouseTestHelpers.USERNAME_DEFAULT; | ||
| password = System.getenv("CLICKHOUSE_CLOUD_PASSWORD"); | ||
| } else { | ||
| LOG.info("Init ClickHouse Docker Configuration"); | ||
| host = db.getHost(); | ||
| port = db.getFirstMappedPort(); | ||
| database = ClickHouseTestHelpers.DATABASE_DEFAULT; | ||
| username = db.getUsername(); | ||
| password = db.getPassword(); | ||
| } | ||
| isSSL = ClickHouseTestHelpers.isCloud(); | ||
| } | ||
| public static void setUp() throws InterruptedException, ExecutionException { | ||
| if (!isCloud) { | ||
| db = new ClickHouseContainer(ClickHouseTestHelpers.CLICKHOUSE_DOCKER_IMAGE).withPassword("test_password").withEnv("CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT", "1"); | ||
| db.start(); | ||
| } | ||
| initConfiguration(); | ||
| // wakeup cloud | ||
| // have a for loop | ||
| boolean isLive = false; | ||
| int counter = 0; | ||
| while (counter < 5) { | ||
| isLive = ClickHouseTestHelpers.ping(host, port, isSSL, username, password); | ||
| if (isLive) { | ||
| String createDatabase = String.format("CREATE DATABASE IF NOT EXISTS `%s`", database); | ||
| executeSql(createDatabase); | ||
| return; | ||
| } | ||
| Thread.sleep(2000); | ||
| counter++; | ||
| } | ||
| throw new RuntimeException("Failed to connect to ClickHouse"); | ||
| } | ||
|
|
||
| public static void tearDown() { | ||
| if (db != null) { | ||
| db.stop(); | ||
| } | ||
| } | ||
|
|
||
| public static String getDataBase() { return database; } | ||
|
|
||
| public static void executeSql(String sql) throws ExecutionException, InterruptedException { | ||
| Client client = ClickHouseTestHelpers.getClient(host, port, isSSL, username, password); | ||
| client.execute(sql).get(); | ||
| } | ||
|
|
||
| public static int countRows(String table) throws ExecutionException, InterruptedException { | ||
| String countSql = String.format("SELECT COUNT(*) FROM `%s`.`%s`", database, table); | ||
| Client client = ClickHouseTestHelpers.getClient(host, port, isSSL, username, password); | ||
| List<GenericRecord> countResult = client.queryAll(countSql); | ||
| return countResult.get(0).getInteger(1); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
.../test/java/org/apache/flink/connector/test/embedded/clickhouse/ClickHouseTestHelpers.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.apache.flink.connector.test.embedded.clickhouse; | ||
|
|
||
| import com.clickhouse.client.api.Client; | ||
| import com.clickhouse.client.api.enums.Protocol; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class ClickHouseTestHelpers { | ||
| private static final Logger LOG = LoggerFactory.getLogger(ClickHouseTestHelpers.class); | ||
|
|
||
| public static final String CLICKHOUSE_VERSION_DEFAULT = "24.3"; | ||
| public static final String CLICKHOUSE_PROXY_VERSION_DEFAULT = "23.8"; | ||
| public static final String CLICKHOUSE_DOCKER_IMAGE = String.format("clickhouse/clickhouse-server:%s", getClickhouseVersion()); | ||
| public static final String CLICKHOUSE_FOR_PROXY_DOCKER_IMAGE = String.format("clickhouse/clickhouse-server:%s", CLICKHOUSE_PROXY_VERSION_DEFAULT); | ||
|
|
||
| public static final String HTTPS_PORT = "8443"; | ||
| public static final String DATABASE_DEFAULT = "default"; | ||
| public static final String USERNAME_DEFAULT = "default"; | ||
|
|
||
| private static final int TIMEOUT_VALUE = 60; | ||
| private static final TimeUnit TIMEOUT_UNIT = TimeUnit.SECONDS; | ||
|
|
||
| public static String getClickhouseVersion() { | ||
| String clickHouseVersion = System.getenv("CLICKHOUSE_VERSION"); | ||
| if (clickHouseVersion == null) { | ||
| clickHouseVersion = CLICKHOUSE_VERSION_DEFAULT; | ||
| } | ||
| return clickHouseVersion; | ||
| } | ||
|
|
||
| public static boolean isCloud() { | ||
| String clickHouseVersion = System.getenv("CLICKHOUSE_VERSION"); | ||
| return clickHouseVersion != null && clickHouseVersion.equalsIgnoreCase("cloud"); | ||
| } | ||
|
|
||
| public static Client getClient(String host, int port, boolean ssl, String username, String password) { | ||
| return new Client.Builder().addEndpoint(Protocol.HTTP, host, port, ssl) | ||
| .setUsername(username) | ||
| .setPassword(password) | ||
| .setConnectTimeout(TIMEOUT_VALUE, TIMEOUT_UNIT.toChronoUnit()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static boolean ping(String host, int port, boolean ssl, String username, String password) { | ||
| Client client = getClient(host, port, ssl, username, password); | ||
| return client.ping(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
flink-connector-clickhouse-base/src/test/resources/log4j.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Define the root logger with appender X | ||
| log4j.rootLogger=INFO, console | ||
| #log4j.logger.org.testcontainers=WARN | ||
| log4j.logger.com.clickhouse.kafka=DEBUG | ||
|
|
||
| log4j.appender.console= org.apache.log4j.ConsoleAppender | ||
| log4j.appender.console.layout=org.apache.log4j.PatternLayout | ||
| log4j.appender.console.layout.conversionPattern=[%d] %p %C %m%n |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is no longer used after changing the base class to FlinkClusterTests. Consider removing it to clean up unused imports.