Skip to content

Commit

Permalink
test(mssql-cdc): enrich test cases (#17966)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeXiangWang authored Aug 8, 2024
1 parent 38927e8 commit fbe1a04
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 8 deletions.
122 changes: 114 additions & 8 deletions e2e_test/source/cdc_inline/sql_server_cdc/sql_server_cdc.slt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,50 @@ system ok
sqlcmd -C -i e2e_test/source/cdc_inline/sql_server_cdc/sql_server_cdc_prepare.sql -b

# ------------ validate stage ------------
# TODO(kexiang): add more tests here

# invalid address, comment this test out because it takes long to wait for TCP connection timeout.
# statement error The TCP/IP connection to the host wrong-sqlserver-server, port 1433 has failed.
# CREATE SOURCE mssql_source WITH (
# connector = 'sqlserver-cdc',
# hostname = 'wrong-sqlserver-server',
# port = '${SQLCMDPORT:1433}',
# username = '${SQLCMDUSER:SA}',
# password = '${SQLCMDPASSWORD}',
# database.name = '${SQLCMDDBNAME}',
# );

# invalid username
statement error Login failed for user 'SAP'
CREATE SOURCE mssql_source WITH (
connector = 'sqlserver-cdc',
hostname = '${SQLCMDSERVER:sqlserver-server}',
port = '${SQLCMDPORT:1433}',
username = 'SAP',
password = '${SQLCMDPASSWORD}',
database.name = '${SQLCMDDBNAME}',
);

# invalid password
# invalid table name
# invalid primary key
# column name mismatch
# column data type mismatch
# format & encode provided and match with debezium json, this is okay
# format & encode provided but mismatch with debezium json, this is not allowed
statement error Login failed for user
CREATE SOURCE mssql_source WITH (
connector = 'sqlserver-cdc',
hostname = '${SQLCMDSERVER:sqlserver-server}',
port = '${SQLCMDPORT:1433}',
username = '${SQLCMDUSER:SA}',
password = 'MyPassword123',
database.name = '${SQLCMDDBNAME}',
);

# invalid database
statement error Cannot open database "wrong_mydb" requested by the login. The login failed.
CREATE SOURCE mssql_source WITH (
connector = 'sqlserver-cdc',
hostname = '${SQLCMDSERVER:sqlserver-server}',
port = '${SQLCMDPORT:1433}',
username = '${SQLCMDUSER:SA}',
password = '${SQLCMDPASSWORD}',
database.name = 'wrong_mydb',
);

statement error Protocol error: connector sqlserver-cdc does not support `CREATE TABLE`, please use `CREATE SOURCE` instead
CREATE TABLE orders (
Expand Down Expand Up @@ -79,7 +114,6 @@ CREATE TABLE sqlserver_all_data_types (
database.name = '${SQLCMDDBNAME}',
);


# ------------ Create source/table/mv stage ------------
# create a cdc source job, which format fixed to `FORMAT PLAIN ENCODE JSON`
statement ok
Expand All @@ -106,6 +140,78 @@ CREATE TABLE shared_orders (
PRIMARY KEY (order_id)
) from mssql_source table 'orders';

# invalid table name
statement error Sql Server table 'dbo'.'wrong_orders' doesn't exist
CREATE TABLE shared_orders (
order_id INT,
order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'dbo.wrong_orders';

# invalid schema name
statement error Sql Server table 'wrong_dbo'.'orders' doesn't exist
CREATE TABLE shared_orders (
order_id INT,
order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'wrong_dbo.orders';

# invalid primary key
statement error INVALID_ARGUMENT: Primary key mismatch
CREATE TABLE shared_orders (
order_id INT,
order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_date)
) from mssql_source table 'dbo.orders';

# column name mismatch
statement error INVALID_ARGUMENT: Column 'wrong_order_date' not found in the upstream database
CREATE TABLE shared_orders (
order_id INT,
wrong_order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'dbo.orders';

# column data type mismatch
statement error INVALID_ARGUMENT: Incompatible data type of column order_date
CREATE TABLE shared_orders (
order_id INT,
order_date VARCHAR,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'dbo.orders';

# table without enabling cdc
statement error INVALID_ARGUMENT: Table 'dbo.orders_without_cdc' has not enabled CDC.
CREATE TABLE shared_orders_without_cdc (
order_id INT,
order_date BIGINT,
customer_name VARCHAR,
price DECIMAL,
product_id INT,
order_status SMALLINT,
PRIMARY KEY (order_id)
) from mssql_source table 'dbo.orders_without_cdc';

statement ok
CREATE TABLE shared_orders (
order_id INT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ INSERT INTO sqlserver_all_data_types VALUES (1, 'False', 0, 0, 0, 0, 0, 0, 0, ''
INSERT INTO sqlserver_all_data_types VALUES (2, 'True', 255, -32768, -2147483648, -9223372036854775808, -10.0, -9999.999999, -10000.0, 'aa', 0xff, '1990-01-01', '13:59:59.123', '2000-01-01 11:00:00.123', '1990-01-01 00:00:01.123');

INSERT INTO sqlserver_all_data_types VALUES (3, 'True', 127, 32767, 2147483647, 9223372036854775807, -10.0, 9999.999999, 10000.0, 'zzzz', 0xffffffff, '2999-12-31', '23:59:59.999', '2099-12-31 23:59:59.999', '2999-12-31 23:59:59.999')

-- Table without enabling CDC
CREATE TABLE orders_without_cdc (
order_id INT PRIMARY KEY,
order_date BIGINT,
customer_name NVARCHAR(200),
price DECIMAL,
product_id INT,
order_status SMALLINT
);

0 comments on commit fbe1a04

Please sign in to comment.