Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ public void testLoad() {

Assertions.assertNotNull(props);
}


@Test
@DisplayName("Unit test to validate config.yml from github repo")
public void testLoadFromGithub() {
ConfigLoader loader = new ConfigLoader();
Properties props = loader.load("https://raw.githubusercontent.com/altinity/clickhouse-debezium-connector/main/config.yml");

Assertions.assertNotNull(props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.apache.log4j.BasicConfigurator;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand All @@ -20,16 +19,15 @@

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;

@Disabled

@Testcontainers
@DisplayName("Integration Test that validates auto create tables feature which creates tables when a CDC record(Insert) is received")
public class AutoCreateTableIT {
protected MySQLContainer mySqlContainer;
@DisplayName("Integration Test that validates auto create tables feature which creates tables when a CDC record(Insert) is received and when table name has spaces")
public class AutoCreateTableWithSpaceAndDashIT {
protected MySQLContainer mySqlContainer;
static ClickHouseContainer clickHouseContainer;

@BeforeEach
Expand Down Expand Up @@ -59,11 +57,10 @@ public void startContainers() throws InterruptedException {
}
@ParameterizedTest
@CsvSource({
"clickhouse/clickhouse-server:latest",
"clickhouse/clickhouse-server:22.3"
"clickhouse/clickhouse-server:latest"
})
@DisplayName("Test that validates auto create table when table name has dashes")
public void testAutoCreateTable(String clickHouseServerVersion) throws Exception {
public void testAutoCreateTable() throws Exception {

Thread.sleep(5000);

Expand All @@ -72,6 +69,22 @@ public void testAutoCreateTable(String clickHouseServerVersion) throws Exception

Thread.sleep(20000);

conn.prepareStatement("CREATE TABLE `test account` (\n" +
" account_id mediumint unsigned NOT NULL AUTO_INCREMENT,\n" +
" account_group_type_id smallint unsigned NOT NULL,\n" +
" jump_lglent_id mediumint unsigned NOT NULL,\n" +
" counterparty_id mediumint unsigned NOT NULL,\n" +
" alternate_lglent_id mediumint unsigned DEFAULT NULL,\n" +
" account varchar(32) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n" +
" status_id tinyint unsigned NOT NULL DEFAULT '1',\n" +
" valid_from date NOT NULL,\n" +
" valid_to date NOT NULL DEFAULT '9999-12-31',\n" +
" gates_from datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),\n" +
" gates_to datetime(6) NOT NULL DEFAULT '9999-12-31 23:59:59.000000',\n" +
" modify_user varchar(16) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL DEFAULT 'gates_dba',\n" +
" notes varchar(128) CHARACTER SET latin1 COLLATE latin1_general_cs DEFAULT NULL,\n" +
" PRIMARY KEY (account_id, gates_from, gates_to, valid_from, valid_to)\n" +
") ENGINE=InnoDB AUTO_INCREMENT=6849 DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs").execute();

AtomicReference<DebeziumChangeEventCapture> engine = new AtomicReference<>();
ExecutorService executorService = Executors.newFixedThreadPool(1);
Expand All @@ -87,6 +100,7 @@ public void testAutoCreateTable(String clickHouseServerVersion) throws Exception

Thread.sleep(30000);
conn.prepareStatement("insert into `new-table` values('test', 1, 2)").execute();
conn.prepareStatement("insert into `test account` values(1, 1, 1, 1, 1, 'test', 1, '2021-01-01', '2021-01-01', '2021-01-01 00:00:00', '2021-01-01 00:00:00', 'test', 'test')").execute();
conn.close();

Thread.sleep(10000);
Expand All @@ -96,6 +110,14 @@ public void testAutoCreateTable(String clickHouseServerVersion) throws Exception
ResultSet dateTimeResult = ITCommon.executeQueryWithResultSet("select count(*) from employees.`new-table`", writer.getConnection());
boolean resultReceived = false;

ResultSet testAccountResult = ITCommon.executeQueryWithResultSet("select count(*) from employees.`test account`", writer.getConnection());
int count = 0;
while(testAccountResult.next()) {
count = testAccountResult.getInt(1);
}
Assert.assertEquals(1, count);


while(dateTimeResult.next()) {
resultReceived = true;
Assert.assertEquals(1, dateTimeResult.getInt(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public void testAlterDatabaseRenameColumnDataTypeMapping() {
log.info("CLICKHOUSE QUERY" + clickHouseQuery);

Assert.assertTrue(clickHouseQuery != null && clickHouseQuery.length() != 0);
// Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(clickhouseExpectedQuery));
//Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(clickhouseExpectedQuery));
}

// Before, After
Expand Down Expand Up @@ -2299,4 +2299,30 @@ public void testReplicationHistoryEnabledDDLTranslation() {
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(expectedQuery));
}

@Test
public void testTableNameWithSpace() {
String sql = "CREATE TABLE `test account` (\n" +
" account_id mediumint unsigned NOT NULL AUTO_INCREMENT,\n" +
" account_group_type_id smallint unsigned NOT NULL,\n" +
" jump_lglent_id mediumint unsigned NOT NULL,\n" +
" counterparty_id mediumint unsigned NOT NULL,\n" +
" alternate_lglent_id mediumint unsigned DEFAULT NULL,\n" +
" account varchar(32) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n" +
" status_id tinyint unsigned NOT NULL DEFAULT '1',\n" +
" valid_from date NOT NULL,\n" +
" valid_to date NOT NULL DEFAULT '9999-12-31',\n" +
" gates_from datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),\n" +
" gates_to datetime(6) NOT NULL DEFAULT '9999-12-31 23:59:59.000000',\n" +
" modify_user varchar(16) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL DEFAULT 'gates_dba',\n" +
" notes varchar(128) CHARACTER SET latin1 COLLATE latin1_general_cs DEFAULT NULL,\n" +
" PRIMARY KEY (account_id, gates_from, gates_to, valid_from, valid_to)\n" +
") ENGINE=InnoDB AUTO_INCREMENT=6849 DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs";

StringBuffer clickHouseQuery = new StringBuffer();
mySQLDDLParserService.parseSql(sql, "employees", clickHouseQuery);

String expectedQuery = "CREATE TABLE employees.`test account`(account_id Int32 NOT NULL ,account_group_type_id Int32 NOT NULL ,jump_lglent_id Int32 NOT NULL ,counterparty_id Int32 NOT NULL ,alternate_lglent_id Nullable(Int32),account String NOT NULL ,status_id Int16 NOT NULL ,valid_from Date32 NOT NULL ,valid_to Date32 NOT NULL ,gates_from DateTime64(6, 0) NOT NULL ,gates_to DateTime64(6, 0) NOT NULL ,modify_user String NOT NULL ,notes Nullable(String),`_version` UInt64,`is_deleted` UInt8) Engine=ReplacingMergeTree(_version,is_deleted) ORDER BY (account_id,gates_from,gates_to,valid_from,valid_to)";
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase(expectedQuery));
}

}
Loading