Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,28 @@ jobs:
EOF
- name: Install Java client
run: mvn --also-make --batch-mode --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true install
- name: Generate Database Name
run: |
# Combine the GitHub Run ID and a random number to guarantee uniqueness
RANDOM_DB="clickhouse_java_test_${GITHUB_RUN_ID}_${RANDOM}"

# Write it to GITHUB_ENV so future steps can access it as $DB_NAME
Comment thread
chernser marked this conversation as resolved.
Outdated
echo "TEST_DB_NAME=$RANDOM_DB" >> $GITHUB_ENV
echo "Generated database name: $RANDOM_DB"

- name: Create Temporary Database
env:
CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }}
CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }}
run: |
echo "Creating database: \`$TEST_DB_NAME\`"
curl -s -u "default:$CLICKHOUSE_CLOUD_PASSWORD" "https://$CLICKHOUSE_CLOUD_HOST:8443" --data-binary "CREATE DATABASE IF NOT EXISTS $TEST_DB_NAME"
Comment thread
chernser marked this conversation as resolved.
Outdated
- name: Test http client
env:
CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }}
CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT }}
CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }}
CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }}
CLIENT_JWT: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_JWT_DESERT_VM_43 }}
JWT_TEST_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }}
run: |
mvn --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -DclickhouseVersion=${{ matrix.clickhouse }} -Dprotocol=http -Dmaven.javadoc.skip=true verify
- name: Upload test results
Expand All @@ -271,6 +288,20 @@ jobs:
path: |
**/target/failsafe-reports
**/target/surefire-reports
- name: Cleanup Database Unconditionally
if: always() # CRITICAL: This ensures the step runs regardless of previous success/failure
env:
CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }}
CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }}
run: |
# Verify we actually generated a DB name to avoid dropping something accidentally
if [ -n "$TEST_DB_NAME" ]; then
DROP_STMT="DROP DATABASE IF EXISTS \`$TEST_DB_NAME\`"
echo "Cleaning up database: \`$TEST_DB_NAME\` with statement '$DROP_STMT'";
curl -s -u "default:$CLICKHOUSE_CLOUD_PASSWORD" "https://$CLICKHOUSE_CLOUD_HOST:8443" --data-binary "$DROP_STMT";
else
echo "No database name was generated; skipping cleanup.";
fi;

test-jdbc-driver:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -321,9 +352,6 @@ jobs:
- name: Install Java client
run: mvn --also-make --batch-mode --no-transfer-progress --projects clickhouse-http-client,client-v2 -DskipTests=true -Dmaven.javadoc.skip=true install
- name: Test JDBC driver
env:
CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }}
CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT }}
run: |
mvn --batch-mode --no-transfer-progress --projects clickhouse-jdbc,jdbc-v2 -DclickhouseVersion=${{ matrix.clickhouse }} -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true verify
- name: Upload test results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@
private static boolean isCloud = false;

private static final String database;
private static final boolean localDatabase;

Check failure on line 65 in clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ4oUKMBPEFRCu6gz8uw&open=AZ4oUKMBPEFRCu6gz8uw&pullRequest=2852

static {
properties = new Properties(System.getProperties());
database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_" + System.currentTimeMillis();
String externalDatabase = System.getenv("TEST_DB_NAME"); // see build.yaml workflow
if (externalDatabase != null && !externalDatabase.trim().isEmpty()) {
localDatabase = false;
database = externalDatabase;
} else {
Comment thread
chernser marked this conversation as resolved.
localDatabase = true;
database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_" + System.currentTimeMillis();
}

LOGGER.info("Local database: {}", localDatabase);

String proxy = properties.getProperty("proxyAddress");
if (proxy != null && !proxy.isEmpty()) { // use external proxy
Expand Down Expand Up @@ -320,10 +330,11 @@
@BeforeSuite(groups = {"integration"})
public static void beforeSuite() {
if (isCloud) {
if (!runQuery("CREATE DATABASE IF NOT EXISTS " + database)) {
throw new RuntimeException("Failed to create database for testing.");
if (localDatabase) {
if (!runQuery("CREATE DATABASE IF NOT EXISTS " + database)) {

Check warning on line 334 in clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ4oUKMBPEFRCu6gz8uu&open=AZ4oUKMBPEFRCu6gz8uu&pullRequest=2852
throw new RuntimeException("Failed to create database for testing.");
}
}

return;
}

Expand Down Expand Up @@ -358,8 +369,10 @@
}

if (isCloud) {
if (!runQuery("DROP DATABASE IF EXISTS `" + database + "`")) {
LOGGER.warn("Failed to drop database for testing.");
if (localDatabase) {

Check warning on line 372 in clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ4oUKMBPEFRCu6gz8uv&open=AZ4oUKMBPEFRCu6gz8uv&pullRequest=2852
if (!runQuery("DROP DATABASE IF EXISTS `" + database + "`")) {
LOGGER.warn("Failed to drop database for testing.");
}
}
}
}
Expand Down Expand Up @@ -391,16 +404,17 @@
try {
URL serverURL = new URL(uri);
LOGGER.info("sending request to {} (uri={})", serverURL, uri);

byte[] postData = sql.getBytes(StandardCharsets.UTF_8);
for (int attempts = 0; attempts < 10; attempts++) {
HttpURLConnection httpConn = (HttpURLConnection) serverURL.openConnection();
try {
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(("default:" + getPassword()).getBytes()));
httpConn.setFixedLengthStreamingMode(postData.length);

try (OutputStream out = httpConn.getOutputStream()) {
out.write(sql.getBytes(StandardCharsets.UTF_8));
out.write(postData, 0, postData.length);
out.flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,17 @@ public void testJWTWithCloud() throws Exception {
if (!isCloud()) {
return; // only for cloud
}
String jwt = System.getenv("CLIENT_JWT");
final String jwt = System.getenv("CLIENT_JWT");
final String host = System.getenv("JWT_TEST_HOST");
Assert.assertTrue(jwt != null && !jwt.trim().isEmpty(), "JWT is missing");
Assert.assertFalse(jwt.contains("\n") || jwt.contains("-----"), "JWT should be single string ready for HTTP header");
Comment thread
chernser marked this conversation as resolved.
try (Client client = newClient().useBearerTokenAuth(jwt).build()) {
try (Client client = new Client.Builder()
.addEndpoint(Protocol.HTTP, host, 8443, true)
.setUsername("default")
.compressClientRequest(false)
.setDefaultDatabase("default")
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "1")
.useBearerTokenAuth(jwt).build()) {
try {
List<GenericRecord> response = client.queryAll("SELECT user(), now()");
System.out.println("response: " + response.get(0).getString(1) + " time: " + response.get(0).getString(2));
Expand Down
Loading