Skip to content

Commit 13e3416

Browse files
committed
ci: clean up tests.
1 parent 6965d84 commit 13e3416

20 files changed

Lines changed: 119 additions & 143 deletions

databend-jdbc/pom.xml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,12 @@
9393
</dependency>
9494

9595
<!-- for testing -->
96-
9796
<dependency>
9897
<groupId>org.testng</groupId>
9998
<artifactId>testng</artifactId>
10099
<scope>test</scope>
101100
</dependency>
102-
<dependency>
103-
<groupId>org.assertj</groupId>
104-
<artifactId>assertj-core</artifactId>
105-
<scope>test</scope>
106-
</dependency>
107-
<dependency>
108-
<groupId>com.solidfire.code.gson</groupId>
109-
<artifactId>gson</artifactId>
110-
<version>2.6.2</version>
111-
</dependency>
112-
<dependency>
113-
<groupId>junit</groupId>
114-
<artifactId>junit</artifactId>
115-
<version>4.13.2</version>
116-
<scope>test</scope>
117-
</dependency>
118-
<dependency>
119-
<groupId>org.junit.jupiter</groupId>
120-
<artifactId>junit-jupiter</artifactId>
121-
<scope>test</scope>
122-
</dependency>
101+
123102
<dependency>
124103
<groupId>org.locationtech.jts</groupId>
125104
<artifactId>jts-core</artifactId>

databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import com.databend.jdbc.cloud.DatabendCopyParams;
66
import com.databend.jdbc.cloud.DatabendStage;
77
import com.databend.jdbc.parser.BatchInsertUtils;
8-
import com.solidfire.gson.Gson;
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
910
import lombok.NonNull;
1011
import org.joda.time.format.DateTimeFormat;
1112
import org.joda.time.format.DateTimeFormatter;
@@ -89,6 +90,8 @@ public class DatabendPreparedStatement extends DatabendStatement implements Prep
8990
private final String statementName;
9091
private int batchSize = 0;
9192

93+
private static final ObjectMapper objectMapper = new ObjectMapper();
94+
9295
DatabendPreparedStatement(DatabendConnection connection, Consumer<DatabendStatement> onClose, String statementName,
9396
String sql) {
9497
super(connection, onClose);
@@ -751,8 +754,11 @@ else if (x instanceof OffsetTime) {
751754
}
752755

753756
public static String convertToJsonString(Map<?, ?> map) {
754-
Gson gson = new Gson();
755-
return gson.toJson(map);
757+
try {
758+
return objectMapper.writeValueAsString(map);
759+
} catch (JsonProcessingException e) {
760+
throw new RuntimeException("Failed to convert map to JSON string", e);
761+
}
756762
}
757763

758764
public static String convertArrayToString(Array array) {

databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.databend.jdbc;
22

33
import com.google.common.collect.ImmutableMap;
4-
import org.junit.jupiter.api.Test;
4+
import org.testng.annotations.Test;
55

66
import java.util.Map;
77

88
import static com.databend.jdbc.StatementUtil.replaceParameterMarksWithValues;
9-
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.testng.Assert.assertEquals;
1010

1111
public class StatementUtilTest {
1212
@Test

databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.sql.Timestamp;
2020
import java.util.Properties;
2121

22-
import static org.junit.jupiter.api.Assertions.assertThrows;
23-
import static org.testng.AssertJUnit.assertEquals;
22+
import static org.testng.Assert.assertThrows;
23+
2424

2525
@Test(timeOut = 10000)
2626
public class TestBasicDriver {
@@ -57,9 +57,6 @@ public void testBasic()
5757
r.next();
5858
Assert.assertEquals(r.getInt(1), i);
5959
}
60-
connection.close();
61-
} finally {
62-
6360
}
6461
}
6562

@@ -73,6 +70,7 @@ public void testExecuteInvalidSql() {
7370
});
7471
}
7572

73+
@Test(groups = {"IT"})
7674
public void testSchema() {
7775
try (Connection connection = Utils.createConnection()) {
7876
PaginationOptions p = connection.unwrap(DatabendConnection.class).getPaginationOptions();
@@ -87,9 +85,8 @@ public void testSchema() {
8785
while (r.next()) {
8886
System.out.println(r.getString(1));
8987
}
90-
connection.close();
91-
} catch (SQLException throwables) {
92-
throwables.printStackTrace();
88+
} catch (SQLException throwable) {
89+
throwable.printStackTrace();
9390
}
9491
}
9592

@@ -221,7 +218,7 @@ public void testQueryUpdateCount()
221218
statement.execute("SELECT version()");
222219
ResultSet r = statement.getResultSet();
223220
r.next();
224-
assertEquals(-1, statement.getUpdateCount());
221+
Assert.assertEquals(-1, statement.getUpdateCount());
225222
}
226223
}
227224

@@ -281,9 +278,6 @@ public void testBasicWithDatabase()
281278
String columnType = r.getString("type_name");
282279
System.out.println(tableSchem + " " + tableName + " " + columnName + " " + dataType + " " + columnType);
283280
}
284-
connection.close();
285-
} finally {
286-
287281
}
288282
}
289283

