Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-${{ github.workflow }}

- name: Set up JDK 11
if: ${{ github.base_ref != 'release/1.11' && github.ref_name != 'release/1.11' }}
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
with:
distribution: 'temurin'
java-version: '11'
overwrite-settings: false

- name: Build with Maven
run: mvn clean test -fae -T 2 -B -V -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=25

Expand Down
2 changes: 1 addition & 1 deletion amazon-redshift-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Amazon Redshift plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion aurora-mysql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Aurora DB MySQL plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion aurora-postgresql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Aurora DB PostgreSQL plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion cloudsql-mysql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>CloudSQL MySQL plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion cloudsql-postgresql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>CloudSQL PostgreSQL plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion database-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Database Commons</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright © 2026 Cask Data, Inc.
*
* Licensed 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 io.cdap.plugin.db.connector;

import org.junit.Assert;
import org.junit.Test;

public class DBSpecificFailedConnectionMessageTest {

@Test
public void testNormalizeConnectionArgumentsReordersProperties() {
String jdk8Order = "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {user=username, rewriteBatchedStatements=true, " +
"connectTimeout=20000, tinyInt1isBit=false, socketTimeout=20000}. Error: " +
"ConnectException: Connection refused (Connection refused).";
String jdk11Order = "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {rewriteBatchedStatements=true, tinyInt1isBit=false, " +
"connectTimeout=20000, socketTimeout=20000, user=username}. Error: " +
"ConnectException: Connection refused (Connection refused).";

Assert.assertEquals(DBSpecificFailedConnectionTest.normalizeConnectionArguments(jdk8Order),
DBSpecificFailedConnectionTest.normalizeConnectionArguments(jdk11Order));
}

@Test
public void testNormalizeConnectionArgumentsDetectsMismatchedValues() {
String expected = "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {user=username, connectTimeout=20000}. Error: " +
"ConnectException: Connection refused.";
String mismatchedValue = "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {connectTimeout=30000, user=username}. Error: " +
"ConnectException: Connection refused.";

Assert.assertNotEquals(DBSpecificFailedConnectionTest.normalizeConnectionArguments(expected),
DBSpecificFailedConnectionTest.normalizeConnectionArguments(mismatchedValue));
}

@Test
public void testNormalizeConnectionArgumentsHandlesEmptyAndUnformattedMessages() {
String emptyArgs = "Failed to create connection to database via connection string: " +
"jdbc:h2:mem:test and arguments: {}. Error: SQLException.";
Assert.assertEquals(emptyArgs, DBSpecificFailedConnectionTest.normalizeConnectionArguments(emptyArgs));
Assert.assertEquals("Plain error", DBSpecificFailedConnectionTest.normalizeConnectionArguments("Plain error"));
Assert.assertNull(DBSpecificFailedConnectionTest.normalizeConnectionArguments(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import org.mockito.Mockito;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class DBSpecificFailedConnectionTest {
private static final String JDBC_DRIVER_CLASS_NAME = "oracle.jdbc.OracleDriver";
private static final String ARGS_PREFIX = " and arguments: {";
private static final String ARGS_SUFFIX = "}. Error: ";

protected void test(String jdbcClassName, AbstractDBSpecificConnector connector, String expectedErrorMsg)
throws ClassNotFoundException, IOException {
Expand All @@ -45,6 +48,26 @@ protected void test(String jdbcClassName, AbstractDBSpecificConnector connector,
connector.test(context);
List<ValidationFailure> validationFailures = context.getFailureCollector().getValidationFailures();
Assert.assertEquals(1, validationFailures.size());
Assert.assertEquals(expectedErrorMsg, validationFailures.get(0).getMessage());
Assert.assertEquals(normalizeConnectionArguments(expectedErrorMsg),
normalizeConnectionArguments(validationFailures.get(0).getMessage()));
}

static String normalizeConnectionArguments(String errorMsg) {
if (errorMsg == null) {
return null;
}
int argsStart = errorMsg.indexOf(ARGS_PREFIX);
if (argsStart < 0) {
return errorMsg;
}
int contentStart = argsStart + ARGS_PREFIX.length();
int argsEnd = errorMsg.indexOf(ARGS_SUFFIX, contentStart);
if (argsEnd <= contentStart) {
return errorMsg;
}
String sortedArgs = Arrays.stream(errorMsg.substring(contentStart, argsEnd).split(", ", -1))
.sorted()
.collect(Collectors.joining(", "));
Comment on lines +68 to +70

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For error messages with zero or one connection arguments, there is no need to split, sort, and rejoin the arguments. We can optimize this by checking if the arguments substring contains the delimiter , before performing the stream operations. This avoids unnecessary object allocations and stream overhead for the common cases of single or empty arguments.

    String argsSubstring = errorMsg.substring(contentStart, argsEnd);
    if (!argsSubstring.contains(", ")) {
      return errorMsg;
    }
    String sortedArgs = Arrays.stream(argsSubstring.split(", ", -1))
      .sorted()
      .collect(Collectors.joining(", "));

return errorMsg.substring(0, contentStart) + sortedArgs + errorMsg.substring(argsEnd);
}
}
2 changes: 1 addition & 1 deletion databricks-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Databricks plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion db2-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>IBM DB2 plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion generic-database-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Generic database plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion generic-db-argument-setter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Generic database argument setter plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion mariadb-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Maria DB plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion memsql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Memsql plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion mssql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Microsoft SQL Server plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion mysql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Mysql plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion netezza-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Netezza plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion oracle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>Oracle plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>io.cdap.plugin</groupId>
<artifactId>database-plugins-parent</artifactId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Database Plugins</name>
<description>Collection of database plugins</description>
Expand Down
2 changes: 1 addition & 1 deletion postgresql-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>PostgreSQL plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion saphana-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<name>SAP HANA plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion teradata-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>database-plugins-parent</artifactId>
<groupId>io.cdap.plugin</groupId>
<version>1.12.6</version>
<version>1.12.7-SNAPSHOT</version>
</parent>

<artifactId>teradata-plugin</artifactId>
Expand Down
Loading