Skip to content

Commit

Permalink
Changes to all integration tests to move the common logic of creating…
Browse files Browse the repository at this point in the history
… connecting to a separate function.
  • Loading branch information
subkanthi committed Jan 27, 2025
1 parent a5a2bb4 commit ec2d634
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,17 @@ static public BaseDbWriter getDBWriter(ClickHouseContainer clickHouseContainer)

return writer;
}

static public BaseDbWriter getDBWriter(ClickHouseContainer clickHouseContainer, String databaseName) {

String jdbcUrl = BaseDbWriter.getConnectionString(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
databaseName);
Connection connection = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME, clickHouseContainer.getUsername(),
clickHouseContainer.getPassword(), BaseDbWriter.SYSTEM_DB, new ClickHouseSinkConnectorConfig(new HashMap<>()));

BaseDbWriter writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
databaseName, clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, connection);

return writer;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.altinity.clickhouse.debezium.embedded.ddl.parser;

import com.altinity.clickhouse.debezium.embedded.ITCommon;
import com.altinity.clickhouse.debezium.embedded.cdc.DebeziumChangeEventCapture;
import com.altinity.clickhouse.debezium.embedded.config.SinkConnectorLightWeightConfig;
import com.altinity.clickhouse.debezium.embedded.parser.SourceRecordParserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.altinity.clickhouse.debezium.embedded.ddl.parser;

import com.altinity.clickhouse.debezium.embedded.ITCommon;
import com.altinity.clickhouse.debezium.embedded.cdc.DebeziumChangeEventCapture;
import com.altinity.clickhouse.debezium.embedded.parser.SourceRecordParserService;
import com.altinity.clickhouse.sink.connector.ClickHouseSinkConnectorConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.altinity.clickhouse.debezium.embedded.ddl.parser;

import com.altinity.clickhouse.debezium.embedded.ITCommon;
import com.altinity.clickhouse.debezium.embedded.cdc.DebeziumChangeEventCapture;
import com.altinity.clickhouse.debezium.embedded.parser.SourceRecordParserService;
import com.altinity.clickhouse.sink.connector.ClickHouseSinkConnectorConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ public void testCreateTable() throws Exception {
writer.getConnection().close();
//Thread.sleep(10000);

//String jdbcUrl = BaseDbWriter.getConnectionString(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(), "employees");
Connection connection = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME, clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), new ClickHouseSinkConnectorConfig(new HashMap<>()));

writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"employees", clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, connection);
writer = ITCommon.getDBWriter(clickHouseContainer);
// Validate temporal_types_DATE data.
ResultSet dateResult = writer.executeQueryWithResultSet("select * from temporal_types_DATE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ public void testCreateTable() throws Exception {
writer.getConnection().close();
Thread.sleep(10000);

Connection conn2 = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME,
clickHouseContainer.getUsername(), clickHouseContainer.getPassword(),
"employees", new ClickHouseSinkConnectorConfig(new HashMap<>()));

writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"employees", clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, conn2);
// Validate temporal_types_DATE data.
ResultSet dateResult = writer.executeQueryWithResultSet("select * from temporal_types_DATE");
boolean dateResultValueChecked = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public void testDDLIgnoreRegex() throws Exception {
Thread.sleep(10000);


String jdbcUrl = BaseDbWriter.getConnectionString(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(), "employees");
Connection conn = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME,clickHouseContainer.getUsername(),
clickHouseContainer.getPassword(), new ClickHouseSinkConnectorConfig(new HashMap<>()));


// Thread.sleep(5000);
// Run MySQL DDL to run analyze partition.
String analyzePartitionDDL = "alter table sales analyze partition p2022";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.altinity.clickhouse.debezium.embedded.ddl.parser;

import com.altinity.clickhouse.debezium.embedded.ITCommon;
import com.altinity.clickhouse.debezium.embedded.cdc.DebeziumChangeEventCapture;
import com.altinity.clickhouse.debezium.embedded.common.PropertiesHelper;
import com.altinity.clickhouse.debezium.embedded.config.ConfigLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.altinity.clickhouse.debezium.embedded.ddl.parser;

import com.altinity.clickhouse.debezium.embedded.ITCommon;
import com.altinity.clickhouse.debezium.embedded.cdc.DebeziumChangeEventCapture;
import com.altinity.clickhouse.debezium.embedded.common.PropertiesHelper;
import com.altinity.clickhouse.debezium.embedded.config.ConfigLoader;
Expand Down Expand Up @@ -94,24 +95,12 @@ public void testCreateTable() throws Exception {
conn.prepareStatement("INSERT INTO `temporal_types_DATETIME6` VALUES ('DATETIME(6)-INSERT','1000-01-01 00:00:00.000000','2022-09-29 01:50:56.123456','9999-12-31 23:59:59.999999',NULL)").execute();
//conn.prepareStatement("INSERT INTO `temporal_types_DATETIME` VALUES ('DATETIME-INSERT','1000-01-01 00:00:00','2022-09-29 01:47:46','9999-12-31 23:59:59',NULL);\n").execute();

String jdbcUrl = BaseDbWriter.getConnectionString(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"employees");
Connection chConn = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME,
clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), new ClickHouseSinkConnectorConfig(new HashMap<>()));

BaseDbWriter writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"employees", clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, chConn);

BaseDbWriter writer = ITCommon.getDBWriter(clickHouseContainer);

writer.getConnection().close();
Thread.sleep(10000);

Connection chConn2 = BaseDbWriter.createConnection(jdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME,
clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), new ClickHouseSinkConnectorConfig(new HashMap<>()));

writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"employees", clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, chConn2);

writer = ITCommon.getDBWriter(clickHouseContainer);
/**
* DATE TIME
* 1969-12-31 18:00:00.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ public void testMultipleDatabases() throws Exception {
// Create a test_db DBWriter instance.
// A new ClickHouseConnection with test_db database.
// Jdbc url with test_db database.
String testDb2JdbcUrl = BaseDbWriter.getConnectionString(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"test_db2");
Connection testDb2Conn = BaseDbWriter.createConnection(testDb2JdbcUrl, BaseDbWriter.DATABASE_CLIENT_NAME,
clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), new ClickHouseSinkConnectorConfig(new HashMap<>()));
BaseDbWriter testDb2Writer = new BaseDbWriter(clickHouseContainer.getHost(), clickHouseContainer.getFirstMappedPort(),
"test_db2", clickHouseContainer.getUsername(), clickHouseContainer.getPassword(), null, testDb2Conn);
BaseDbWriter testDb2Writer = ITCommon.getDBWriter(clickHouseContainer, "test_db2");

// Validate the columns in Clickhouse for test_db.test_table
Map<String, String> columnMap = testDb2Writer.getColumnsDataTypesForTable("test_table");
Expand Down

0 comments on commit ec2d634

Please sign in to comment.