Skip to content

Commit

Permalink
ci: allow changing port via env in it tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Oct 20, 2024
1 parent 558c070 commit caca290
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

@Test(timeOut = 10000)
public class TestClientIT {
static String port = System.getenv("DATABEND_CONN_PORT") != null ? System.getenv("DATABEND_CONN_PORT") : "8000";

// please setup a local databend cluster before running this test, and create databend
private static final String DATABEND_HOST = "http://databend:databend@127.0.0.1:8000";
private static final String DATABEND_HOST = "http://databend:databend@127.0.0.1:" + port;
private static final String DATABASE = "default";

@Test(groups = {"it"})
Expand Down
55 changes: 19 additions & 36 deletions databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -25,27 +24,11 @@

@Test(timeOut = 10000)
public class TestBasicDriver {
private Connection createConnection()
throws SQLException {
String url = "jdbc:databend://localhost:8000";
return DriverManager.getConnection(url, "databend", "databend");
}

private Connection createConnection(String database) throws SQLException {
String url = "jdbc:databend://localhost:8000/" + database;
return DriverManager.getConnection(url, "databend", "databend");
}

private Connection createConnection(String database, Properties p) throws SQLException {
String url = "jdbc:databend://localhost:8000/" + database;
return DriverManager.getConnection(url, p);
}

@BeforeTest
public void setUp()
throws SQLException {
// create table
Connection c = createConnection();
Connection c = Utils.createConnection();
c.createStatement().execute("drop database if exists test_basic_driver");
c.createStatement().execute("drop database if exists test_basic_driver_2");
c.createStatement().execute("create database test_basic_driver");
Expand All @@ -61,7 +44,7 @@ public void setUp()
@Test(groups = {"IT"})
public void testBasic()
throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
PaginationOptions p = connection.unwrap(DatabendConnection.class).getPaginationOptions();
Assert.assertEquals(p.getWaitTimeSecs(), PaginationOptions.getDefaultWaitTimeSec());
Assert.assertEquals(p.getMaxRowsInBuffer(), PaginationOptions.getDefaultMaxRowsInBuffer());
Expand All @@ -83,15 +66,15 @@ public void testBasic()
@Test(groups = {"IT"})
public void testExecuteInvalidSql() {
assertThrows(SQLException.class, () -> {
try (Connection connection = createConnection();
try (Connection connection = Utils.createConnection();
Statement statement = connection.createStatement()) {
statement.execute("create tabl xxx (a int, b varchar)");
}
});
}

public void testSchema() {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
PaginationOptions p = connection.unwrap(DatabendConnection.class).getPaginationOptions();
Assert.assertEquals(p.getWaitTimeSecs(), PaginationOptions.getDefaultWaitTimeSec());
Assert.assertEquals(p.getMaxRowsInBuffer(), PaginationOptions.getDefaultMaxRowsInBuffer());
Expand Down Expand Up @@ -122,13 +105,13 @@ public void testCreateUserFunction() throws SQLException {
" return i+k;\n" +
"}\n" +
"$$;";
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute(s);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("select add_plus(1,2)");
ResultSet r = statement.getResultSet();
Expand All @@ -141,7 +124,7 @@ public void testCreateUserFunction() throws SQLException {

@Test
public void TestMergeinto() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("CREATE TABLE IF NOT EXISTS test_basic_driver.target_table (\n" +
" ID INT,\n" +
Expand Down Expand Up @@ -184,7 +167,7 @@ public void TestMergeinto() throws SQLException {

@Test
public void testWriteDouble() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("CREATE TABLE IF NOT EXISTS test_basic_driver.table_double (\n" +
" ID INT,\n" +
Expand Down Expand Up @@ -216,7 +199,7 @@ public void testWriteDouble() throws SQLException {

@Test
public void testDefaultSelectNullValue() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.executeQuery("SELECT a,b from test_basic_driver.table_with_null");
ResultSet r = statement.getResultSet();
Expand All @@ -231,7 +214,7 @@ public void testDefaultSelectNullValue() throws SQLException {
@Test(groups = {"IT"})
public void testQueryUpdateCount()
throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("SELECT version()");
ResultSet r = statement.getResultSet();
Expand All @@ -247,11 +230,11 @@ public void testBasicWithProperties() throws SQLException {
p.setProperty("wait_time_secs", "10");
p.setProperty("max_rows_in_buffer", "100");
p.setProperty("max_rows_per_page", "100");
p.setProperty("user", "databend");
p.setProperty("password", "databend");
p.setProperty("user", Utils.getUsername());
p.setProperty("password", Utils.getPassword());

//INFO databend_query::servers::http::v1::http_query_handlers: receive http query: HttpQueryRequest { session_id: None, session: Some(HttpSessionConf { database: Some("test_basic_driver"), keep_server_session_secs: None, settings: None }), sql: "SELECT 1", pagination: PaginationConf { wait_time_secs: 10, max_rows_in_buffer: 100, max_rows_per_page: 100 }, string_fields: true, stage_attachment: None }
try (Connection connection = createConnection("test_basic_driver", p)) {
try (Connection connection = Utils.createConnection("test_basic_driver", p)) {
PaginationOptions options = connection.unwrap(DatabendConnection.class).getPaginationOptions();
Assert.assertEquals(options.getWaitTimeSecs(), 10);
Assert.assertEquals(options.getMaxRowsInBuffer(), 100);
Expand All @@ -267,7 +250,7 @@ public void testBasicWithProperties() throws SQLException {
@Test
public void testPrepareStatementQuery() throws SQLException {
String sql = "SELECT number from numbers(100) where number = ? or number = ?";
Connection conn = createConnection("test_basic_driver");
Connection conn = Utils.createConnection("test_basic_driver");
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, 1);
statement.setInt(2, 2);
Expand All @@ -281,7 +264,7 @@ public void testPrepareStatementQuery() throws SQLException {
@Test(groups = {"IT"})
public void testBasicWithDatabase()
throws SQLException {
try (Connection connection = createConnection("test_basic_driver")) {
try (Connection connection = Utils.createConnection("test_basic_driver")) {
Statement statement = connection.createStatement();
statement.execute("SELECT i from table1");
ResultSet r = statement.getResultSet();
Expand All @@ -305,7 +288,7 @@ public void testBasicWithDatabase()
@Test(groups = {"IT"})
public void testUpdateSession()
throws SQLException {
try (Connection connection = createConnection("test_basic_driver")) {
try (Connection connection = Utils.createConnection("test_basic_driver")) {
connection.createStatement().execute("set max_threads=1");
connection.createStatement().execute("use test_basic_driver_2");
DatabendSession session = connection.unwrap(DatabendConnection.class).getSession();
Expand All @@ -316,7 +299,7 @@ public void testUpdateSession()

@Test(groups = {"IT"})
public void testResultException() {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
Statement statement = connection.createStatement();
ResultSet r = statement.executeQuery("SELECT 1e189he 198h");

Expand All @@ -329,7 +312,7 @@ public void testResultException() {
@Test(groups = {"IT"})
public void testSelectWithPreparement()
throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
connection.createStatement().execute("create or replace table test_basic_driver.table_time(t timestamp, d date, ts timestamp)");
connection.createStatement().execute("insert into test_basic_driver.table_time values('2021-01-01 00:00:00', '2021-01-01', '2021-01-01 00:00:00')");
PreparedStatement statement = connection.prepareStatement("SELECT * from test_basic_driver.table_time where t < ? and d < ? and ts < ?");
Expand All @@ -346,7 +329,7 @@ public void testSelectWithPreparement()
public void testSelectGeometry() throws SQLException, ParseException {
// skip due to failed cluster tests

try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
connection.createStatement().execute("set enable_geo_create_table=1");
connection.createStatement().execute("CREATE or replace table cities ( id INT, name VARCHAR NOT NULL, location GEOMETRY);");
connection.createStatement().execute("INSERT INTO cities (id, name, location) VALUES (1, 'New York', 'POINT (-73.935242 40.73061))');");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static void assertTableMetadata(ResultSet rs)
public void setUp()
throws SQLException {
// create table
Connection c = createConnection();
Connection c = Utils.createConnection();
c.createStatement().execute("drop table if exists test_column_meta");
c.createStatement().execute("drop table if exists decimal_test");
c.createStatement().execute("drop table if exists test_comment");
Expand All @@ -65,25 +65,19 @@ public void setUp()
// json data
}

private Connection createConnection()
throws SQLException {
String url = "jdbc:databend://localhost:8000";
return DriverManager.getConnection(url, "databend", "databend");
}

@Test(groups = {"IT"})
public void testGetUrl() throws SQLException {
try (Connection c = createConnection()) {
try (Connection c = Utils.createConnection()) {
DatabaseMetaData metaData = c.getMetaData();
String url = metaData.getURL();
Assert.assertEquals(url, "jdbc:databend://http://localhost:8000");
Assert.assertEquals(url, Utils.baseURL());
}
}

@Test(groups = {"IT"})
public void testGetDatabaseProductName()
throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
assertEquals(metaData.getDatabaseProductName(), "Databend");
}
Expand All @@ -92,7 +86,7 @@ public void testGetDatabaseProductName()
@Test(groups = {"IT"})
public void testGetDatabaseProductVersion()
throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
float majorVersion = (float) metaData.getDatabaseMajorVersion() / 10;
int minorVersion = metaData.getDatabaseMinorVersion();
Expand All @@ -104,15 +98,15 @@ public void testGetDatabaseProductVersion()
@Test(groups = {"IT"})
public void testGetUserName()
throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
Assert.assertTrue(metaData.getUserName().contains("databend"));
}
}

@Test(groups = {"IT"})
public void testGetTables() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getTables(null, null, null, null)) {
assertTableMetadata(rs);
Expand All @@ -122,7 +116,7 @@ public void testGetTables() throws Exception {

@Test(groups = {"IT"})
public void testGetSchemas() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getSchemas()) {
ResultSetMetaData metaData1 = rs.getMetaData();
Expand All @@ -137,7 +131,7 @@ public void testGetSchemas() throws Exception {

@Test(groups = {"IT"})
public void testGetColumns() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getColumns(null, null, null, null)) {
assertEquals(rs.getMetaData().getColumnCount(), 24);
Expand All @@ -147,7 +141,7 @@ public void testGetColumns() throws Exception {

@Test(groups = {"IT"})
public void testComment() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getColumns("default", "default", "test_comment", null)) {
while (rs.next()) {
Expand All @@ -164,7 +158,7 @@ public void testComment() throws SQLException {

@Test(groups = {"IT"})
public void testColumnsMeta() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
try (ResultSet rs = connection.getMetaData().getColumns("default", "default", "trino_sjh", null)) {
while (rs.next()) {
String tableCat = rs.getString("table_cat");
Expand Down Expand Up @@ -192,7 +186,7 @@ public void testColumnsMeta() throws Exception {

@Test(groups = {"IT"})
public void testGetColumnTypesBySelectEmpty() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
ResultSet rs = connection.createStatement().executeQuery("select * from test_column_meta where 1=2");
ResultSetMetaData metaData = rs.getMetaData();
assertEquals(metaData.getColumnCount(), 17);
Expand All @@ -204,7 +198,7 @@ public void testGetColumnTypesBySelectEmpty() throws Exception {

@Test(groups = {"IT"})
public void testGetColumnTypeWithDecimal() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
ResultSet rs = connection.createStatement().executeQuery("select * from decimal_test");
ResultSetMetaData metaData = rs.getMetaData();

Expand All @@ -221,7 +215,7 @@ public void testGetColumnTypeWithDecimal() throws Exception {

@Test(groups = {"IT"})
public void testGetObjectWithDecimal() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
connection.createStatement().execute("insert into decimal_test values(1.2)");
ResultSet rs = connection.createStatement().executeQuery("select * from decimal_test");
while (rs.next()) {
Expand All @@ -232,7 +226,7 @@ public void testGetObjectWithDecimal() throws Exception {

@Test(groups = {"IT"})
public void testGetPrimaryKeys() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = connection.getMetaData().getPrimaryKeys(null, null, null)) {
assertEquals(rs.getMetaData().getColumnCount(), 6);
Expand All @@ -242,7 +236,7 @@ public void testGetPrimaryKeys() throws Exception {

@Test(groups = {"IT"})
public void testTableTypes() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet rs = metaData.getTableTypes()) {
assertEquals(rs.getMetaData().getColumnCount(), 1);
Expand All @@ -260,7 +254,7 @@ public void testTableTypes() throws Exception {

@Test(groups = {"IT"})
public void testGetFunctions() throws Exception {
try (Connection connection = createConnection()) {
try (Connection connection = Utils.createConnection()) {
try (ResultSet rs = connection.getMetaData().getFunctions(null, null, "abs")) {
ResultSetMetaData metadata = rs.getMetaData();
assertEquals(metadata.getColumnCount(), 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

Expand Down Expand Up @@ -236,9 +235,7 @@ public void testFull() throws SQLException {

@Test
public void TestSetSchema() throws SQLException {
String url = "jdbc:databend://databend:databend@localhost:8000/";
Properties p = new Properties();
DatabendConnection connection = (DatabendConnection) DriverManager.getConnection(url, p);
DatabendConnection connection = (DatabendConnection) Utils.createConnection();
try {
connection.createStatement().execute("create or replace database test2");
connection.createStatement().execute("create or replace table test2.test2(id int)");
Expand Down
Loading

0 comments on commit caca290

Please sign in to comment.