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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:
curl -u databend:databend --request POST localhost:8000/v1/query --header 'Content-Type:application/json' --data-raw '{"sql":"select 1"}'

- name: Run Maven clean deploy with release profile
run: mvn test -DexcludedGroups=cluster,FLAKY
run: mvn test -DexcludedGroups=CLUSTER,FLAKY
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
23 changes: 1 addition & 22 deletions databend-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,12 @@
</dependency>

<!-- for testing -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.solidfire.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.databend.jdbc.cloud.DatabendCopyParams;
import com.databend.jdbc.cloud.DatabendStage;
import com.databend.jdbc.parser.BatchInsertUtils;
import com.solidfire.gson.Gson;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -89,6 +90,8 @@ public class DatabendPreparedStatement extends DatabendStatement implements Prep
private final String statementName;
private int batchSize = 0;

private static final ObjectMapper objectMapper = new ObjectMapper();

DatabendPreparedStatement(DatabendConnection connection, Consumer<DatabendStatement> onClose, String statementName,
String sql) {
super(connection, onClose);
Expand Down Expand Up @@ -751,8 +754,11 @@ else if (x instanceof OffsetTime) {
}

public static String convertToJsonString(Map<?, ?> map) {
Gson gson = new Gson();
return gson.toJson(map);
try {
return objectMapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to convert map to JSON string", e);
}
}

public static String convertArrayToString(Array array) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.databend.jdbc;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Test;
import org.testng.annotations.Test;

import java.util.Map;

import static com.databend.jdbc.StatementUtil.replaceParameterMarksWithValues;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testng.Assert.assertEquals;

public class StatementUtilTest {
@Test
Expand Down
22 changes: 7 additions & 15 deletions databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.sql.Timestamp;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.Assert.assertThrows;


@Test(timeOut = 10000)
public class TestBasicDriver {
Expand Down Expand Up @@ -57,9 +57,6 @@ public void testBasic()
r.next();
Assert.assertEquals(r.getInt(1), i);
}
connection.close();
} finally {

}
}

Expand All @@ -73,6 +70,7 @@ public void testExecuteInvalidSql() {
});
}

@Test(groups = {"IT"})
public void testSchema() {
try (Connection connection = Utils.createConnection()) {
PaginationOptions p = connection.unwrap(DatabendConnection.class).getPaginationOptions();
Expand All @@ -87,9 +85,8 @@ public void testSchema() {
while (r.next()) {
System.out.println(r.getString(1));
}
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
} catch (SQLException throwable) {
throwable.printStackTrace();
}
}

Expand Down Expand Up @@ -221,7 +218,7 @@ public void testQueryUpdateCount()
statement.execute("SELECT version()");
ResultSet r = statement.getResultSet();
r.next();
assertEquals(-1, statement.getUpdateCount());
Assert.assertEquals(-1, statement.getUpdateCount());
}
}

Expand Down Expand Up @@ -281,9 +278,6 @@ public void testBasicWithDatabase()
String columnType = r.getString("type_name");
System.out.println(tableSchem + " " + tableName + " " + columnName + " " + dataType + " " + columnType);
}
connection.close();
} finally {

}
}

Expand All @@ -304,15 +298,13 @@ public void testResultException() {
try (Connection connection = Utils.createConnection()) {
Statement statement = connection.createStatement();
ResultSet r = statement.executeQuery("SELECT 1e189he 198h");

connection.close();
} catch (SQLException e) {
Assert.assertTrue(e.getMessage().contains("Query failed"));
}
}