@@ -304,15 +298,13 @@ public void testResultException() {
304298
try (Connection connection = Utils.createConnection()) {
305299
Statement statement = connection.createStatement();
306300
ResultSet r = statement.executeQuery("SELECT 1e189he 198h");
307-
308-
connection.close();
309301
} catch (SQLException e) {
310302
Assert.assertTrue(e.getMessage().contains("Query failed"));
311303
}
312304
}
313305

314306
@Test(groups = {"IT"})
315-
public void testSelectWithPreparement()
307+
public void testSelectWithPreparedStatement()
316308
throws SQLException {
317309
try (Connection connection = Utils.createConnection()) {
318310
connection.createStatement().execute("create or replace table test_basic_driver.table_time(t timestamp, d date, ts timestamp)");

databend-jdbc/src/test/java/com/databend/jdbc/TestCopyInto.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static org.testng.Assert.assertEquals;
1111

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

databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import java.sql.Statement;
1010
import java.util.Properties;
1111

12-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
13-
1412
@Test(timeOut = 10000)
1513
public class TestDatabendDriverUri {
1614
private static DatabendDriverUri createDriverUri(String url)
@@ -21,12 +19,15 @@ private static DatabendDriverUri createDriverUri(String url)
2119
}
2220

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

29-
@Test(groups = {"unit"})
30+
@Test(groups = {"UNIT"})
3031
public void testInvalidUri() {
3132
// missing jdbc: prefix
3233
assertInvalid("test", "Invalid JDBC URL: test");
@@ -38,15 +39,15 @@ public void testInvalidUri() {
3839

3940
}
4041

41-
@Test(groups = {"unit"})
42+
@Test(groups = {"UNIT"})
4243
public void testBasic() throws SQLException {
4344
DatabendDriverUri uri = DatabendDriverUri.create("jdbc:databend://http://localhost", null);
4445
Assert.assertEquals(uri.getUri().getScheme(), "http");
4546
Assert.assertEquals(uri.getUri().getHost(), "localhost");
4647
Assert.assertEquals(uri.getUri().getPort(), 8000);
4748
}
4849

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

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

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

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

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

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

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

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

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

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

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

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

124125
}
125126

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

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

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

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

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

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

153-
@Test(groups = {"unit"})
154+
@Test(groups = {"UNIT"})
154155
public void testUserDatabaseProp() throws SQLException {
155156
Properties props = new Properties();
156157
props.setProperty("database", "db3");
@@ -178,7 +179,7 @@ public void testUserDatabaseProp() throws SQLException {
178179
Assert.assertEquals("enable", uri.getSslmode().toString());
179180
}
180181

181-
@Test(groups = {"unit"})
182+
@Test(groups = {"UNIT"})
182183
public void testUserDatabasePropFull() throws SQLException {
183184
Properties props = new Properties();
184185
props.setProperty("database", "db3");
@@ -202,7 +203,7 @@ public void testUserDatabasePropFull() throws SQLException {
202203
Assert.assertEquals("", uri.binaryFormat().toString());
203204
}
204205

205-
@Test(groups = {"unit"})
206+
@Test(groups = {"UNIT"})
206207
public void testFull() throws SQLException {
207208
Properties props = new Properties();
208209
props.setProperty("database", "db3");
@@ -235,7 +236,7 @@ public void testFull() throws SQLException {
235236
Assert.assertEquals(false, uri.getStrNullAsNull());
236237
}
237238

238-
@Test
239+
@Test(groups = "IT")
239240
public void TestSetSchema() throws SQLException {
240241
DatabendConnection connection = (DatabendConnection) Utils.createConnection();
241242
try {
@@ -249,7 +250,7 @@ public void TestSetSchema() throws SQLException {
249250
connection.createStatement().execute("insert into test2 values (1)");
250251
}
251252

252-
@Test
253+
@Test(groups = "IT")
253254
public void TestSetSessionSettings() throws SQLException{
254255
Properties props = new Properties();
255256
// set session settings

databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendParameterMetaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void setUp()
2525
}
2626

2727

28-
@Test(groups = "integration")
28+
@Test(groups = "IT")
2929
public void testGetParameterMetaData() throws SQLException {
3030
try (Connection conn = Utils.createConnection();
3131
PreparedStatement emptyPs = conn.prepareStatement("select 1");

databend-jdbc/src/test/java/com/databend/jdbc/TestFileTransfer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testFileTransfer()
131131
}
132132
}
133133

134-
@Test(groups = {"Local"})
134+
@Test(groups = {"LOCAL"})
135135
public void testFileTransferThroughAPI() {
136136
String filePath = generateRandomCSV(100000);
137137
File f = new File(filePath);

databend-jdbc/src/test/java/com/databend/jdbc/TestHeartbeat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.databend.jdbc;
22

3-
import org.junit.Assert;
3+
import org.testng.Assert;
44
import org.testng.annotations.Test;
55

66
import java.sql.Connection;

0 commit comments

Comments
 (0)