@Test(groups = {"IT"})
public void testSelectWithPreparement()
public void testSelectWithPreparedStatement()
throws SQLException {
try (Connection connection = Utils.createConnection()) {
connection.createStatement().execute("create or replace table test_basic_driver.table_time(t timestamp, d date, ts timestamp)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.testng.Assert.assertEquals;

public class TestCopyInto {
@Test(groups = {"Unit"})
@Test(groups = {"UNIT"})
public void TestParseSql() {
DatabendStage s = DatabendStage.builder().stageName("~").path("a/b/c").build();
List<String> files = new ArrayList<>();
Expand All @@ -19,6 +19,5 @@ public void TestParseSql() {
assertEquals(sql.trim(), "COPY INTO db1.tb1 FROM @~/a/b/c FILES = ('file.csv') FILE_FORMAT = ( type = 'CSV' )");
sql = DatabendConnection.getCopyIntoSql(null, DatabendCopyParams.builder().setDatabendStage(s).setDatabaseTableName("tb1").build());
assertEquals(sql.trim(), "COPY INTO tb1 FROM @~/a/b/c FILE_FORMAT = ( type = 'CSV' )");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.sql.Statement;
import java.util.Properties;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Test(timeOut = 10000)
public class TestDatabendDriverUri {
private static DatabendDriverUri createDriverUri(String url)
Expand All @@ -21,12 +19,15 @@ private static DatabendDriverUri createDriverUri(String url)
}

private static void assertInvalid(String url, String prefix) {
assertThatThrownBy(() -> createDriverUri(url))
.isInstanceOf(SQLException.class)
.hasMessageStartingWith(prefix);
SQLException exception = Assert.expectThrows(SQLException.class, () -> createDriverUri(url));
String msg = exception.getMessage();
Assert.assertTrue(
msg.startsWith(prefix),
"error message not start with " + prefix + ":" + msg
);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testInvalidUri() {
// missing jdbc: prefix
assertInvalid("test", "Invalid JDBC URL: test");
Expand All @@ -38,15 +39,15 @@ public void testInvalidUri() {

}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testBasic() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://http://localhost", null);
Assert.assertEquals(uri.getUri().getScheme(), "http");
Assert.assertEquals(uri.getUri().getHost(), "localhost");
Assert.assertEquals(uri.getUri().getPort(), 8000);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testMultiHost() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://localhost,localhost:9991,localhost:31919/d2?ssl=true", null);
Assert.assertEquals(uri.getNodes().getUris().size(), 3);
Expand All @@ -61,7 +62,7 @@ public void testMultiHost() throws SQLException {
Assert.assertEquals(uri.getNodes().getUris().get(2).getPort(), 31919);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testSameHost() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://u1:p1@localhost,localhost:9991,localhost/d2?ssl=false", null);
System.out.println(uri.getNodes().toString());
Expand All @@ -77,7 +78,7 @@ public void testSameHost() throws SQLException {
Assert.assertEquals(uri.getNodes().getUris().get(1).getPort(), 9991);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testDefaultSSL() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://localhost", null);

Expand All @@ -86,7 +87,7 @@ public void testDefaultSSL() throws SQLException {
Assert.assertEquals(uri.getUri().getPort(), 8000);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testSSLSetFalse() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://localhost?SSL=false", null);

Expand All @@ -95,7 +96,7 @@ public void testSSLSetFalse() throws SQLException {
Assert.assertEquals(uri.getUri().getPort(), 8000);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testSSLSetTrue() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://localhost?ssl=true", null);

Expand All @@ -104,7 +105,7 @@ public void testSSLSetTrue() throws SQLException {
Assert.assertEquals(uri.getUri().getPort(), 443);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testSSLCustomPort() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://localhost:33101", null);

Expand All @@ -113,7 +114,7 @@ public void testSSLCustomPort() throws SQLException {
Assert.assertEquals(uri.getUri().getPort(), 33101);
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testSSLCustomPort2() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://http://localhost:33101", null);

Expand All @@ -123,7 +124,7 @@ public void testSSLCustomPort2() throws SQLException {

}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testUser() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://u1@localhost:33101?password=p1", null);

Expand All @@ -132,7 +133,7 @@ public void testUser() throws SQLException {
Assert.assertEquals(uri.getDatabase(), "default");
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testUserDatabase() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://u1@localhost:33101/db1?password=p1", null);

Expand All @@ -141,7 +142,7 @@ public void testUserDatabase() throws SQLException {
Assert.assertEquals(uri.getDatabase(), "db1");
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testUserDatabasePath() throws SQLException {
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://u1@localhost:33101/db1?password=p1&database=db2", null);

Expand All @@ -150,7 +151,7 @@ public void testUserDatabasePath() throws SQLException {
Assert.assertEquals(uri.getDatabase(), "db2");
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testUserDatabaseProp() throws SQLException {
Properties props = new Properties();
props.setProperty("database", "db3");
Expand Down Expand Up @@ -178,7 +179,7 @@ public void testUserDatabaseProp() throws SQLException {
Assert.assertEquals("enable", uri.getSslmode().toString());
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testUserDatabasePropFull() throws SQLException {
Properties props = new Properties();
props.setProperty("database", "db3");
Expand All @@ -202,7 +203,7 @@ public void testUserDatabasePropFull() throws SQLException {
Assert.assertEquals("", uri.binaryFormat().toString());
}

@Test(groups = {"unit"})
@Test(groups = {"UNIT"})
public void testFull() throws SQLException {
Properties props = new Properties();
props.setProperty("database", "db3");
Expand Down Expand Up @@ -235,7 +236,7 @@ public void testFull() throws SQLException {
Assert.assertEquals(false, uri.getStrNullAsNull());
}

@Test
@Test(groups = "IT")
public void TestSetSchema() throws SQLException {
DatabendConnection connection = (DatabendConnection) Utils.createConnection();
try {
Expand All @@ -249,14 +250,14 @@ public void TestSetSchema() throws SQLException {
connection.createStatement().execute("insert into test2 values (1)");
}

@Test
public void TestSetSessionSettings() throws SQLException{
@Test(groups = "IT")
public void TestSetSessionSettings() throws SQLException {
Properties props = new Properties();
// set session settings
props.setProperty("session_settings", "key1=value1,key2=value2");
props.setProperty("user","databend");
props.setProperty("password","databend");
DatabendConnection connection = (DatabendConnection) Utils.createConnection("default",props);
props.setProperty("user", "databend");
props.setProperty("password", "databend");
DatabendConnection connection = (DatabendConnection) Utils.createConnection("default", props);
try {
Statement statement = connection.createStatement();
statement.execute("show settings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void setUp()
}


@Test(groups = "integration")
@Test(groups = "IT")
public void testGetParameterMetaData() throws SQLException {
try (Connection conn = Utils.createConnection();
PreparedStatement emptyPs = conn.prepareStatement("select 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testFileTransfer()
}
}

@Test(groups = {"Local"})
@Test(groups = {"LOCAL"})
public void testFileTransferThroughAPI() {
String filePath = generateRandomCSV(100000);
File f = new File(filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.databend.jdbc;

import org.junit.Assert;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.sql.Connection;
Expand Down
Loading
Loading