DBZ-304 MySQL test conversion to dynamic database creation

This commit is contained in:
Jiri Pechanec 2017-07-14 09:22:12 +02:00 committed by Gunnar Morling
parent 7b9c29efe6
commit 1c5326e731
25 changed files with 1035 additions and 1029 deletions

1
debezium-connector-mysql/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
database.properties

View File

@ -13,606 +13,4 @@ GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'%';
-- ---------------------------------------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: emptydb -- DATABASE: emptydb
-- ---------------------------------------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE emptydb; CREATE DATABASE emptydb;
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: readbinlog_test
-- Database needs to be populated to break dependency between MetadataIT and MySqlConnectorIT.shouldValidateAcceptableConfiguration run order
-- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE readbinlog_test;
USE readbinlog_test;
CREATE TABLE person (
name VARCHAR(255) primary key,
birthdate DATE NULL,
age INTEGER NULL DEFAULT 10,
salary DECIMAL(5,2), bitStr BIT(18)
);
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
createdByDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
modifiedDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
CREATE TABLE purchased (
purchaser VARCHAR(255) NOT NULL,
productId INT NOT NULL,
purchaseDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(productId,purchaser)
);
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: connector_test
-- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE connector_test;
USE connector_test;
-- Create and populate our products using a single insert with many rows
CREATE TABLE products (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description VARCHAR(512),
weight FLOAT
);
ALTER TABLE products AUTO_INCREMENT = 101;
INSERT INTO products
VALUES (default,"scooter","Small 2-wheel scooter",3.14),
(default,"car battery","12V car battery",8.1),
(default,"12-pack drill bits","12-pack of drill bits with sizes ranging from #40 to #3",0.8),
(default,"hammer","12oz carpenter's hammer",0.75),
(default,"hammer","14oz carpenter's hammer",0.875),
(default,"hammer","16oz carpenter's hammer",1.0),
(default,"rocks","box of assorted rocks",5.3),
(default,"jacket","water resistent black wind breaker",0.1),
(default,"spare tire","24 inch spare tire",22.2);
-- Create and populate the products on hand using multiple inserts
CREATE TABLE products_on_hand (
product_id INTEGER NOT NULL PRIMARY KEY,
quantity INTEGER NOT NULL,
FOREIGN KEY (product_id) REFERENCES products(id)
);
INSERT INTO products_on_hand VALUES (101,3);
INSERT INTO products_on_hand VALUES (102,8);
INSERT INTO products_on_hand VALUES (103,18);
INSERT INTO products_on_hand VALUES (104,4);
INSERT INTO products_on_hand VALUES (105,5);
INSERT INTO products_on_hand VALUES (106,0);
INSERT INTO products_on_hand VALUES (107,44);
INSERT INTO products_on_hand VALUES (108,2);
INSERT INTO products_on_hand VALUES (109,5);
-- Create some customers ...
CREATE TABLE customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE KEY
) AUTO_INCREMENT=1001;
INSERT INTO customers
VALUES (default,"Sally","Thomas","sally.thomas@acme.com"),
(default,"George","Bailey","gbailey@foobar.com"),
(default,"Edward","Walker","ed@walker.com"),
(default,"Anne","Kretchmar","annek@noanswer.org");
-- Create some very simple orders
CREATE TABLE orders (
order_number INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_date DATE NOT NULL,
purchaser INTEGER NOT NULL,
quantity INTEGER NOT NULL,
product_id INTEGER NOT NULL,
FOREIGN KEY order_customer (purchaser) REFERENCES customers(id),
FOREIGN KEY ordered_product (product_id) REFERENCES products(id)
) AUTO_INCREMENT = 10001;
INSERT INTO orders
VALUES (default, '2016-01-16', 1001, 1, 102),
(default, '2016-01-17', 1002, 2, 105),
(default, '2016-02-18', 1004, 3, 109),
(default, '2016-02-19', 1002, 2, 106),
(default, '16-02-21', 1003, 1, 107);
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: connector_test_ro
-- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE connector_test_ro;
USE connector_test_ro;
-- Create and populate our products using a single insert with many rows
CREATE TABLE products (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description VARCHAR(512),
weight FLOAT
);
ALTER TABLE products AUTO_INCREMENT = 101;
INSERT INTO products
VALUES (default,"scooter","Small 2-wheel scooter",3.14),
(default,"car battery","12V car battery",8.1),
(default,"12-pack drill bits","12-pack of drill bits with sizes ranging from #40 to #3",0.8),
(default,"hammer","12oz carpenter's hammer",0.75),
(default,"hammer","14oz carpenter's hammer",0.875),
(default,"hammer","16oz carpenter's hammer",1.0),
(default,"rocks","box of assorted rocks",5.3),
(default,"jacket","water resistent black wind breaker",0.1),
(default,"spare tire","24 inch spare tire",22.2);
-- Create and populate the products on hand using multiple inserts
CREATE TABLE products_on_hand (
product_id INTEGER NOT NULL PRIMARY KEY,
quantity INTEGER NOT NULL,
FOREIGN KEY (product_id) REFERENCES products(id)
);
INSERT INTO products_on_hand VALUES (101,3);
INSERT INTO products_on_hand VALUES (102,8);
INSERT INTO products_on_hand VALUES (103,18);
INSERT INTO products_on_hand VALUES (104,4);
INSERT INTO products_on_hand VALUES (105,5);
INSERT INTO products_on_hand VALUES (106,0);
INSERT INTO products_on_hand VALUES (107,44);
INSERT INTO products_on_hand VALUES (108,2);
INSERT INTO products_on_hand VALUES (109,5);
-- Create some customers ...
CREATE TABLE customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE KEY
) AUTO_INCREMENT=1001;
INSERT INTO customers
VALUES (default,"Sally","Thomas","sally.thomas@acme.com"),
(default,"George","Bailey","gbailey@foobar.com"),
(default,"Edward","Walker","ed@walker.com"),
(default,"Anne","Kretchmar","annek@noanswer.org");
-- Create some very simple orders
CREATE TABLE orders (
order_number INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_date DATE NOT NULL,
purchaser INTEGER NOT NULL,
quantity INTEGER NOT NULL,
product_id INTEGER NOT NULL,
FOREIGN KEY order_customer (purchaser) REFERENCES customers(id),
FOREIGN KEY ordered_product (product_id) REFERENCES products(id)
) AUTO_INCREMENT = 10001;
INSERT INTO orders
VALUES (default, '2016-01-16', 1001, 1, 102),
(default, '2016-01-17', 1002, 2, 105),
(default, '2016-02-18', 1004, 3, 109),
(default, '2016-02-19', 1002, 2, 106),
(default, '2016-02-21', 1003, 1, 107);
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: regression_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
CREATE DATABASE regression_test;
USE regression_test;
-- DBZ-61 handle binary value recorded as hex string value
CREATE TABLE t1464075356413_testtable6 (
pk_column int auto_increment NOT NULL,
varbinary_col varbinary(20) NOT NULL,
PRIMARY KEY(pk_column)
);
INSERT INTO t1464075356413_testtable6 (pk_column, varbinary_col)
VALUES(default, 0x4D7953514C);
-- DBZ-84 Handle TINYINT
CREATE TABLE dbz84_integer_types_table (
-- The column lengths are used for display purposes, and do not affect the range of values
colTinyIntA tinyint NOT NULL DEFAULT 100,
colTinyIntB tinyint(1) NOT NULL DEFAULT 101,
colTinyIntC tinyint(2) UNSIGNED NOT NULL DEFAULT 102,
colTinyIntD tinyint(3) UNSIGNED NOT NULL DEFAULT 103,
colSmallIntA smallint NOT NULL DEFAULT 200,
colSmallIntB smallint(1) NOT NULL DEFAULT 201,
colSmallIntC smallint(2) NOT NULL DEFAULT 201,
colSmallIntD smallint(3) NOT NULL DEFAULT 201,
colMediumIntA mediumint NOT NULL DEFAULT 300,
colMediumIntB mediumint(1) NOT NULL DEFAULT 301,
colMediumIntC mediumint(2) NOT NULL DEFAULT 302,
colMediumIntD mediumint(3) NOT NULL DEFAULT 303,
colIntA int NOT NULL DEFAULT 400,
colIntB int(1) NOT NULL DEFAULT 401,
colIntC int(2) NOT NULL DEFAULT 402,
colIntD int(3) NOT NULL DEFAULT 403,
colBigIntA bigint NOT NULL DEFAULT 500,
colBigIntB bigint(1) NOT NULL DEFAULT 501,
colBigIntC bigint(2) NOT NULL DEFAULT 502,
colBigIntD bigint(3) NOT NULL DEFAULT 503
);
INSERT INTO dbz84_integer_types_table
VALUES(127,-128,128,255, default,201,202,203, default,301,302,303, default,401,402,403, default,501,502,503);
-- DBZ-85 handle fractional part of seconds
CREATE TABLE dbz_85_fractest (
c1 DATE,
c2 TIME(2),
c3 DATETIME(2),
c4 TIMESTAMP(2)
);
INSERT INTO dbz_85_fractest VALUES ('2014-09-08', '17:51:04.777', '2014-09-08 17:51:04.777', '2014-09-08 17:51:04.777');
-- DBZ-100 handle enum and set
CREATE TABLE dbz_100_enumsettest (
c1 ENUM('a','b','c'),
c2 SET('a','b','c')
);
INSERT INTO dbz_100_enumsettest VALUES ('a', 'a,b,c');
INSERT INTO dbz_100_enumsettest VALUES ('b', 'b,a');
INSERT INTO dbz_100_enumsettest VALUES ('c', 'a');
-- DBZ-102 handle character sets
-- Use session variables to dictate the character sets used by the client running these commands so
-- the literal value is interpretted correctly...
set character_set_client=utf8;
set character_set_connection=utf8;
CREATE TABLE dbz_102_charsettest (
id INT(11) NOT NULL AUTO_INCREMENT,
text VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2001 DEFAULT CHARSET=utf8;
INSERT INTO dbz_102_charsettest VALUES (default, "产品");
-- DBZ-114 handle zero-value dates
CREATE TABLE dbz_114_zerovaluetest (
c1 DATE,
c2 TIME(2),
c3 DATETIME(2),
c4 TIMESTAMP(2)
);
INSERT IGNORE INTO dbz_114_zerovaluetest VALUES ('0000-00-00', '00:00:00.000', '0000-00-00 00:00:00.000', '0000-00-00 00:00:00.000');
INSERT IGNORE INTO dbz_114_zerovaluetest VALUES ('0001-00-00', '00:01:00.000', '0001-00-00 00:00:00.000', '0001-00-00 00:00:00.000');
-- DBZ-123 handle bit values, including bit field literals
CREATE TABLE dbz_123_bitvaluetest (
c1 BIT,
c2 BIT(2),
c3 BIT(8) NOT NULL,
c4 BIT(64)
);
INSERT INTO dbz_123_bitvaluetest VALUES (1,2,64,23989979);
INSERT INTO dbz_123_bitvaluetest VALUES (b'1',b'10',b'01000000',b'1011011100000111011011011');
-- DBZ-104 handle create table like ...
CREATE TABLE dbz_104_customers LIKE connector_test.customers;
INSERT INTO dbz_104_customers SELECT * FROM connector_test.customers;
-- DBZ-147 handle decimal value
CREATE TABLE dbz_147_decimalvalues (
pk_column int auto_increment NOT NULL,
decimal_value decimal(7,2) NOT NULL,
PRIMARY KEY(pk_column)
);
INSERT INTO dbz_147_decimalvalues (pk_column, decimal_value)
VALUES(default, 12345.67);
-- DBZ-162 handle function declarations with newline characters
DELIMITER $$
CREATE FUNCTION fnDbz162( p_creditLimit DOUBLE ) RETURNS VARCHAR(10)
DETERMINISTIC
BEGIN
DECLARE lvl VARCHAR(10);
IF p_creditLimit > 50000 THEN
SET lvl = 'PLATINUM';
ELSEIF (p_creditLimit <= 50000 AND p_creditLimit >= 10000) THEN
SET lvl = 'GOLD';
ELSEIF p_creditLimit < 10000 THEN
SET lvl = 'SILVER';
END IF;
RETURN (lvl);
END;
$$
DELIMITER ;
-- DBZ-195 handle numeric values
CREATE TABLE dbz_195_numvalues (
id int auto_increment NOT NULL,
`search_version_read` int(11) NOT NULL DEFAULT '0', -- (11) is the display width
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4972 DEFAULT CHARSET=utf8;
INSERT INTO dbz_195_numvalues VALUES (default,0);
INSERT INTO dbz_195_numvalues VALUES (default,-2147483648);
INSERT INTO dbz_195_numvalues VALUES (default,2147483647);
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: json_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's JSON datatype.
CREATE DATABASE json_test;
USE json_test;
-- DBZ-126 handle JSON column types ...
CREATE TABLE dbz_126_jsontable (
id INT AUTO_INCREMENT NOT NULL,
json JSON,
expectedJdbcStr VARCHAR(256), -- value that we get back from JDBC
expectedBinlogStr VARCHAR(256), -- value we parse from the binlog
PRIMARY KEY(id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_126_jsontable VALUES (default,NULL,
NULL,
NULL);
INSERT INTO dbz_126_jsontable VALUES (default,'{"a": 2}',
'{"a": 2}',
'{"a":2}');
INSERT INTO dbz_126_jsontable VALUES (default,'[1, 2]',
'[1, 2]',
'[1,2]');
INSERT INTO dbz_126_jsontable VALUES (default,'{"key1": "value1", "key2": "value2"}',
'{"key1": "value1", "key2": "value2"}',
'{"key1":"value1","key2":"value2"}');
INSERT INTO dbz_126_jsontable VALUES (default,'["a", "b",1]',
'["a", "b",1]',
'["a","b",1]');
INSERT INTO dbz_126_jsontable VALUES (default,'{"k1": "v1", "k2": {"k21": "v21", "k22": "v22"}, "k3": ["a", "b", 1]}',
'{"k1": "v1", "k2": {"k21": "v21", "k22": "v22"}, "k3": ["a", "b", 1]}',
'{"k1":"v1","k2":{"k21":"v21","k22":"v22"},"k3":["a","b",1]}');
INSERT INTO dbz_126_jsontable VALUES (default,'{"a": "b", "c": "d", "ab": "abc", "bc": ["x", "y"]}',
'{"a": "b", "c": "d", "ab": "abc", "bc": ["x", "y"]}',
'{"a":"b","c":"d","ab":"abc","bc":["x","y"]}');
INSERT INTO dbz_126_jsontable VALUES (default,'["here", ["I", "am"], "!!!"]',
'["here", ["I", "am"], "!!!"]',
'["here",["I","am"],"!!!"]');
INSERT INTO dbz_126_jsontable VALUES (default,'"scalar string"',
'"scalar string"',
'"scalar string"');
INSERT INTO dbz_126_jsontable VALUES (default,'true',
'true',
'true');
INSERT INTO dbz_126_jsontable VALUES (default,'false',
'false',
'false');
INSERT INTO dbz_126_jsontable VALUES (default,'null',
'null',
'null');
INSERT INTO dbz_126_jsontable VALUES (default,'-1',
'-1',
'-1');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST(1 AS UNSIGNED) AS JSON),
'1',
'1');
INSERT INTO dbz_126_jsontable VALUES (default,'32767',
'32767',
'32767');
INSERT INTO dbz_126_jsontable VALUES (default,'32768',
'32768',
'32768');
INSERT INTO dbz_126_jsontable VALUES (default,'-32768',
'-32768',
'-32768');
INSERT INTO dbz_126_jsontable VALUES (default,'2147483647', -- INT32
'2147483647',
'2147483647');
INSERT INTO dbz_126_jsontable VALUES (default,'2147483648', -- INT64
'2147483648',
'2147483648');
INSERT INTO dbz_126_jsontable VALUES (default,'-2147483648', -- INT32
'-2147483648',
'-2147483648');
INSERT INTO dbz_126_jsontable VALUES (default,'-2147483649', -- INT64
'-2147483649',
'-2147483649');
INSERT INTO dbz_126_jsontable VALUES (default,'18446744073709551615', -- INT64
'18446744073709551615',
'18446744073709551615');
INSERT INTO dbz_126_jsontable VALUES (default,'18446744073709551616', -- BigInteger
'18446744073709551616',
'18446744073709551616');
INSERT INTO dbz_126_jsontable VALUES (default,'3.14',
'3.14',
'3.14');
INSERT INTO dbz_126_jsontable VALUES (default,'{}',
'{}',
'{}');
INSERT INTO dbz_126_jsontable VALUES (default,'[]',
'[]',
'[]');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25' AS DATETIME) AS JSON),
'"2015-01-15 23:24:25"',
'"2015-01-15 23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25.12' AS DATETIME(3)) AS JSON),
'"2015-01-15 23:24:25.12"',
'"2015-01-15 23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25.0237' AS DATETIME(3)) AS JSON),
'"2015-01-15 23:24:25.024"',
'"2015-01-15 23:24:25.024"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25' AS TIME) AS JSON),
'"23:24:25"',
'"23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25.12' AS TIME(3)) AS JSON),
'"23:24:25.12"',
'"23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25.0237' AS TIME(3)) AS JSON),
'"23:24:25.024"',
'"23:24:25.024"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15' AS DATE) AS JSON),
'"2015-01-15"',
'"2015-01-15"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25' AS JSON),
'"2015-01-15 23:24:25"',
'"2015-01-15 23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25.12' AS JSON),
'"2015-01-15 23:24:25.12"',
'"2015-01-15 23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25.0237' AS JSON),
'"2015-01-15 23:24:25.0237"',
'"2015-01-15 23:24:25.0237"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(UNIX_TIMESTAMP('2015-01-15 23:24:25') AS JSON),
'1421364265',
'1421364265');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(ST_GeomFromText('POINT(1 1)') AS JSON),
'{\"type\": \"Point\", \"coordinates\": [1.0, 1.0]}',
'{\"type\":\"Point\",\"coordinates\":[1.0,1.0]}');
INSERT INTO dbz_126_jsontable VALUES (default,CAST('[]' AS CHAR CHARACTER SET 'ascii'),
'[]',
'[]');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(x'cafe' AS JSON), -- BLOB as Base64
'"yv4="',
'"yv4="');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(x'cafebabe' AS JSON), -- BLOB as Base64
'"yv66vg=="',
'"yv66vg=="');
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: geometry_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's Geometries datatypes.
CREATE DATABASE geometry_test;
USE geometry_test;
-- DBZ-222 handle POINT column types ...
CREATE TABLE dbz_222_point (
id INT AUTO_INCREMENT NOT NULL,
point POINT DEFAULT NULL,
expected_x FLOAT,
expected_y FLOAT,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(1 1)'), 1.0, 1.0);
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(8.25554554 3.22124447)'), 8.25554554, 3.22124447);
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(0 0)'), 0.0, 0.0);
INSERT INTO dbz_222_point VALUES (default,NULL, 0.0, 0.0);
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: table_maintenance_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
CREATE DATABASE table_maintenance_test;
USE table_maintenance_test;
CREATE TABLE dbz_253_table_maintenance_test (
id INT AUTO_INCREMENT NOT NULL,
other int,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
ANALYZE TABLE dbz_253_table_maintenance_test;
OPTIMIZE TABLE dbz_253_table_maintenance_test;
REPAIR TABLE dbz_253_table_maintenance_test;
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: binary_column_test
-- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE binary_column_test;
USE binary_column_test;
CREATE TABLE dbz_254_binary_column_test (
id INT AUTO_INCREMENT NOT NULL,
file_uuid BINARY(16),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b7400','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b74ab','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b74','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(00));
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: unsigned_integer_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's Geometries datatypes.
CREATE DATABASE unsigned_integer_test;
USE unsigned_integer_test;
-- DBZ-228 handle unsigned TINYINT UNSIGNED
CREATE TABLE dbz_228_tinyint_unsigned (
id int auto_increment NOT NULL,
c1 TINYINT(3) UNSIGNED ZEROFILL NOT NULL,
c2 TINYINT(3) UNSIGNED NOT NULL,
c3 TINYINT(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 255, 255, 127);
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 155, 155, -100);
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 0, 0, -128);
-- DBZ-228 handle unsigned SMALLINT UNSIGNED
CREATE TABLE dbz_228_smallint_unsigned (
id int auto_increment NOT NULL,
c1 SMALLINT UNSIGNED ZEROFILL NOT NULL,
c2 SMALLINT UNSIGNED NOT NULL,
c3 SMALLINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 65535, 65535, 32767);
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 45535, 45535, -12767);
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 0, 0, -32768);
-- DBZ-228 handle unsigned MEDIUMINT UNSIGNED
CREATE TABLE dbz_228_mediumint_unsigned (
id int auto_increment NOT NULL,
c1 MEDIUMINT UNSIGNED ZEROFILL NOT NULL,
c2 MEDIUMINT UNSIGNED NOT NULL,
c3 MEDIUMINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 16777215, 16777215, 8388607);
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 10777215, 10777215, -6388607);
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 0, 0, -8388608);
-- DBZ-228 handle unsigned INT UNSIGNED
CREATE TABLE dbz_228_int_unsigned (
id int auto_increment NOT NULL,
c1 int(11) UNSIGNED ZEROFILL NOT NULL,
c2 int(11) UNSIGNED NOT NULL,
c3 int(11) NOT NULL,
c4 int(5) UNSIGNED ZEROFILL NOT NULL,
c5 int(5) UNSIGNED NOT NULL ,
c6 int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_int_unsigned VALUES (default, 4294967295, 4294967295, 2147483647, 4294967295, 4294967295, 2147483647);
INSERT INTO dbz_228_int_unsigned VALUES (default, 3294967295, 3294967295, -1147483647, 3294967295, 3294967295, -1147483647);
INSERT INTO dbz_228_int_unsigned VALUES (default, 0, 0, -2147483648, 0, 0, -2147483648);
-- DBZ-228 handle unsigned BIGINT UNSIGNED
CREATE TABLE dbz_228_bigint_unsigned (
id int auto_increment NOT NULL,
c1 BIGINT UNSIGNED ZEROFILL NOT NULL,
c2 BIGINT UNSIGNED NOT NULL,
c3 BIGINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 18446744073709551615, 18446744073709551615, 9223372036854775807);
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 14446744073709551615, 14446744073709551615, -1223372036854775807);
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 0, 0, -9223372036854775808);

View File

@ -22,14 +22,12 @@
import org.junit.Test; import org.junit.Test;
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.connector.mysql.MySqlConnectorConfig.SecureConnectionMode;
import io.debezium.data.Envelope; import io.debezium.data.Envelope;
import io.debezium.data.KeyValueStore; import io.debezium.data.KeyValueStore;
import io.debezium.data.KeyValueStore.Collection; import io.debezium.data.KeyValueStore.Collection;
import io.debezium.data.SchemaChangeHistory; import io.debezium.data.SchemaChangeHistory;
import io.debezium.data.VerifyRecord; import io.debezium.data.VerifyRecord;
import io.debezium.doc.FixFor; import io.debezium.doc.FixFor;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.time.ZonedTimestamp; import io.debezium.time.ZonedTimestamp;
import io.debezium.util.Testing; import io.debezium.util.Testing;
@ -40,8 +38,8 @@
public class BinlogReaderIT { public class BinlogReaderIT {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-binlog.txt").toAbsolutePath(); private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-binlog.txt").toAbsolutePath();
private static final String DB_NAME = "connector_test_ro"; private final UniqueDatabase DATABASE = new UniqueDatabase("logical_server_name", "connector_test_ro")
private static final String LOGICAL_NAME = "logical_server_name"; .withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
private MySqlTaskContext context; private MySqlTaskContext context;
@ -52,8 +50,9 @@ public class BinlogReaderIT {
@Before @Before
public void beforeEach() { public void beforeEach() {
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
this.store = KeyValueStore.createForTopicsBeginningWith(LOGICAL_NAME + "."); DATABASE.createAndInitialize();
this.schemaChanges = new SchemaChangeHistory(LOGICAL_NAME); this.store = KeyValueStore.createForTopicsBeginningWith(DATABASE.getServerName() + ".");
this.schemaChanges = new SchemaChangeHistory(DATABASE.getServerName());
} }
@After @After
@ -98,23 +97,10 @@ protected int consumeAtLeast(int minNumber, long timeout, TimeUnit unit) throws
} }
protected Configuration.Builder simpleConfig() { protected Configuration.Builder simpleConfig() {
String hostname = System.getProperty("database.hostname"); return DATABASE.defaultConfig()
String port = System.getProperty("database.port");
assertThat(hostname).isNotNull();
assertThat(port).isNotNull();
return Configuration.create()
.with(MySqlConnectorConfig.HOSTNAME, hostname)
.with(MySqlConnectorConfig.PORT, port)
.with(MySqlConnectorConfig.USER, "replicator") .with(MySqlConnectorConfig.USER, "replicator")
.with(MySqlConnectorConfig.PASSWORD, "replpass") .with(MySqlConnectorConfig.PASSWORD, "replpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false);
.with(MySqlConnectorConfig.SERVER_ID, 18911)
.with(MySqlConnectorConfig.SERVER_NAME, LOGICAL_NAME)
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, DB_NAME)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH);
} }
@Test @Test
@ -140,7 +126,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
// Check the records via the store ... // Check the records via the store ...
assertThat(store.collectionCount()).isEqualTo(4); assertThat(store.collectionCount()).isEqualTo(4);
Collection products = store.collection(DB_NAME, "products"); Collection products = store.collection(DATABASE.getDatabaseName(), "products");
assertThat(products.numberOfCreates()).isEqualTo(9); assertThat(products.numberOfCreates()).isEqualTo(9);
assertThat(products.numberOfUpdates()).isEqualTo(0); assertThat(products.numberOfUpdates()).isEqualTo(0);
assertThat(products.numberOfDeletes()).isEqualTo(0); assertThat(products.numberOfDeletes()).isEqualTo(0);
@ -149,7 +135,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1);
Collection products_on_hand = store.collection(DB_NAME, "products_on_hand"); Collection products_on_hand = store.collection(DATABASE.getDatabaseName(), "products_on_hand");
assertThat(products_on_hand.numberOfCreates()).isEqualTo(9); assertThat(products_on_hand.numberOfCreates()).isEqualTo(9);
assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0); assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0);
assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0); assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0);
@ -158,7 +144,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1);
Collection customers = store.collection(DB_NAME, "customers"); Collection customers = store.collection(DATABASE.getDatabaseName(), "customers");
assertThat(customers.numberOfCreates()).isEqualTo(4); assertThat(customers.numberOfCreates()).isEqualTo(4);
assertThat(customers.numberOfUpdates()).isEqualTo(0); assertThat(customers.numberOfUpdates()).isEqualTo(0);
assertThat(customers.numberOfDeletes()).isEqualTo(0); assertThat(customers.numberOfDeletes()).isEqualTo(0);
@ -167,7 +153,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1);
Collection orders = store.collection(DB_NAME, "orders"); Collection orders = store.collection(DATABASE.getDatabaseName(), "orders");
assertThat(orders.numberOfCreates()).isEqualTo(5); assertThat(orders.numberOfCreates()).isEqualTo(5);
assertThat(orders.numberOfUpdates()).isEqualTo(0); assertThat(orders.numberOfUpdates()).isEqualTo(0);
assertThat(orders.numberOfDeletes()).isEqualTo(0); assertThat(orders.numberOfDeletes()).isEqualTo(0);
@ -202,7 +188,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
// Check the records via the store ... // Check the records via the store ...
assertThat(store.collectionCount()).isEqualTo(4); assertThat(store.collectionCount()).isEqualTo(4);
Collection products = store.collection(DB_NAME, "products"); Collection products = store.collection(DATABASE.getDatabaseName(), "products");
assertThat(products.numberOfCreates()).isEqualTo(9); assertThat(products.numberOfCreates()).isEqualTo(9);
assertThat(products.numberOfUpdates()).isEqualTo(0); assertThat(products.numberOfUpdates()).isEqualTo(0);
assertThat(products.numberOfDeletes()).isEqualTo(0); assertThat(products.numberOfDeletes()).isEqualTo(0);
@ -211,7 +197,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1);
Collection products_on_hand = store.collection(DB_NAME, "products_on_hand"); Collection products_on_hand = store.collection(DATABASE.getDatabaseName(), "products_on_hand");
assertThat(products_on_hand.numberOfCreates()).isEqualTo(9); assertThat(products_on_hand.numberOfCreates()).isEqualTo(9);
assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0); assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0);
assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0); assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0);
@ -220,7 +206,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1);
Collection customers = store.collection(DB_NAME, "customers"); Collection customers = store.collection(DATABASE.getDatabaseName(), "customers");
assertThat(customers.numberOfCreates()).isEqualTo(4); assertThat(customers.numberOfCreates()).isEqualTo(4);
assertThat(customers.numberOfUpdates()).isEqualTo(0); assertThat(customers.numberOfUpdates()).isEqualTo(0);
assertThat(customers.numberOfDeletes()).isEqualTo(0); assertThat(customers.numberOfDeletes()).isEqualTo(0);
@ -229,7 +215,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1);
Collection orders = store.collection(DB_NAME, "orders"); Collection orders = store.collection(DATABASE.getDatabaseName(), "orders");
assertThat(orders.numberOfCreates()).isEqualTo(5); assertThat(orders.numberOfCreates()).isEqualTo(5);
assertThat(orders.numberOfUpdates()).isEqualTo(0); assertThat(orders.numberOfUpdates()).isEqualTo(0);
assertThat(orders.numberOfDeletes()).isEqualTo(0); assertThat(orders.numberOfDeletes()).isEqualTo(0);
@ -242,11 +228,14 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
@Test @Test
@FixFor( "DBZ-183" ) @FixFor( "DBZ-183" )
public void shouldHandleTimestampTimezones() throws Exception { public void shouldHandleTimestampTimezones() throws Exception {
String dbName = "regression_test"; final UniqueDatabase REGRESSION_DATABASE = new UniqueDatabase("logical_server_name", "regression_test")
.withDbHistoryPath(DB_HISTORY_PATH);
REGRESSION_DATABASE.createAndInitialize();
String tableName = "dbz_85_fractest"; String tableName = "dbz_85_fractest";
config = simpleConfig().with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false) config = simpleConfig().with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, dbName) .with(MySqlConnectorConfig.DATABASE_WHITELIST, REGRESSION_DATABASE.getDatabaseName())
.with(MySqlConnectorConfig.TABLE_WHITELIST, dbName + "." + tableName) .with(MySqlConnectorConfig.TABLE_WHITELIST, REGRESSION_DATABASE.qualifiedTableName(tableName))
.build(); .build();
context = new MySqlTaskContext(config); context = new MySqlTaskContext(config);
context.start(); context.start();

View File

@ -25,7 +25,9 @@ public void shouldConnectToDefaulDatabase() throws SQLException {
@Test @Test
public void shouldDoStuffWithDatabase() throws SQLException { public void shouldDoStuffWithDatabase() throws SQLException {
try (MySQLConnection conn = MySQLConnection.forTestDatabase("readbinlog_test");) { final UniqueDatabase DATABASE = new UniqueDatabase("readbinlog", "readbinlog_test");
DATABASE.createAndInitialize();
try (MySQLConnection conn = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
conn.connect(); conn.connect();
// Set up the table as one transaction and wait to see the events ... // Set up the table as one transaction and wait to see the events ...
conn.execute("DROP TABLE IF EXISTS person", conn.execute("DROP TABLE IF EXISTS person",

View File

@ -26,7 +26,10 @@ public class MetadataIT implements Testing {
*/ */
@Test @Test
public void shouldLoadMetadataViaJdbc() throws SQLException { public void shouldLoadMetadataViaJdbc() throws SQLException {
try (MySQLConnection conn = MySQLConnection.forTestDatabase("readbinlog_test");) { final UniqueDatabase DATABASE = new UniqueDatabase("readbinlog_it", "readbinlog_test");
DATABASE.createAndInitialize();
try (MySQLConnection conn = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
conn.connect(); conn.connect();
// Set up the table as one transaction and wait to see the events ... // Set up the table as one transaction and wait to see the events ...
conn.execute("DROP TABLE IF EXISTS person", conn.execute("DROP TABLE IF EXISTS person",
@ -42,10 +45,10 @@ public void shouldLoadMetadataViaJdbc() throws SQLException {
+ ")"); + ")");
conn.execute("SELECT * FROM person"); conn.execute("SELECT * FROM person");
Tables tables = new Tables(); Tables tables = new Tables();
conn.readSchema(tables, "readbinlog_test", null, null, null, true); conn.readSchema(tables, DATABASE.getDatabaseName(), null, null, null, true);
//System.out.println(tables); //System.out.println(tables);
assertThat(tables.size()).isEqualTo(1); assertThat(tables.size()).isEqualTo(1);
Table person = tables.forTable("readbinlog_test", null, "person"); Table person = tables.forTable(DATABASE.getDatabaseName(), null, "person");
assertThat(person).isNotNull(); assertThat(person).isNotNull();
assertThat(person.filterColumns(col->col.isAutoIncremented())).isEmpty(); assertThat(person.filterColumns(col->col.isAutoIncremented())).isEmpty();
assertThat(person.primaryKeyColumnNames()).containsOnly("name"); assertThat(person.primaryKeyColumnNames()).containsOnly("name");
@ -104,10 +107,10 @@ public void shouldLoadMetadataViaJdbc() throws SQLException {
+ ")"); + ")");
conn.execute("SELECT * FROM product"); conn.execute("SELECT * FROM product");
tables = new Tables(); tables = new Tables();
conn.readSchema(tables, "readbinlog_test", null, null, null, true); conn.readSchema(tables, DATABASE.getDatabaseName(), null, null, null, true);
// System.out.println(tables); // System.out.println(tables);
assertThat(tables.size()).isEqualTo(2); assertThat(tables.size()).isEqualTo(2);
Table product = tables.forTable("readbinlog_test", null, "product"); Table product = tables.forTable(DATABASE.getDatabaseName(), null, "product");
assertThat(product).isNotNull(); assertThat(product).isNotNull();
assertThat(product.filterColumnNames(Column::isAutoIncremented)).containsOnly("id"); assertThat(product.filterColumnNames(Column::isAutoIncremented)).containsOnly("id");
assertThat(product.primaryKeyColumnNames()).containsOnly("id"); assertThat(product.primaryKeyColumnNames()).containsOnly("id");
@ -148,10 +151,10 @@ public void shouldLoadMetadataViaJdbc() throws SQLException {
+ ")"); + ")");
conn.execute("SELECT * FROM purchased"); conn.execute("SELECT * FROM purchased");
tables = new Tables(); tables = new Tables();
conn.readSchema(tables, "readbinlog_test", null, null, null, true); conn.readSchema(tables, DATABASE.getDatabaseName(), null, null, null, true);
//System.out.println(tables); //System.out.println(tables);
assertThat(tables.size()).isEqualTo(3); assertThat(tables.size()).isEqualTo(3);
Table purchased = tables.forTable("readbinlog_test", null, "purchased"); Table purchased = tables.forTable(DATABASE.getDatabaseName(), null, "purchased");
assertThat(purchased).isNotNull(); assertThat(purchased).isNotNull();
assertThat(person.filterColumns(col->col.isAutoIncremented())).isEmpty(); assertThat(person.filterColumns(col->col.isAutoIncremented())).isEmpty();
assertThat(purchased.primaryKeyColumnNames()).containsOnly("productId","purchaser"); assertThat(purchased.primaryKeyColumnNames()).containsOnly("productId","purchaser");

View File

@ -27,6 +27,7 @@ public static MySQLConnection forTestDatabase(String databaseName) {
return new MySQLConnection(JdbcConfiguration.copy(Configuration.fromSystemProperties("database.")) return new MySQLConnection(JdbcConfiguration.copy(Configuration.fromSystemProperties("database."))
.withDatabase(databaseName) .withDatabase(databaseName)
.with("useSSL", false) .with("useSSL", false)
.with("characterEncoding", "utf8")
.build()); .build());
} }

View File

@ -40,12 +40,18 @@
public class MySqlConnectorIT extends AbstractConnectorTest { public class MySqlConnectorIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-connect.txt").toAbsolutePath(); private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-connect.txt").toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("myServer1", "connector_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private final UniqueDatabase RO_DATABASE = new UniqueDatabase("myServer2", "connector_test_ro", DATABASE)
.withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
RO_DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -125,11 +131,7 @@ public void shouldFailToValidateInvalidConfiguration() {
@Test @Test
public void shouldValidateValidConfigurationWithSSL() { public void shouldValidateValidConfigurationWithSSL() {
Configuration config = Configuration.create() Configuration config = DATABASE.defaultJdbcConfigBuilder()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.REQUIRED) .with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.REQUIRED)
.with(MySqlConnectorConfig.SSL_KEYSTORE, "/some/path/to/keystore") .with(MySqlConnectorConfig.SSL_KEYSTORE, "/some/path/to/keystore")
.with(MySqlConnectorConfig.SSL_KEYSTORE_PASSWORD, "keystore1234") .with(MySqlConnectorConfig.SSL_KEYSTORE_PASSWORD, "keystore1234")
@ -182,11 +184,7 @@ public void shouldValidateValidConfigurationWithSSL() {
@Test @Test
public void shouldValidateAcceptableConfiguration() { public void shouldValidateAcceptableConfiguration() {
Configuration config = Configuration.create() Configuration config = DATABASE.defaultJdbcConfigBuilder()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED) .with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765) .with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "myServer") .with(MySqlConnectorConfig.SERVER_NAME, "myServer")
@ -233,8 +231,8 @@ public void shouldValidateAcceptableConfiguration() {
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException {
String masterPort = System.getProperty("database.port"); String masterPort = System.getProperty("database.port", "3306");
String replicaPort = System.getProperty("database.replica.port"); String replicaPort = System.getProperty("database.replica.port", "3306");
boolean replicaIsMaster = masterPort.equals(replicaPort); boolean replicaIsMaster = masterPort.equals(replicaPort);
if (!replicaIsMaster) { if (!replicaIsMaster) {
// Give time for the replica to catch up to the master ... // Give time for the replica to catch up to the master ...
@ -244,15 +242,15 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// Use the DB configuration to define the connector's configuration to use the "replica" // Use the DB configuration to define the connector's configuration to use the "replica"
// which may be the same as the "master" ... // which may be the same as the "master" ...
config = Configuration.create() config = Configuration.create()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.replica.hostname")) .with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.replica.hostname", "localhost"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.replica.port")) .with(MySqlConnectorConfig.PORT, System.getProperty("database.replica.port", "3306"))
.with(MySqlConnectorConfig.USER, "snapper") .with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass") .with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SERVER_ID, 18765) .with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "myServer") .with(MySqlConnectorConfig.SERVER_NAME, DATABASE.getServerName())
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED) .with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10) .with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "connector_test") .with(MySqlConnectorConfig.DATABASE_WHITELIST, DATABASE.getDatabaseName())
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class) .with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH) .with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
@ -267,17 +265,17 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// Consume all of the events due to startup and initialization of the database // Consume all of the events due to startup and initialization of the database
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
SourceRecords records = consumeRecordsByTopic(5 + 9 + 9 + 4 + 11 + 1); // 11 schema change records + 1 SET statement SourceRecords records = consumeRecordsByTopic(5 + 9 + 9 + 4 + 11 + 1); // 11 schema change records + 1 SET statement
assertThat(records.recordsForTopic("myServer").size()).isEqualTo(12); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(12);
assertThat(records.recordsForTopic("myServer.connector_test.products").size()).isEqualTo(9); assertThat(records.recordsForTopic(DATABASE.topicForTable("products")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer.connector_test.products_on_hand").size()).isEqualTo(9); assertThat(records.recordsForTopic(DATABASE.topicForTable("products_on_hand")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer.connector_test.customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("myServer.connector_test.orders").size()).isEqualTo(5); assertThat(records.recordsForTopic(DATABASE.topicForTable("orders")).size()).isEqualTo(5);
assertThat(records.topics().size()).isEqualTo(5); assertThat(records.topics().size()).isEqualTo(5);
assertThat(records.databaseNames().size()).isEqualTo(2); assertThat(records.databaseNames().size()).isEqualTo(2);
assertThat(records.ddlRecordsForDatabase("connector_test").size()).isEqualTo(11); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(11);
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1);
records.ddlRecordsForDatabase("connector_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -303,7 +301,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
stopConnector(); stopConnector();
// Make some changes to data only while the connector is stopped ... // Make some changes to data only while the connector is stopped ...
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.query("SELECT * FROM products", rs -> { connection.query("SELECT * FROM products", rs -> {
if (Testing.Print.isEnabled()) connection.print(rs); if (Testing.Print.isEnabled()) connection.print(rs);
@ -321,9 +319,9 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
Testing.print("*** Restarting connector after inserts were made"); Testing.print("*** Restarting connector after inserts were made");
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.recordsForTopic("myServer.connector_test.products").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("products")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
List<SourceRecord> inserts = records.recordsForTopic("myServer.connector_test.products"); List<SourceRecord> inserts = records.recordsForTopic(DATABASE.topicForTable("products"));
assertInsert(inserts.get(0), "id", 110); assertInsert(inserts.get(0), "id", 110);
Testing.print("*** Done with inserts and restart"); Testing.print("*** Done with inserts and restart");
@ -335,7 +333,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Simple INSERT // Simple INSERT
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("INSERT INTO products VALUES (1001,'roy','old robot',1234.56);"); connection.execute("INSERT INTO products VALUES (1001,'roy','old robot',1234.56);");
connection.query("SELECT * FROM products", rs -> { connection.query("SELECT * FROM products", rs -> {
@ -346,9 +344,9 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And consume the one insert ... // And consume the one insert ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.recordsForTopic("myServer.connector_test.products").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("products")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
inserts = records.recordsForTopic("myServer.connector_test.products"); inserts = records.recordsForTopic(DATABASE.topicForTable("products"));
assertInsert(inserts.get(0), "id", 1001); assertInsert(inserts.get(0), "id", 1001);
// Testing.print("*** Done with simple insert"); // Testing.print("*** Done with simple insert");
@ -356,7 +354,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Changing the primary key of a row should result in 3 events: INSERT, DELETE, and TOMBSTONE // Changing the primary key of a row should result in 3 events: INSERT, DELETE, and TOMBSTONE
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("UPDATE products SET id=2001, description='really old robot' WHERE id=1001"); connection.execute("UPDATE products SET id=2001, description='really old robot' WHERE id=1001");
connection.query("SELECT * FROM products", rs -> { connection.query("SELECT * FROM products", rs -> {
@ -366,7 +364,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
} }
// And consume the update of the PK, which is one insert followed by a delete followed by a tombstone ... // And consume the update of the PK, which is one insert followed by a delete followed by a tombstone ...
records = consumeRecordsByTopic(3); records = consumeRecordsByTopic(3);
List<SourceRecord> updates = records.recordsForTopic("myServer.connector_test.products"); List<SourceRecord> updates = records.recordsForTopic(DATABASE.topicForTable("products"));
assertThat(updates.size()).isEqualTo(3); assertThat(updates.size()).isEqualTo(3);
assertDelete(updates.get(0), "id", 1001); assertDelete(updates.get(0), "id", 1001);
assertTombstone(updates.get(1), "id", 1001); assertTombstone(updates.get(1), "id", 1001);
@ -377,7 +375,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Simple UPDATE (with no schema changes) // Simple UPDATE (with no schema changes)
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("UPDATE products SET weight=1345.67 WHERE id=2001"); connection.execute("UPDATE products SET weight=1345.67 WHERE id=2001");
connection.query("SELECT * FROM products", rs -> { connection.query("SELECT * FROM products", rs -> {
@ -389,7 +387,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And consume the one update ... // And consume the one update ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
updates = records.recordsForTopic("myServer.connector_test.products"); updates = records.recordsForTopic(DATABASE.topicForTable("products"));
assertThat(updates.size()).isEqualTo(1); assertThat(updates.size()).isEqualTo(1);
assertUpdate(updates.get(0), "id", 2001); assertUpdate(updates.get(0), "id", 2001);
updates.forEach(this::validate); updates.forEach(this::validate);
@ -402,9 +400,11 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// Change our schema with a fully-qualified name; we should still see this event // Change our schema with a fully-qualified name; we should still see this event
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Add a column with default to the 'products' table and explicitly update one record ... // Add a column with default to the 'products' table and explicitly update one record ...
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("ALTER TABLE connector_test.products ADD COLUMN volume FLOAT, ADD COLUMN alias VARCHAR(30) NULL AFTER description"); connection.execute(String.format(
"ALTER TABLE %s.products ADD COLUMN volume FLOAT, ADD COLUMN alias VARCHAR(30) NULL AFTER description",
DATABASE.getDatabaseName()));
connection.execute("UPDATE products SET volume=13.5 WHERE id=2001"); connection.execute("UPDATE products SET volume=13.5 WHERE id=2001");
connection.query("SELECT * FROM products", rs -> { connection.query("SELECT * FROM products", rs -> {
if (Testing.Print.isEnabled()) connection.print(rs); if (Testing.Print.isEnabled()) connection.print(rs);
@ -415,8 +415,8 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And consume the one schema change event and one update event ... // And consume the one schema change event and one update event ...
records = consumeRecordsByTopic(2); records = consumeRecordsByTopic(2);
assertThat(records.topics().size()).isEqualTo(2); assertThat(records.topics().size()).isEqualTo(2);
assertThat(records.recordsForTopic("myServer").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(1);
updates = records.recordsForTopic("myServer.connector_test.products"); updates = records.recordsForTopic(DATABASE.topicForTable("products"));
assertThat(updates.size()).isEqualTo(1); assertThat(updates.size()).isEqualTo(1);
assertUpdate(updates.get(0), "id", 2001); assertUpdate(updates.get(0), "id", 2001);
updates.forEach(this::validate); updates.forEach(this::validate);
@ -429,19 +429,19 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// Connect to a different database, but use the fully qualified name for a table in our database ... // Connect to a different database, but use the fully qualified name for a table in our database ...
try (MySQLConnection db = MySQLConnection.forTestDatabase("emptydb");) { try (MySQLConnection db = MySQLConnection.forTestDatabase("emptydb");) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("CREATE TABLE connector_test.stores (" connection.execute(String.format("CREATE TABLE %s.stores ("
+ " id INT(11) PRIMARY KEY NOT NULL AUTO_INCREMENT," + " id INT(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,"
+ " first_name VARCHAR(255) NOT NULL," + " first_name VARCHAR(255) NOT NULL,"
+ " last_name VARCHAR(255) NOT NULL," + " last_name VARCHAR(255) NOT NULL,"
+ " email VARCHAR(255) NOT NULL );"); + " email VARCHAR(255) NOT NULL );", DATABASE.getDatabaseName()));
} }
} }
// And consume the one schema change event only ... // And consume the one schema change event only ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
assertThat(records.recordsForTopic("myServer").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(1);
records.recordsForTopic("myServer").forEach(this::validate); records.recordsForTopic(DATABASE.getServerName()).forEach(this::validate);
Testing.print("*** Done with PK change (different db and fully-qualified name)"); Testing.print("*** Done with PK change (different db and fully-qualified name)");
@ -450,7 +450,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Do something completely different with a table we've not modified yet and then read that event. // Do something completely different with a table we've not modified yet and then read that event.
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.execute("UPDATE products_on_hand SET quantity=20 WHERE product_id=109"); connection.execute("UPDATE products_on_hand SET quantity=20 WHERE product_id=109");
connection.query("SELECT * FROM products_on_hand", rs -> { connection.query("SELECT * FROM products_on_hand", rs -> {
@ -462,7 +462,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And make sure we consume that one update ... // And make sure we consume that one update ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
updates = records.recordsForTopic("myServer.connector_test.products_on_hand"); updates = records.recordsForTopic(DATABASE.topicForTable("products_on_hand"));
assertThat(updates.size()).isEqualTo(1); assertThat(updates.size()).isEqualTo(1);
assertUpdate(updates.get(0), "product_id", 109); assertUpdate(updates.get(0), "product_id", 109);
updates.forEach(this::validate); updates.forEach(this::validate);
@ -492,7 +492,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
BinlogPosition positionBeforeInserts = new BinlogPosition(); BinlogPosition positionBeforeInserts = new BinlogPosition();
BinlogPosition positionAfterInserts = new BinlogPosition(); BinlogPosition positionAfterInserts = new BinlogPosition();
BinlogPosition positionAfterUpdate = new BinlogPosition(); BinlogPosition positionAfterUpdate = new BinlogPosition();
try (MySQLConnection db = MySQLConnection.forTestDatabase("connector_test");) { try (MySQLConnection db = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());) {
try (JdbcConnection connection = db.connect()) { try (JdbcConnection connection = db.connect()) {
connection.query("SHOW MASTER STATUS", positionBeforeInserts::readFromDatabase); connection.query("SHOW MASTER STATUS", positionBeforeInserts::readFromDatabase);
connection.execute("INSERT INTO products(id,name,description,weight,volume,alias) VALUES " connection.execute("INSERT INTO products(id,name,description,weight,volume,alias) VALUES "
@ -516,9 +516,9 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And consume the one insert ... // And consume the one insert ...
records = consumeRecordsByTopic(2); records = consumeRecordsByTopic(2);
assertThat(records.recordsForTopic("myServer.connector_test.products").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("products")).size()).isEqualTo(2);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
inserts = records.recordsForTopic("myServer.connector_test.products"); inserts = records.recordsForTopic(DATABASE.topicForTable("products"));
assertInsert(inserts.get(0), "id", 3001); assertInsert(inserts.get(0), "id", 3001);
assertInsert(inserts.get(1), "id", 3002); assertInsert(inserts.get(1), "id", 3002);
@ -565,9 +565,9 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And consume the insert for 3003 ... // And consume the insert for 3003 ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
inserts = records.recordsForTopic("myServer.connector_test.products"); inserts = records.recordsForTopic(DATABASE.topicForTable("products"));
if (inserts == null) { if (inserts == null) {
updates = records.recordsForTopic("myServer.connector_test.products_on_hand"); updates = records.recordsForTopic(DATABASE.topicForTable("products_on_hand"));
if (updates != null) { if (updates != null) {
fail("Restarted connector and missed the insert of product id=3003!"); fail("Restarted connector and missed the insert of product id=3003!");
} }
@ -594,7 +594,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
// And make sure we consume that one extra update ... // And make sure we consume that one extra update ...
records = consumeRecordsByTopic(1); records = consumeRecordsByTopic(1);
assertThat(records.topics().size()).isEqualTo(1); assertThat(records.topics().size()).isEqualTo(1);
updates = records.recordsForTopic("myServer.connector_test.products_on_hand"); updates = records.recordsForTopic(DATABASE.topicForTable("products_on_hand"));
assertThat(updates.size()).isEqualTo(1); assertThat(updates.size()).isEqualTo(1);
assertUpdate(updates.get(0), "product_id", 109); assertUpdate(updates.get(0), "product_id", 109);
updates.forEach(this::validate); updates.forEach(this::validate);
@ -647,20 +647,9 @@ public void shouldConsumeEventsWithNoSnapshot() throws SQLException, Interrupted
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = RO_DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18780)
.with(MySqlConnectorConfig.SERVER_NAME, "myServer1")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "connector_test_ro")
.with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER) .with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
@ -669,12 +658,12 @@ public void shouldConsumeEventsWithNoSnapshot() throws SQLException, Interrupted
// Consume the first records due to startup and initialization of the database ... // Consume the first records due to startup and initialization of the database ...
// Testing.Print.enable(); // Testing.Print.enable();
SourceRecords records = consumeRecordsByTopic(9 + 9 + 4 + 5 + 6); // 6 DDL changes SourceRecords records = consumeRecordsByTopic(9 + 9 + 4 + 5 + 6); // 6 DDL changes
assertThat(records.recordsForTopic("myServer1.connector_test_ro.products").size()).isEqualTo(9); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("products")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer1.connector_test_ro.products_on_hand").size()).isEqualTo(9); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("products_on_hand")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer1.connector_test_ro.customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("myServer1.connector_test_ro.orders").size()).isEqualTo(5); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("orders")).size()).isEqualTo(5);
assertThat(records.topics().size()).isEqualTo(4 + 1); assertThat(records.topics().size()).isEqualTo(4 + 1);
assertThat(records.ddlRecordsForDatabase("connector_test_ro").size()).isEqualTo(6); assertThat(records.ddlRecordsForDatabase(RO_DATABASE.getDatabaseName()).size()).isEqualTo(6);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -682,11 +671,11 @@ public void shouldConsumeEventsWithNoSnapshot() throws SQLException, Interrupted
// More records may have been written (if this method were run after the others), but we don't care ... // More records may have been written (if this method were run after the others), but we don't care ...
stopConnector(); stopConnector();
records.recordsForTopic("myServer1.connector_test_ro.orders").forEach(record -> { records.recordsForTopic(RO_DATABASE.topicForTable("orders")).forEach(record -> {
print(record); print(record);
}); });
records.recordsForTopic("myServer1.connector_test_ro.customers").forEach(record -> { records.recordsForTopic(RO_DATABASE.topicForTable("customers")).forEach(record -> {
print(record); print(record);
}); });
} }
@ -696,21 +685,10 @@ public void shouldConsumeEventsWithMaskedAndBlacklistedColumns() throws SQLExcep
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = RO_DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.COLUMN_BLACKLIST, RO_DATABASE.qualifiedTableName("orders") + ".order_number")
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port")) .with(MySqlConnectorConfig.MASK_COLUMN(12), RO_DATABASE.qualifiedTableName("customers") + ".email")
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18780)
.with(MySqlConnectorConfig.SERVER_NAME, "myServer2")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "connector_test_ro")
.with(MySqlConnectorConfig.COLUMN_BLACKLIST, "connector_test_ro.orders.order_number")
.with(MySqlConnectorConfig.MASK_COLUMN(12), "connector_test_ro.customers.email")
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
@ -719,10 +697,10 @@ public void shouldConsumeEventsWithMaskedAndBlacklistedColumns() throws SQLExcep
// Consume the first records due to startup and initialization of the database ... // Consume the first records due to startup and initialization of the database ...
// Testing.Print.enable(); // Testing.Print.enable();
SourceRecords records = consumeRecordsByTopic(9 + 9 + 4 + 5); SourceRecords records = consumeRecordsByTopic(9 + 9 + 4 + 5);
assertThat(records.recordsForTopic("myServer2.connector_test_ro.products").size()).isEqualTo(9); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("products")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer2.connector_test_ro.products_on_hand").size()).isEqualTo(9); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("products_on_hand")).size()).isEqualTo(9);
assertThat(records.recordsForTopic("myServer2.connector_test_ro.customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("myServer2.connector_test_ro.orders").size()).isEqualTo(5); assertThat(records.recordsForTopic(RO_DATABASE.topicForTable("orders")).size()).isEqualTo(5);
assertThat(records.topics().size()).isEqualTo(4); assertThat(records.topics().size()).isEqualTo(4);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
@ -732,7 +710,7 @@ public void shouldConsumeEventsWithMaskedAndBlacklistedColumns() throws SQLExcep
stopConnector(); stopConnector();
// Check that the orders.order_number is not present ... // Check that the orders.order_number is not present ...
records.recordsForTopic("myServer2.connector_test_ro.orders").forEach(record -> { records.recordsForTopic(RO_DATABASE.topicForTable("orders")).forEach(record -> {
print(record); print(record);
Struct value = (Struct) record.value(); Struct value = (Struct) record.value();
try { try {
@ -744,7 +722,7 @@ public void shouldConsumeEventsWithMaskedAndBlacklistedColumns() throws SQLExcep
}); });
// Check that the customer.email is masked ... // Check that the customer.email is masked ...
records.recordsForTopic("myServer2.connector_test_ro.customers").forEach(record -> { records.recordsForTopic(RO_DATABASE.topicForTable("customers")).forEach(record -> {
Struct value = (Struct) record.value(); Struct value = (Struct) record.value();
if (value.getStruct("after") != null) { if (value.getStruct("after") != null) {
assertThat(value.getStruct("after").getString("email")).isEqualTo("************"); assertThat(value.getStruct("after").getString("email")).isEqualTo("************");

View File

@ -20,12 +20,9 @@
import org.junit.Test; import org.junit.Test;
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.connector.mysql.MySqlConnectorConfig.SecureConnectionMode;
import io.debezium.connector.mysql.MySqlConnectorConfig.SnapshotMode;
import io.debezium.data.Envelope; import io.debezium.data.Envelope;
import io.debezium.doc.FixFor; import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
/** /**
@ -34,12 +31,15 @@
public class MySqlConnectorJsonIT extends AbstractConnectorTest { public class MySqlConnectorJsonIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-json.txt").toAbsolutePath(); private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-json.txt").toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("jsonit", "json_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -57,20 +57,9 @@ public void afterEach() {
@FixFor("DBZ-126") @FixFor("DBZ-126")
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port")) .build();
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "jsonit_binlog")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "json_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -84,15 +73,15 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("jsonit_binlog").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic("jsonit_binlog.json_test.dbz_126_jsontable").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_126_jsontable")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(1 + numCreateTables); assertThat(records.topics().size()).isEqualTo(1 + numCreateTables);
assertThat(records.databaseNames().size()).isEqualTo(1); assertThat(records.databaseNames().size()).isEqualTo(1);
assertThat(records.ddlRecordsForDatabase("json_test").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
records.ddlRecordsForDatabase("json_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -117,19 +106,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig().build();
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "jsonit_snap")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "json_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -144,17 +121,17 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("jsonit_snap").size()).isEqualTo(numDdlRecords + numSetVariables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numDdlRecords + numSetVariables);
assertThat(records.recordsForTopic("jsonit_snap.json_test.dbz_126_jsontable").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_126_jsontable")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(numTables + 1); assertThat(records.topics().size()).isEqualTo(numTables + 1);
assertThat(records.databaseNames().size()).isEqualTo(2); assertThat(records.databaseNames().size()).isEqualTo(2);
assertThat(records.databaseNames()).containsOnly("json_test", ""); assertThat(records.databaseNames()).containsOnly(DATABASE.getDatabaseName(), "");
assertThat(records.ddlRecordsForDatabase("json_test").size()).isEqualTo(numDdlRecords); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numDdlRecords);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement
records.ddlRecordsForDatabase("json_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);

View File

@ -30,13 +30,11 @@
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.connector.mysql.MySqlConnectorConfig.DecimalHandlingMode; import io.debezium.connector.mysql.MySqlConnectorConfig.DecimalHandlingMode;
import io.debezium.connector.mysql.MySqlConnectorConfig.SecureConnectionMode;
import io.debezium.connector.mysql.MySqlConnectorConfig.SnapshotMode; import io.debezium.connector.mysql.MySqlConnectorConfig.SnapshotMode;
import io.debezium.connector.mysql.MySqlConnectorConfig.TemporalPrecisionMode; import io.debezium.connector.mysql.MySqlConnectorConfig.TemporalPrecisionMode;
import io.debezium.data.Envelope; import io.debezium.data.Envelope;
import io.debezium.doc.FixFor; import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.time.ZonedTimestamp; import io.debezium.time.ZonedTimestamp;
import io.debezium.util.Testing; import io.debezium.util.Testing;
@ -46,6 +44,9 @@
public class MySqlConnectorRegressionIT extends AbstractConnectorTest { public class MySqlConnectorRegressionIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-regression.txt").toAbsolutePath(); private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-regression.txt").toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("regression", "regression_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private static final TemporalAdjuster ADJUSTER = MySqlValueConverters::adjustTemporal; private static final TemporalAdjuster ADJUSTER = MySqlValueConverters::adjustTemporal;
private Configuration config; private Configuration config;
@ -53,6 +54,7 @@ public class MySqlConnectorRegressionIT extends AbstractConnectorTest {
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -70,21 +72,10 @@ public void afterEach() {
@FixFor("DBZ-61") @FixFor("DBZ-61")
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port")) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(MySqlConnectorConfig.USER, "snapper") .build();
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "regression")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "regression_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER.toString())
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -98,22 +89,22 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("regression").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic("regression.regression_test.t1464075356413_testtable6").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("t1464075356413_testtable6")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz84_integer_types_table").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz84_integer_types_table")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_85_fractest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_85_fractest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_100_enumsettest").size()).isEqualTo(3); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_100_enumsettest")).size()).isEqualTo(3);
assertThat(records.recordsForTopic("regression.regression_test.dbz_102_charsettest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_102_charsettest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_114_zerovaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_114_zerovaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_123_bitvaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_123_bitvaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_104_customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_104_customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("regression.regression_test.dbz_147_decimalvalues").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_147_decimalvalues")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(1 + numCreateTables); assertThat(records.topics().size()).isEqualTo(1 + numCreateTables);
assertThat(records.databaseNames().size()).isEqualTo(1); assertThat(records.databaseNames().size()).isEqualTo(1);
assertThat(records.ddlRecordsForDatabase("regression_test").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
records.ddlRecordsForDatabase("regression_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -277,21 +268,11 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
@FixFor("DBZ-61") @FixFor("DBZ-61")
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshotAndConnectTimesTypes() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshotAndConnectTimesTypes() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "regression")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "regression_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER) .with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER)
.with(MySqlConnectorConfig.TIME_PRECISION_MODE, TemporalPrecisionMode.CONNECT) .with(MySqlConnectorConfig.TIME_PRECISION_MODE, TemporalPrecisionMode.CONNECT)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -306,22 +287,22 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshotAndConnect
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("regression").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic("regression.regression_test.t1464075356413_testtable6").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("t1464075356413_testtable6")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz84_integer_types_table").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz84_integer_types_table")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_85_fractest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_85_fractest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_100_enumsettest").size()).isEqualTo(3); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_100_enumsettest")).size()).isEqualTo(3);
assertThat(records.recordsForTopic("regression.regression_test.dbz_102_charsettest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_102_charsettest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_114_zerovaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_114_zerovaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_123_bitvaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_123_bitvaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_104_customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_104_customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("regression.regression_test.dbz_147_decimalvalues").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_147_decimalvalues")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(1 + numCreateTables); assertThat(records.topics().size()).isEqualTo(1 + numCreateTables);
assertThat(records.databaseNames().size()).isEqualTo(1); assertThat(records.databaseNames().size()).isEqualTo(1);
assertThat(records.ddlRecordsForDatabase("regression_test").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
records.ddlRecordsForDatabase("regression_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
// records.forEach(this::validate); // Can't run this with 0.10.0.1; see KAFKA-4183 // records.forEach(this::validate); // Can't run this with 0.10.0.1; see KAFKA-4183
@ -485,19 +466,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshotAndConnect
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig().build();
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "regression")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "regression_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -512,25 +481,25 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("regression").size()).isEqualTo(numDdlRecords + numSetVariables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numDdlRecords + numSetVariables);
assertThat(records.recordsForTopic("regression.regression_test.t1464075356413_testtable6").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("t1464075356413_testtable6")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz84_integer_types_table").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz84_integer_types_table")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_85_fractest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_85_fractest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_100_enumsettest").size()).isEqualTo(3); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_100_enumsettest")).size()).isEqualTo(3);
assertThat(records.recordsForTopic("regression.regression_test.dbz_102_charsettest").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_102_charsettest")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_114_zerovaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_114_zerovaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_123_bitvaluetest").size()).isEqualTo(2); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_123_bitvaluetest")).size()).isEqualTo(2);
assertThat(records.recordsForTopic("regression.regression_test.dbz_104_customers").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_104_customers")).size()).isEqualTo(4);
assertThat(records.recordsForTopic("regression.regression_test.dbz_147_decimalvalues").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_147_decimalvalues")).size()).isEqualTo(1);
assertThat(records.recordsForTopic("regression.regression_test.dbz_195_numvalues").size()).isEqualTo(3); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_195_numvalues")).size()).isEqualTo(3);
assertThat(records.topics().size()).isEqualTo(numTables + 1); assertThat(records.topics().size()).isEqualTo(numTables + 1);
assertThat(records.databaseNames().size()).isEqualTo(2); assertThat(records.databaseNames().size()).isEqualTo(2);
assertThat(records.databaseNames()).containsOnly("regression_test", ""); assertThat(records.databaseNames()).containsOnly(DATABASE.getDatabaseName(), "");
assertThat(records.ddlRecordsForDatabase("regression_test").size()).isEqualTo(numDdlRecords); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numDdlRecords);
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement
records.ddlRecordsForDatabase("regression_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -668,22 +637,11 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
@FixFor("DBZ-147") @FixFor("DBZ-147")
public void shouldConsumeAllEventsFromDecimalTableInDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDecimalTableInDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.TABLE_WHITELIST, DATABASE.qualifiedTableName("dbz_147_decimalvalues"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "regression")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "regression_test")
.with(MySqlConnectorConfig.TABLE_WHITELIST, "regression_test.dbz_147_decimalvalues")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true) .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER.toString()) .with(MySqlConnectorConfig.SNAPSHOT_MODE, SnapshotMode.NEVER.toString())
.with(MySqlConnectorConfig.DECIMAL_HANDLING_MODE, DecimalHandlingMode.DOUBLE) .with(MySqlConnectorConfig.DECIMAL_HANDLING_MODE, DecimalHandlingMode.DOUBLE)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -698,8 +656,8 @@ public void shouldConsumeAllEventsFromDecimalTableInDatabaseUsingBinlogAndNoSnap
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("regression").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic("regression.regression_test.dbz_147_decimalvalues").size()).isEqualTo(1); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_147_decimalvalues")).size()).isEqualTo(1);
assertThat(records.topics().size()).isEqualTo(2); // rather than 1+numCreateTables assertThat(records.topics().size()).isEqualTo(2); // rather than 1+numCreateTables
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...

View File

@ -22,7 +22,6 @@
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.doc.FixFor; import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
/** /**
@ -32,12 +31,15 @@ public class MySqlFixedLengthBinaryColumnIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-binary-column.txt") private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-binary-column.txt")
.toAbsolutePath(); .toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("binarycolumnit", "binary_column_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -55,19 +57,8 @@ public void afterEach() {
@FixFor("DBZ-254") @FixFor("DBZ-254")
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "binarycolumnit")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "binary_column_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
@ -83,7 +74,7 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numInserts); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numInserts);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
List<SourceRecord> dmls = records.recordsForTopic("binarycolumnit.binary_column_test.dbz_254_binary_column_test"); List<SourceRecord> dmls = records.recordsForTopic(DATABASE.topicForTable("dbz_254_binary_column_test"));
assertThat(dmls).hasSize(4); assertThat(dmls).hasSize(4);
// source value has a trailing "00" which is not distinguishable from // source value has a trailing "00" which is not distinguishable from

View File

@ -19,7 +19,6 @@
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.data.Envelope; import io.debezium.data.Envelope;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
import mil.nga.wkb.geom.Point; import mil.nga.wkb.geom.Point;
import mil.nga.wkb.io.ByteReader; import mil.nga.wkb.io.ByteReader;
@ -32,12 +31,15 @@ public class MySqlGeometryIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-json.txt") private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-json.txt")
.toAbsolutePath(); .toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("geometryit", "geometry_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -54,20 +56,10 @@ public void afterEach() {
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname")) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port")) .build();
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "geometryit")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "geometry_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -81,17 +73,17 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("geometryit").size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic("geometryit.geometry_test.dbz_222_point").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_222_point")).size()).isEqualTo(4);
assertThat(records.topics().size()).isEqualTo(1 + numCreateTables); assertThat(records.topics().size()).isEqualTo(1 + numCreateTables);
assertThat(records.databaseNames().size()).isEqualTo(1); assertThat(records.databaseNames().size()).isEqualTo(1);
assertThat(records.ddlRecordsForDatabase("geometry_test").size()).isEqualTo( assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(
numCreateDatabase + numCreateTables); numCreateDatabase + numCreateTables);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("json_test")).isNull(); assertThat(records.ddlRecordsForDatabase("json_test")).isNull();
records.ddlRecordsForDatabase("geometry_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -106,19 +98,8 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig().build();
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "geometryit")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "geometry_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -134,17 +115,17 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("geometryit").size()).isEqualTo(numDdlRecords + numSetVariables); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numDdlRecords + numSetVariables);
assertThat(records.recordsForTopic("geometryit.geometry_test.dbz_222_point").size()).isEqualTo(4); assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_222_point")).size()).isEqualTo(4);
assertThat(records.topics().size()).isEqualTo(numTables + 1); assertThat(records.topics().size()).isEqualTo(numTables + 1);
assertThat(records.databaseNames()).containsOnly("geometry_test", ""); assertThat(records.databaseNames()).containsOnly(DATABASE.getDatabaseName(), "");
assertThat(records.ddlRecordsForDatabase("geometry_test").size()).isEqualTo(numDdlRecords); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numDdlRecords);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("json_test")).isNull(); assertThat(records.ddlRecordsForDatabase("json_test")).isNull();
assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement
records.ddlRecordsForDatabase("geometry_test").forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);

View File

@ -17,7 +17,6 @@
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.doc.FixFor; import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
/** /**
@ -25,14 +24,18 @@
*/ */
public class MySqlTableMaintenanceStatementsIT extends AbstractConnectorTest { public class MySqlTableMaintenanceStatementsIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-table-maintenance.txt") private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-table-maintenance.txt")
.toAbsolutePath(); .toAbsolutePath();
private final UniqueDatabase DATABASE = new UniqueDatabase("tablemaintenanceit", "table_maintenance_test")
.withDbHistoryPath(DB_HISTORY_PATH);
private Configuration config; private Configuration config;
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -50,19 +53,8 @@ public void afterEach() {
@FixFor("DBZ-253") @FixFor("DBZ-253")
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, "tablemaintenanceit")
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, "table_maintenance_test")
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
@ -76,11 +68,12 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
int numCreateTables = 1; int numCreateTables = 1;
int numTableMaintenanceStatements = 3; int numTableMaintenanceStatements = 3;
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numTableMaintenanceStatements); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numTableMaintenanceStatements);
System.out.println(records.allRecordsInOrder());
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic("tablemaintenanceit").size()).isEqualTo(numCreateDatabase + numCreateTables + numTableMaintenanceStatements); assertThat(records.recordsForTopic(DATABASE.getServerName()).size()).isEqualTo(numCreateDatabase + numCreateTables + numTableMaintenanceStatements);
assertThat(records.databaseNames()).containsOnly("table_maintenance_test"); assertThat(records.databaseNames()).containsOnly(DATABASE.getDatabaseName());
assertThat(records.ddlRecordsForDatabase("table_maintenance_test").size()).isEqualTo( assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(
numCreateDatabase + numCreateTables + numTableMaintenanceStatements); numCreateDatabase + numCreateTables + numTableMaintenanceStatements);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...

View File

@ -5,6 +5,12 @@
*/ */
package io.debezium.connector.mysql; package io.debezium.connector.mysql;
import static org.fest.assertions.Assertions.assertThat;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.sql.SQLException;
import org.apache.kafka.connect.data.Decimal; import org.apache.kafka.connect.data.Decimal;
import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.Struct; import org.apache.kafka.connect.data.Struct;
@ -12,18 +18,11 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.sql.SQLException;
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.data.Envelope; import io.debezium.data.Envelope;
import io.debezium.embedded.AbstractConnectorTest; import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* @author Omar Al-Safi * @author Omar Al-Safi
*/ */
@ -34,12 +33,13 @@ public class MySqlUnsignedIntegerIT extends AbstractConnectorTest {
private Configuration config; private Configuration config;
private static final String SERVER_NAME = "unsignednumericit"; private final UniqueDatabase DATABASE = new UniqueDatabase("unsignednumericit", "unsigned_integer_test")
private static final String DATABASE_NAME = "unsigned_integer_test"; .withDbHistoryPath(DB_HISTORY_PATH);
@Before @Before
public void beforeEach() { public void beforeEach() {
stopConnector(); stopConnector();
DATABASE.createAndInitialize();
initializeConnectorTestFramework(); initializeConnectorTestFramework();
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
} }
@ -56,20 +56,10 @@ public void afterEach() {
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, SERVER_NAME)
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, DATABASE_NAME)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER) .with(MySqlConnectorConfig.SNAPSHOT_MODE, MySqlConnectorConfig.SnapshotMode.NEVER)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build(); .build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -83,27 +73,27 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numCreateDatabase + numCreateTables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic(SERVER_NAME).size()).isEqualTo(numCreateDatabase + numCreateTables); assertThat(records.recordsForTopic("unsignednumericit").size()).isEqualTo(numCreateDatabase + numCreateTables);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_tinyint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_tinyint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_smallint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_smallint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_mediumint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_mediumint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_int_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_int_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_bigint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_bigint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.topics().size()).isEqualTo(1 + numCreateTables); assertThat(records.topics().size()).isEqualTo(1 + numCreateTables);
assertThat(records.databaseNames().size()).isEqualTo(1); assertThat(records.databaseNames().size()).isEqualTo(1);
assertThat(records.ddlRecordsForDatabase(DATABASE_NAME).size()).isEqualTo( assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(
numCreateDatabase + numCreateTables); numCreateDatabase + numCreateTables);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("json_test")).isNull(); assertThat(records.ddlRecordsForDatabase("json_test")).isNull();
assertThat(records.ddlRecordsForDatabase("geometry_test")).isNull(); assertThat(records.ddlRecordsForDatabase("geometry_test")).isNull();
records.ddlRecordsForDatabase(DATABASE_NAME).forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);
@ -126,19 +116,8 @@ public void shouldConsumeAllEventsFromDatabaseUsingBinlogAndNoSnapshot() throws
@Test @Test
public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException { public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLException, InterruptedException {
// Use the DB configuration to define the connector's configuration ... // Use the DB configuration to define the connector's configuration ...
config = Configuration.create() config = DATABASE.defaultConfig().build();
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, SERVER_NAME)
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, DATABASE_NAME)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
.build();
// Start the connector ... // Start the connector ...
start(MySqlConnector.class, config); start(MySqlConnector.class, config);
@ -154,27 +133,27 @@ public void shouldConsumeAllEventsFromDatabaseUsingSnapshot() throws SQLExceptio
SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords); SourceRecords records = consumeRecordsByTopic(numDdlRecords + numSetVariables + numDataRecords);
stopConnector(); stopConnector();
assertThat(records).isNotNull(); assertThat(records).isNotNull();
assertThat(records.recordsForTopic(SERVER_NAME).size()).isEqualTo(numDdlRecords + numSetVariables); assertThat(records.recordsForTopic("unsignednumericit").size()).isEqualTo(numDdlRecords + numSetVariables);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_tinyint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_tinyint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_smallint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_smallint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_mediumint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_mediumint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_int_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_int_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.recordsForTopic(SERVER_NAME + "." + DATABASE_NAME + ".dbz_228_bigint_unsigned").size()) assertThat(records.recordsForTopic(DATABASE.topicForTable("dbz_228_bigint_unsigned")).size())
.isEqualTo(3); .isEqualTo(3);
assertThat(records.topics().size()).isEqualTo(numTables + 1); assertThat(records.topics().size()).isEqualTo(numTables + 1);
assertThat(records.databaseNames()).containsOnly(DATABASE_NAME, ""); assertThat(records.databaseNames()).containsOnly(DATABASE.getDatabaseName(), "");
assertThat(records.ddlRecordsForDatabase(DATABASE_NAME).size()).isEqualTo(numDdlRecords); assertThat(records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).size()).isEqualTo(numDdlRecords);
assertThat(records.ddlRecordsForDatabase("regression_test")).isNull(); assertThat(records.ddlRecordsForDatabase("regression_test")).isNull();
assertThat(records.ddlRecordsForDatabase("connector_test")).isNull(); assertThat(records.ddlRecordsForDatabase("connector_test")).isNull();
assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull(); assertThat(records.ddlRecordsForDatabase("readbinlog_test")).isNull();
assertThat(records.ddlRecordsForDatabase("json_test")).isNull(); assertThat(records.ddlRecordsForDatabase("json_test")).isNull();
assertThat(records.ddlRecordsForDatabase("geometry_test")).isNull(); assertThat(records.ddlRecordsForDatabase("geometry_test")).isNull();
assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement assertThat(records.ddlRecordsForDatabase("").size()).isEqualTo(1); // SET statement
records.ddlRecordsForDatabase(DATABASE_NAME).forEach(this::print); records.ddlRecordsForDatabase(DATABASE.getDatabaseName()).forEach(this::print);
// Check that all records are valid, can be serialized and deserialized ... // Check that all records are valid, can be serialized and deserialized ...
records.forEach(this::validate); records.forEach(this::validate);

View File

@ -69,12 +69,15 @@ private static final class AnyValue implements Serializable {
private List<Event> events = new LinkedList<>(); private List<Event> events = new LinkedList<>();
private JdbcConfiguration config; private JdbcConfiguration config;
private final UniqueDatabase DATABASE = new UniqueDatabase("readbinlog_it", "readbinlog_test");
@Before @Before
public void beforeEach() throws TimeoutException, IOException, SQLException, InterruptedException { public void beforeEach() throws TimeoutException, IOException, SQLException, InterruptedException {
events.clear(); events.clear();
// Connect the normal SQL client ... // Connect the normal SQL client ...
conn = MySQLConnection.forTestDatabase("readbinlog_test"); DATABASE.createAndInitialize();
conn = MySQLConnection.forTestDatabase(DATABASE.getDatabaseName());
conn.connect(); conn.connect();
// Get the configuration that we used ... // Get the configuration that we used ...

View File

@ -19,12 +19,10 @@
import org.junit.Test; import org.junit.Test;
import io.debezium.config.Configuration; import io.debezium.config.Configuration;
import io.debezium.connector.mysql.MySqlConnectorConfig.SecureConnectionMode;
import io.debezium.data.KeyValueStore; import io.debezium.data.KeyValueStore;
import io.debezium.data.KeyValueStore.Collection; import io.debezium.data.KeyValueStore.Collection;
import io.debezium.data.SchemaChangeHistory; import io.debezium.data.SchemaChangeHistory;
import io.debezium.data.VerifyRecord; import io.debezium.data.VerifyRecord;
import io.debezium.relational.history.FileDatabaseHistory;
import io.debezium.util.Testing; import io.debezium.util.Testing;
/** /**
@ -34,8 +32,9 @@
public class SnapshotReaderIT { public class SnapshotReaderIT {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-snapshot.txt").toAbsolutePath(); private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-snapshot.txt").toAbsolutePath();
private static final String DB_NAME = "connector_test_ro"; private final UniqueDatabase DATABASE = new UniqueDatabase("logical_server_name", "connector_test_ro")
private static final String LOGICAL_NAME = "logical_server_name"; .withDbHistoryPath(DB_HISTORY_PATH);
private final UniqueDatabase OTHER_DATABASE = new UniqueDatabase("logical_server_name", "connector_test", DATABASE);
private Configuration config; private Configuration config;
private MySqlTaskContext context; private MySqlTaskContext context;
@ -45,6 +44,8 @@ public class SnapshotReaderIT {
@Before @Before
public void beforeEach() { public void beforeEach() {
Testing.Files.delete(DB_HISTORY_PATH); Testing.Files.delete(DB_HISTORY_PATH);
DATABASE.createAndInitialize();
OTHER_DATABASE.createAndInitialize();
completed = new CountDownLatch(1); completed = new CountDownLatch(1);
} }
@ -68,28 +69,14 @@ public void afterEach() {
} }
protected Configuration.Builder simpleConfig() { protected Configuration.Builder simpleConfig() {
String hostname = System.getProperty("database.hostname"); return DATABASE.defaultConfig()
String port = System.getProperty("database.port"); .with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false);
assertThat(hostname).isNotNull();
assertThat(port).isNotNull();
return Configuration.create()
.with(MySqlConnectorConfig.HOSTNAME, hostname)
.with(MySqlConnectorConfig.PORT, port)
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass")
.with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18911)
.with(MySqlConnectorConfig.SERVER_NAME, LOGICAL_NAME)
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, false)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, DB_NAME)
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
.with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH);
} }
@Test @Test
public void shouldCreateSnapshotOfSingleDatabase() throws Exception { public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
config = simpleConfig().build(); config = simpleConfig()
.build();
context = new MySqlTaskContext(config); context = new MySqlTaskContext(config);
context.start(); context.start();
reader = new SnapshotReader("snapshot", context); reader = new SnapshotReader("snapshot", context);
@ -103,8 +90,8 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
// Poll for records ... // Poll for records ...
// Testing.Print.enable(); // Testing.Print.enable();
List<SourceRecord> records = null; List<SourceRecord> records = null;
KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(LOGICAL_NAME + "."); KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(DATABASE.getServerName() + ".");
SchemaChangeHistory schemaChanges = new SchemaChangeHistory(LOGICAL_NAME); SchemaChangeHistory schemaChanges = new SchemaChangeHistory(DATABASE.getServerName());
while ((records = reader.poll()) != null) { while ((records = reader.poll()) != null) {
records.forEach(record -> { records.forEach(record -> {
VerifyRecord.isValid(record); VerifyRecord.isValid(record);
@ -120,7 +107,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
// Check the records via the store ... // Check the records via the store ...
assertThat(store.collectionCount()).isEqualTo(4); assertThat(store.collectionCount()).isEqualTo(4);
Collection products = store.collection(DB_NAME, "products"); Collection products = store.collection(DATABASE.getDatabaseName(), "products");
assertThat(products.numberOfCreates()).isEqualTo(9); assertThat(products.numberOfCreates()).isEqualTo(9);
assertThat(products.numberOfUpdates()).isEqualTo(0); assertThat(products.numberOfUpdates()).isEqualTo(0);
assertThat(products.numberOfDeletes()).isEqualTo(0); assertThat(products.numberOfDeletes()).isEqualTo(0);
@ -129,7 +116,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1);
Collection products_on_hand = store.collection(DB_NAME, "products_on_hand"); Collection products_on_hand = store.collection(DATABASE.getDatabaseName(), "products_on_hand");
assertThat(products_on_hand.numberOfCreates()).isEqualTo(9); assertThat(products_on_hand.numberOfCreates()).isEqualTo(9);
assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0); assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0);
assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0); assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0);
@ -138,7 +125,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1);
Collection customers = store.collection(DB_NAME, "customers"); Collection customers = store.collection(DATABASE.getDatabaseName(), "customers");
assertThat(customers.numberOfCreates()).isEqualTo(4); assertThat(customers.numberOfCreates()).isEqualTo(4);
assertThat(customers.numberOfUpdates()).isEqualTo(0); assertThat(customers.numberOfUpdates()).isEqualTo(0);
assertThat(customers.numberOfDeletes()).isEqualTo(0); assertThat(customers.numberOfDeletes()).isEqualTo(0);
@ -147,7 +134,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1);
Collection orders = store.collection(DB_NAME, "orders"); Collection orders = store.collection(DATABASE.getDatabaseName(), "orders");
assertThat(orders.numberOfCreates()).isEqualTo(5); assertThat(orders.numberOfCreates()).isEqualTo(5);
assertThat(orders.numberOfUpdates()).isEqualTo(0); assertThat(orders.numberOfUpdates()).isEqualTo(0);
assertThat(orders.numberOfDeletes()).isEqualTo(0); assertThat(orders.numberOfDeletes()).isEqualTo(0);
@ -167,7 +154,7 @@ public void shouldCreateSnapshotOfSingleDatabase() throws Exception {
@Test @Test
public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Exception { public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Exception {
config = simpleConfig().with(MySqlConnectorConfig.DATABASE_WHITELIST, "connector_(.*)").build(); config = simpleConfig().with(MySqlConnectorConfig.DATABASE_WHITELIST, "connector_(.*)_" + DATABASE.getIdentifier()).build();
context = new MySqlTaskContext(config); context = new MySqlTaskContext(config);
context.start(); context.start();
reader = new SnapshotReader("snapshot", context); reader = new SnapshotReader("snapshot", context);
@ -181,8 +168,8 @@ public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Excepti
// Poll for records ... // Poll for records ...
// Testing.Print.enable(); // Testing.Print.enable();
List<SourceRecord> records = null; List<SourceRecord> records = null;
KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(LOGICAL_NAME + "."); KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(DATABASE.getServerName() + ".");
SchemaChangeHistory schemaChanges = new SchemaChangeHistory(LOGICAL_NAME); SchemaChangeHistory schemaChanges = new SchemaChangeHistory(DATABASE.getServerName());
while ((records = reader.poll()) != null) { while ((records = reader.poll()) != null) {
records.forEach(record -> { records.forEach(record -> {
VerifyRecord.isValid(record); VerifyRecord.isValid(record);
@ -197,10 +184,10 @@ public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Excepti
assertThat(schemaChanges.recordCount()).isEqualTo(0); assertThat(schemaChanges.recordCount()).isEqualTo(0);
// Check the records via the store ... // Check the records via the store ...
assertThat(store.databases()).containsOnly(DB_NAME, "connector_test"); // 2 databases assertThat(store.databases()).containsOnly(DATABASE.getDatabaseName(), OTHER_DATABASE.getDatabaseName()); // 2 databases
assertThat(store.collectionCount()).isEqualTo(8); // 2 databases assertThat(store.collectionCount()).isEqualTo(8); // 2 databases
Collection products = store.collection(DB_NAME, "products"); Collection products = store.collection(DATABASE.getDatabaseName(), "products");
assertThat(products.numberOfCreates()).isEqualTo(0); assertThat(products.numberOfCreates()).isEqualTo(0);
assertThat(products.numberOfUpdates()).isEqualTo(0); assertThat(products.numberOfUpdates()).isEqualTo(0);
assertThat(products.numberOfDeletes()).isEqualTo(0); assertThat(products.numberOfDeletes()).isEqualTo(0);
@ -209,7 +196,7 @@ public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Excepti
assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1);
Collection products_on_hand = store.collection(DB_NAME, "products_on_hand"); Collection products_on_hand = store.collection(DATABASE.getDatabaseName(), "products_on_hand");
assertThat(products_on_hand.numberOfCreates()).isEqualTo(0); assertThat(products_on_hand.numberOfCreates()).isEqualTo(0);
assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0); assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0);
assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0); assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0);
@ -218,7 +205,7 @@ public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Excepti
assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1);
Collection customers = store.collection(DB_NAME, "customers"); Collection customers = store.collection(DATABASE.getDatabaseName(), "customers");
assertThat(customers.numberOfCreates()).isEqualTo(0); assertThat(customers.numberOfCreates()).isEqualTo(0);
assertThat(customers.numberOfUpdates()).isEqualTo(0); assertThat(customers.numberOfUpdates()).isEqualTo(0);
assertThat(customers.numberOfDeletes()).isEqualTo(0); assertThat(customers.numberOfDeletes()).isEqualTo(0);
@ -227,7 +214,7 @@ public void shouldCreateSnapshotOfSingleDatabaseUsingReadEvents() throws Excepti
assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1);
Collection orders = store.collection(DB_NAME, "orders"); Collection orders = store.collection(DATABASE.getDatabaseName(), "orders");
assertThat(orders.numberOfCreates()).isEqualTo(0); assertThat(orders.numberOfCreates()).isEqualTo(0);
assertThat(orders.numberOfUpdates()).isEqualTo(0); assertThat(orders.numberOfUpdates()).isEqualTo(0);
assertThat(orders.numberOfDeletes()).isEqualTo(0); assertThat(orders.numberOfDeletes()).isEqualTo(0);
@ -261,8 +248,8 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
// Poll for records ... // Poll for records ...
// Testing.Print.enable(); // Testing.Print.enable();
List<SourceRecord> records = null; List<SourceRecord> records = null;
KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(LOGICAL_NAME + "."); KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(DATABASE.getServerName() + ".");
SchemaChangeHistory schemaChanges = new SchemaChangeHistory(LOGICAL_NAME); SchemaChangeHistory schemaChanges = new SchemaChangeHistory(DATABASE.getServerName());
while ((records = reader.poll()) != null) { while ((records = reader.poll()) != null) {
records.forEach(record -> { records.forEach(record -> {
VerifyRecord.isValid(record); VerifyRecord.isValid(record);
@ -276,11 +263,11 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
// There should be 11 schema changes plus 1 SET statement ... // There should be 11 schema changes plus 1 SET statement ...
assertThat(schemaChanges.recordCount()).isEqualTo(12); assertThat(schemaChanges.recordCount()).isEqualTo(12);
assertThat(schemaChanges.databaseCount()).isEqualTo(2); assertThat(schemaChanges.databaseCount()).isEqualTo(2);
assertThat(schemaChanges.databases()).containsOnly(DB_NAME, ""); assertThat(schemaChanges.databases()).containsOnly(DATABASE.getDatabaseName(), "");
// Check the records via the store ... // Check the records via the store ...
assertThat(store.collectionCount()).isEqualTo(4); assertThat(store.collectionCount()).isEqualTo(4);
Collection products = store.collection(DB_NAME, "products"); Collection products = store.collection(DATABASE.getDatabaseName(), "products");
assertThat(products.numberOfCreates()).isEqualTo(9); assertThat(products.numberOfCreates()).isEqualTo(9);
assertThat(products.numberOfUpdates()).isEqualTo(0); assertThat(products.numberOfUpdates()).isEqualTo(0);
assertThat(products.numberOfDeletes()).isEqualTo(0); assertThat(products.numberOfDeletes()).isEqualTo(0);
@ -289,7 +276,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products.numberOfValueSchemaChanges()).isEqualTo(1);
Collection products_on_hand = store.collection(DB_NAME, "products_on_hand"); Collection products_on_hand = store.collection(DATABASE.getDatabaseName(), "products_on_hand");
assertThat(products_on_hand.numberOfCreates()).isEqualTo(9); assertThat(products_on_hand.numberOfCreates()).isEqualTo(9);
assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0); assertThat(products_on_hand.numberOfUpdates()).isEqualTo(0);
assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0); assertThat(products_on_hand.numberOfDeletes()).isEqualTo(0);
@ -298,7 +285,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(products_on_hand.numberOfValueSchemaChanges()).isEqualTo(1);
Collection customers = store.collection(DB_NAME, "customers"); Collection customers = store.collection(DATABASE.getDatabaseName(), "customers");
assertThat(customers.numberOfCreates()).isEqualTo(4); assertThat(customers.numberOfCreates()).isEqualTo(4);
assertThat(customers.numberOfUpdates()).isEqualTo(0); assertThat(customers.numberOfUpdates()).isEqualTo(0);
assertThat(customers.numberOfDeletes()).isEqualTo(0); assertThat(customers.numberOfDeletes()).isEqualTo(0);
@ -307,7 +294,7 @@ public void shouldCreateSnapshotOfSingleDatabaseWithSchemaChanges() throws Excep
assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1); assertThat(customers.numberOfKeySchemaChanges()).isEqualTo(1);
assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1); assertThat(customers.numberOfValueSchemaChanges()).isEqualTo(1);
Collection orders = store.collection(DB_NAME, "orders"); Collection orders = store.collection(DATABASE.getDatabaseName(), "orders");
assertThat(orders.numberOfCreates()).isEqualTo(5); assertThat(orders.numberOfCreates()).isEqualTo(5);
assertThat(orders.numberOfUpdates()).isEqualTo(0); assertThat(orders.numberOfUpdates()).isEqualTo(0);
assertThat(orders.numberOfDeletes()).isEqualTo(0); assertThat(orders.numberOfDeletes()).isEqualTo(0);
@ -341,8 +328,8 @@ public void shouldCreateSnapshotSchemaOnly() throws Exception {
// Poll for records ... // Poll for records ...
// Testing.Print.enable(); // Testing.Print.enable();
List<SourceRecord> records = null; List<SourceRecord> records = null;
KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(LOGICAL_NAME + "."); KeyValueStore store = KeyValueStore.createForTopicsBeginningWith(DATABASE.getServerName() + ".");
SchemaChangeHistory schemaChanges = new SchemaChangeHistory(LOGICAL_NAME); SchemaChangeHistory schemaChanges = new SchemaChangeHistory(DATABASE.getServerName());
while ((records = reader.poll()) != null) { while ((records = reader.poll()) != null) {
records.forEach(record -> { records.forEach(record -> {
VerifyRecord.isValid(record); VerifyRecord.isValid(record);

View File

@ -0,0 +1,183 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.mysql;
import static org.junit.Assert.assertNotNull;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.debezium.config.Configuration;
import io.debezium.relational.history.FileDatabaseHistory;
/**
* Create and populate a unique instance of a MySQL database for each run of JUnit test. A user of class
* needs to provide a logical name for Debezium and database name. It is expected that there is a init file
* in <code>src/test/resources/ddl/&lt;database_name&gt;.sql</code>.
* The database name is enriched with a unique suffix that guarantees complete isolation between runs
* <code>&lt;database_name&gt_&lt;suffix&gt</code>
*
* @author jpechane
*
*/
public class UniqueDatabase {
private static final String DEFAULT_DATABASE = "mysql";
private static final String[] CREATE_DATABASE_DDL = new String[] {
"CREATE DATABASE $DBNAME$;",
"USE $DBNAME$;"
};
private static final Pattern COMMENT_PATTERN = Pattern.compile("^(.*)--.*$");
private final String databaseName;
private final String templateName;
private final String serverName;
private Path dbHistoryPath;
private String identifier;
private UniqueDatabase(final String serverName, final String databaseName, final String identifier) {
this.identifier = identifier;
this.databaseName = databaseName + "_" + identifier;
this.templateName = databaseName;
this.serverName = serverName;
}
/**
* Creates an instance with given Debezium logical name and database name
*
* @param serverName - logical Debezium server name
* @param databaseName - the name of the database (prix)
*/
public UniqueDatabase(final String serverName, final String databaseName) {
this(serverName, databaseName, Integer.toUnsignedString(new Random().nextInt(), 36));
}
/**
* Creates an instance with given Debezium logical name and database name and id suffix same
* as another database. This is handy for tests that need multpli databases and can use regex
* based whitelisting.
* @param serverName - logical Debezium server name
* @param databaseName - the name of the database (prix)
* @param sibling - a database whose unique suffix will be used
*/
public UniqueDatabase(final String serverName, final String databaseName, final UniqueDatabase sibling) {
this(serverName, databaseName, sibling.getIdentifier());
}
private String convertSQL(final String sql) {
return sql.replace("$DBNAME$", databaseName);
}
public String getDatabaseName() {
return databaseName;
}
/**
* @param tableName
* @return Fully qualified Kafka topic name for a given table <code>&lt;serverName&gt;.&lt;databaseName&gt;.&lt;tableName&gt;</code>
*/
public String topicForTable(final String tableName) {
return String.format("%s.%s.%s", serverName, databaseName, tableName);
}
/**
* @param tableName
* @return Fully qualified table name <code>&lt;databaseName&gt;.&lt;tableName&gt;</code>
*/
public String qualifiedTableName(final String tableName) {
return String.format("%s.%s", databaseName, tableName);
}
protected String getServerName() {
return serverName;
}
/**
* Creates the database and populates it with initialization SQL script. To use multiline
* statements for stored procedures definition use delimiter $$ to delimit statements in the procedure.
* See fnDbz162 procedure in reqression_test.sql for example of usage.
*/
public void createAndInitialize() {
final String ddlFile = String.format("ddl/%s.sql", templateName);
final URL ddlTestFile = UniqueDatabase.class.getClassLoader().getResource(ddlFile);
assertNotNull("Cannot locate " + ddlFile, ddlTestFile);
try {
try (MySQLConnection connection = MySQLConnection.forTestDatabase(DEFAULT_DATABASE)) {
final List<String> statements = Arrays.stream(
Stream.concat(
Arrays.stream(CREATE_DATABASE_DDL),
Files.readAllLines(Paths.get(ddlTestFile.toURI())).stream())
.map(String::trim)
.filter(x -> !x.startsWith("--") && !x.isEmpty())
.map(x -> {
final Matcher m = COMMENT_PATTERN.matcher(x);
return m.matches() ? m.group(1) : x;
})
.map(this::convertSQL)
.collect(Collectors.joining("\n")).split(";")
)
.map(x -> x.replace("$$", ";"))
.collect(Collectors.toList());
connection.execute(statements.toArray(new String[statements.size()]));
}
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}
/**
* @param dbHistoryPath - directory where to store database schema history
* @see io.debezium.relational.history.FileDatabaseHistory
*/
public UniqueDatabase withDbHistoryPath(final Path dbHistoryPath) {
this.dbHistoryPath = dbHistoryPath;
return this;
}
/**
* @return Configuration builder initialized with JDBC connection parameters.
*/
public Configuration.Builder defaultJdbcConfigBuilder() {
return Configuration.create()
.with(MySqlConnectorConfig.HOSTNAME, System.getProperty("database.hostname", "localhost"))
.with(MySqlConnectorConfig.PORT, System.getProperty("database.port", "3306"))
.with(MySqlConnectorConfig.USER, "snapper")
.with(MySqlConnectorConfig.PASSWORD, "snapperpass");
}
/**
* @return Configuration builder initialized with JDBC connection parameters and most frequently used parameters
*/
public Configuration.Builder defaultConfig() {
final Configuration.Builder builder = defaultJdbcConfigBuilder()
.with(MySqlConnectorConfig.SSL_MODE, MySqlConnectorConfig.SecureConnectionMode.DISABLED)
.with(MySqlConnectorConfig.SERVER_ID, 18765)
.with(MySqlConnectorConfig.SERVER_NAME, getServerName())
.with(MySqlConnectorConfig.POLL_INTERVAL_MS, 10)
.with(MySqlConnectorConfig.DATABASE_WHITELIST, getDatabaseName())
.with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class);
if (dbHistoryPath != null) {
builder.with(FileDatabaseHistory.FILE_PATH, dbHistoryPath);
}
return builder;
}
/**
* @return The unique database suffix
*/
public String getIdentifier() {
return identifier;
}
}

View File

@ -0,0 +1,14 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: binary_column_test
-- ----------------------------------------------------------------------------------------------------------------
CREATE TABLE dbz_254_binary_column_test (
id INT AUTO_INCREMENT NOT NULL,
file_uuid BINARY(16),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b7400','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b74ab','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(replace('651aed08-390f-4893-b2f1-36923e7b74','-','')));
INSERT INTO dbz_254_binary_column_test VALUES (default, unhex(00));

View File

@ -0,0 +1,73 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: connector_test
-- ----------------------------------------------------------------------------------------------------------------
-- Create and populate our products using a single insert with many rows
CREATE TABLE products (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description VARCHAR(512),
weight FLOAT
);
ALTER TABLE products AUTO_INCREMENT = 101;
INSERT INTO products
VALUES (default,"scooter","Small 2-wheel scooter",3.14),
(default,"car battery","12V car battery",8.1),
(default,"12-pack drill bits","12-pack of drill bits with sizes ranging from #40 to #3",0.8),
(default,"hammer","12oz carpenter's hammer",0.75),
(default,"hammer","14oz carpenter's hammer",0.875),
(default,"hammer","16oz carpenter's hammer",1.0),
(default,"rocks","box of assorted rocks",5.3),
(default,"jacket","water resistent black wind breaker",0.1),
(default,"spare tire","24 inch spare tire",22.2);
-- Create and populate the products on hand using multiple inserts
CREATE TABLE products_on_hand (
product_id INTEGER NOT NULL PRIMARY KEY,
quantity INTEGER NOT NULL,
FOREIGN KEY (product_id) REFERENCES products(id)
);
INSERT INTO products_on_hand VALUES (101,3);
INSERT INTO products_on_hand VALUES (102,8);
INSERT INTO products_on_hand VALUES (103,18);
INSERT INTO products_on_hand VALUES (104,4);
INSERT INTO products_on_hand VALUES (105,5);
INSERT INTO products_on_hand VALUES (106,0);
INSERT INTO products_on_hand VALUES (107,44);
INSERT INTO products_on_hand VALUES (108,2);
INSERT INTO products_on_hand VALUES (109,5);
-- Create some customers ...
CREATE TABLE customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE KEY
) AUTO_INCREMENT=1001;
INSERT INTO customers
VALUES (default,"Sally","Thomas","sally.thomas@acme.com"),
(default,"George","Bailey","gbailey@foobar.com"),
(default,"Edward","Walker","ed@walker.com"),
(default,"Anne","Kretchmar","annek@noanswer.org");
-- Create some very simple orders
CREATE TABLE orders (
order_number INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_date DATE NOT NULL,
purchaser INTEGER NOT NULL,
quantity INTEGER NOT NULL,
product_id INTEGER NOT NULL,
FOREIGN KEY order_customer (purchaser) REFERENCES customers(id),
FOREIGN KEY ordered_product (product_id) REFERENCES products(id)
) AUTO_INCREMENT = 10001;
INSERT INTO orders
VALUES (default, '2016-01-16', 1001, 1, 102),
(default, '2016-01-17', 1002, 2, 105),
(default, '2016-02-18', 1004, 3, 109),
(default, '2016-02-19', 1002, 2, 106),
(default, '16-02-21', 1003, 1, 107);

View File

@ -0,0 +1,73 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: connector_test_ro
-- ----------------------------------------------------------------------------------------------------------------
-- Create and populate our products using a single insert with many rows
CREATE TABLE products (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description VARCHAR(512),
weight FLOAT
);
ALTER TABLE products AUTO_INCREMENT = 101;
INSERT INTO products
VALUES (default,"scooter","Small 2-wheel scooter",3.14),
(default,"car battery","12V car battery",8.1),
(default,"12-pack drill bits","12-pack of drill bits with sizes ranging from #40 to #3",0.8),
(default,"hammer","12oz carpenter's hammer",0.75),
(default,"hammer","14oz carpenter's hammer",0.875),
(default,"hammer","16oz carpenter's hammer",1.0),
(default,"rocks","box of assorted rocks",5.3),
(default,"jacket","water resistent black wind breaker",0.1),
(default,"spare tire","24 inch spare tire",22.2);
-- Create and populate the products on hand using multiple inserts
CREATE TABLE products_on_hand (
product_id INTEGER NOT NULL PRIMARY KEY,
quantity INTEGER NOT NULL,
FOREIGN KEY (product_id) REFERENCES products(id)
);
INSERT INTO products_on_hand VALUES (101,3);
INSERT INTO products_on_hand VALUES (102,8);
INSERT INTO products_on_hand VALUES (103,18);
INSERT INTO products_on_hand VALUES (104,4);
INSERT INTO products_on_hand VALUES (105,5);
INSERT INTO products_on_hand VALUES (106,0);
INSERT INTO products_on_hand VALUES (107,44);
INSERT INTO products_on_hand VALUES (108,2);
INSERT INTO products_on_hand VALUES (109,5);
-- Create some customers ...
CREATE TABLE customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE KEY
) AUTO_INCREMENT=1001;
INSERT INTO customers
VALUES (default,"Sally","Thomas","sally.thomas@acme.com"),
(default,"George","Bailey","gbailey@foobar.com"),
(default,"Edward","Walker","ed@walker.com"),
(default,"Anne","Kretchmar","annek@noanswer.org");
-- Create some very simple orders
CREATE TABLE orders (
order_number INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_date DATE NOT NULL,
purchaser INTEGER NOT NULL,
quantity INTEGER NOT NULL,
product_id INTEGER NOT NULL,
FOREIGN KEY order_customer (purchaser) REFERENCES customers(id),
FOREIGN KEY ordered_product (product_id) REFERENCES products(id)
) AUTO_INCREMENT = 10001;
INSERT INTO orders
VALUES (default, '2016-01-16', 1001, 1, 102),
(default, '2016-01-17', 1002, 2, 105),
(default, '2016-02-18', 1004, 3, 109),
(default, '2016-02-19', 1002, 2, 106),
(default, '2016-02-21', 1003, 1, 107);

View File

@ -0,0 +1,21 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: geometry_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's Geometries datatypes.
-- DBZ-222 handle POINT column types ...
CREATE TABLE dbz_222_point (
id INT AUTO_INCREMENT NOT NULL,
point POINT DEFAULT NULL,
expected_x FLOAT,
expected_y FLOAT,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(1 1)'), 1.0, 1.0);
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(8.25554554 3.22124447)'), 8.25554554, 3.22124447);
INSERT INTO dbz_222_point VALUES (default,GeomFromText('POINT(0 0)'), 0.0, 0.0);
INSERT INTO dbz_222_point VALUES (default,NULL, 0.0, 0.0);

View File

@ -0,0 +1,140 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: json_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's JSON datatype.
-- DBZ-126 handle JSON column types ...
CREATE TABLE dbz_126_jsontable (
id INT AUTO_INCREMENT NOT NULL,
json JSON,
expectedJdbcStr VARCHAR(256), -- value that we get back from JDBC
expectedBinlogStr VARCHAR(256), -- value we parse from the binlog
PRIMARY KEY(id)
) DEFAULT CHARSET=utf8;
INSERT INTO dbz_126_jsontable VALUES (default,NULL,
NULL,
NULL);
INSERT INTO dbz_126_jsontable VALUES (default,'{"a": 2}',
'{"a": 2}',
'{"a":2}');
INSERT INTO dbz_126_jsontable VALUES (default,'[1, 2]',
'[1, 2]',
'[1,2]');
INSERT INTO dbz_126_jsontable VALUES (default,'{"key1": "value1", "key2": "value2"}',
'{"key1": "value1", "key2": "value2"}',
'{"key1":"value1","key2":"value2"}');
INSERT INTO dbz_126_jsontable VALUES (default,'["a", "b",1]',
'["a", "b",1]',
'["a","b",1]');
INSERT INTO dbz_126_jsontable VALUES (default,'{"k1": "v1", "k2": {"k21": "v21", "k22": "v22"}, "k3": ["a", "b", 1]}',
'{"k1": "v1", "k2": {"k21": "v21", "k22": "v22"}, "k3": ["a", "b", 1]}',
'{"k1":"v1","k2":{"k21":"v21","k22":"v22"},"k3":["a","b",1]}');
INSERT INTO dbz_126_jsontable VALUES (default,'{"a": "b", "c": "d", "ab": "abc", "bc": ["x", "y"]}',
'{"a": "b", "c": "d", "ab": "abc", "bc": ["x", "y"]}',
'{"a":"b","c":"d","ab":"abc","bc":["x","y"]}');
INSERT INTO dbz_126_jsontable VALUES (default,'["here", ["I", "am"], "!!!"]',
'["here", ["I", "am"], "!!!"]',
'["here",["I","am"],"!!!"]');
INSERT INTO dbz_126_jsontable VALUES (default,'"scalar string"',
'"scalar string"',
'"scalar string"');
INSERT INTO dbz_126_jsontable VALUES (default,'true',
'true',
'true');
INSERT INTO dbz_126_jsontable VALUES (default,'false',
'false',
'false');
INSERT INTO dbz_126_jsontable VALUES (default,'null',
'null',
'null');
INSERT INTO dbz_126_jsontable VALUES (default,'-1',
'-1',
'-1');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST(1 AS UNSIGNED) AS JSON),
'1',
'1');
INSERT INTO dbz_126_jsontable VALUES (default,'32767',
'32767',
'32767');
INSERT INTO dbz_126_jsontable VALUES (default,'32768',
'32768',
'32768');
INSERT INTO dbz_126_jsontable VALUES (default,'-32768',
'-32768',
'-32768');
INSERT INTO dbz_126_jsontable VALUES (default,'2147483647', -- INT32
'2147483647',
'2147483647');
INSERT INTO dbz_126_jsontable VALUES (default,'2147483648', -- INT64
'2147483648',
'2147483648');
INSERT INTO dbz_126_jsontable VALUES (default,'-2147483648', -- INT32
'-2147483648',
'-2147483648');
INSERT INTO dbz_126_jsontable VALUES (default,'-2147483649', -- INT64
'-2147483649',
'-2147483649');
INSERT INTO dbz_126_jsontable VALUES (default,'18446744073709551615', -- INT64
'18446744073709551615',
'18446744073709551615');
INSERT INTO dbz_126_jsontable VALUES (default,'18446744073709551616', -- BigInteger
'18446744073709551616',
'18446744073709551616');
INSERT INTO dbz_126_jsontable VALUES (default,'3.14',
'3.14',
'3.14');
INSERT INTO dbz_126_jsontable VALUES (default,'{}',
'{}',
'{}');
INSERT INTO dbz_126_jsontable VALUES (default,'[]',
'[]',
'[]');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25' AS DATETIME) AS JSON),
'"2015-01-15 23:24:25"',
'"2015-01-15 23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25.12' AS DATETIME(3)) AS JSON),
'"2015-01-15 23:24:25.12"',
'"2015-01-15 23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15 23:24:25.0237' AS DATETIME(3)) AS JSON),
'"2015-01-15 23:24:25.024"',
'"2015-01-15 23:24:25.024"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25' AS TIME) AS JSON),
'"23:24:25"',
'"23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25.12' AS TIME(3)) AS JSON),
'"23:24:25.12"',
'"23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('23:24:25.0237' AS TIME(3)) AS JSON),
'"23:24:25.024"',
'"23:24:25.024"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(CAST('2015-01-15' AS DATE) AS JSON),
'"2015-01-15"',
'"2015-01-15"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25' AS JSON),
'"2015-01-15 23:24:25"',
'"2015-01-15 23:24:25"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25.12' AS JSON),
'"2015-01-15 23:24:25.12"',
'"2015-01-15 23:24:25.12"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(TIMESTAMP'2015-01-15 23:24:25.0237' AS JSON),
'"2015-01-15 23:24:25.0237"',
'"2015-01-15 23:24:25.0237"');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(UNIX_TIMESTAMP('2015-01-15 23:24:25') AS JSON),
'1421364265',
'1421364265');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(ST_GeomFromText('POINT(1 1)') AS JSON),
'{\"type\": \"Point\", \"coordinates\": [1.0, 1.0]}',
'{\"type\":\"Point\",\"coordinates\":[1.0,1.0]}');
INSERT INTO dbz_126_jsontable VALUES (default,CAST('[]' AS CHAR CHARACTER SET 'ascii'),
'[]',
'[]');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(x'cafe' AS JSON), -- BLOB as Base64
'"yv4="',
'"yv4="');
INSERT INTO dbz_126_jsontable VALUES (default,CAST(x'cafebabe' AS JSON), -- BLOB as Base64
'"yv66vg=="',
'"yv66vg=="');

View File

@ -0,0 +1,23 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: readbinlog_test
-- Database needs to be populated to break dependency between MetadataIT and MySqlConnectorIT.shouldValidateAcceptableConfiguration run order
-- ----------------------------------------------------------------------------------------------------------------
CREATE TABLE person (
name VARCHAR(255) primary key,
birthdate DATE NULL,
age INTEGER NULL DEFAULT 10,
salary DECIMAL(5,2), bitStr BIT(18)
);
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
createdByDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
modifiedDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
CREATE TABLE purchased (
purchaser VARCHAR(255) NOT NULL,
productId INT NOT NULL,
purchaseDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(productId,purchaser)
);

View File

@ -0,0 +1,147 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: regression_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
-- DBZ-61 handle binary value recorded as hex string value
CREATE TABLE t1464075356413_testtable6 (
pk_column int auto_increment NOT NULL,
varbinary_col varbinary(20) NOT NULL,
PRIMARY KEY(pk_column)
);
INSERT INTO t1464075356413_testtable6 (pk_column, varbinary_col)
VALUES(default, 0x4D7953514C);
-- DBZ-84 Handle TINYINT
CREATE TABLE dbz84_integer_types_table (
-- The column lengths are used for display purposes, and do not affect the range of values
colTinyIntA tinyint NOT NULL DEFAULT 100,
colTinyIntB tinyint(1) NOT NULL DEFAULT 101,
colTinyIntC tinyint(2) UNSIGNED NOT NULL DEFAULT 102,
colTinyIntD tinyint(3) UNSIGNED NOT NULL DEFAULT 103,
colSmallIntA smallint NOT NULL DEFAULT 200,
colSmallIntB smallint(1) NOT NULL DEFAULT 201,
colSmallIntC smallint(2) NOT NULL DEFAULT 201,
colSmallIntD smallint(3) NOT NULL DEFAULT 201,
colMediumIntA mediumint NOT NULL DEFAULT 300,
colMediumIntB mediumint(1) NOT NULL DEFAULT 301,
colMediumIntC mediumint(2) NOT NULL DEFAULT 302,
colMediumIntD mediumint(3) NOT NULL DEFAULT 303,
colIntA int NOT NULL DEFAULT 400,
colIntB int(1) NOT NULL DEFAULT 401,
colIntC int(2) NOT NULL DEFAULT 402,
colIntD int(3) NOT NULL DEFAULT 403,
colBigIntA bigint NOT NULL DEFAULT 500,
colBigIntB bigint(1) NOT NULL DEFAULT 501,
colBigIntC bigint(2) NOT NULL DEFAULT 502,
colBigIntD bigint(3) NOT NULL DEFAULT 503
);
INSERT INTO dbz84_integer_types_table
VALUES(127,-128,128,255, default,201,202,203, default,301,302,303, default,401,402,403, default,501,502,503);
-- DBZ-85 handle fractional part of seconds
CREATE TABLE dbz_85_fractest (
c1 DATE,
c2 TIME(2),
c3 DATETIME(2),
c4 TIMESTAMP(2)
);
INSERT INTO dbz_85_fractest VALUES ('2014-09-08', '17:51:04.777', '2014-09-08 17:51:04.777', '2014-09-08 17:51:04.777');
-- DBZ-100 handle enum and set
CREATE TABLE dbz_100_enumsettest (
c1 ENUM('a','b','c'),
c2 SET('a','b','c')
);
INSERT INTO dbz_100_enumsettest VALUES ('a', 'a,b,c');
INSERT INTO dbz_100_enumsettest VALUES ('b', 'b,a');
INSERT INTO dbz_100_enumsettest VALUES ('c', 'a');
-- DBZ-102 handle character sets
-- Use session variables to dictate the character sets used by the client running these commands so
-- the literal value is interpretted correctly...
set character_set_client=utf8;
set character_set_connection=utf8;
CREATE TABLE dbz_102_charsettest (
id INT(11) NOT NULL AUTO_INCREMENT,
text VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2001 DEFAULT CHARSET=utf8;
INSERT INTO dbz_102_charsettest VALUES (default, "产品");
-- DBZ-114 handle zero-value dates
CREATE TABLE dbz_114_zerovaluetest (
c1 DATE,
c2 TIME(2),
c3 DATETIME(2),
c4 TIMESTAMP(2)
);
INSERT IGNORE INTO dbz_114_zerovaluetest VALUES ('0000-00-00', '00:00:00.000', '0000-00-00 00:00:00.000', '0000-00-00 00:00:00.000');
INSERT IGNORE INTO dbz_114_zerovaluetest VALUES ('0001-00-00', '00:01:00.000', '0001-00-00 00:00:00.000', '0001-00-00 00:00:00.000');
-- DBZ-123 handle bit values, including bit field literals
CREATE TABLE dbz_123_bitvaluetest (
c1 BIT,
c2 BIT(2),
c3 BIT(8) NOT NULL,
c4 BIT(64)
);
INSERT INTO dbz_123_bitvaluetest VALUES (1,2,64,23989979);
INSERT INTO dbz_123_bitvaluetest VALUES (b'1',b'10',b'01000000',b'1011011100000111011011011');
-- DBZ-104 handle create table like ...
DROP DATABASE IF EXISTS connector_test;
CREATE DATABASE connector_test;
CREATE TABLE connector_test.customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE KEY
) AUTO_INCREMENT=1001;
INSERT INTO connector_test.customers
VALUES (default,"Sally","Thomas","sally.thomas@acme.com"),
(default,"George","Bailey","gbailey@foobar.com"),
(default,"Edward","Walker","ed@walker.com"),
(default,"Anne","Kretchmar","annek@noanswer.org");
CREATE TABLE dbz_104_customers LIKE connector_test.customers;
INSERT INTO dbz_104_customers SELECT * FROM connector_test.customers;
-- DBZ-147 handle decimal value
CREATE TABLE dbz_147_decimalvalues (
pk_column int auto_increment NOT NULL,
decimal_value decimal(7,2) NOT NULL,
PRIMARY KEY(pk_column)
);
INSERT INTO dbz_147_decimalvalues (pk_column, decimal_value)
VALUES(default, 12345.67);
-- DBZ-162 handle function declarations with newline characters
CREATE FUNCTION fnDbz162( p_creditLimit DOUBLE ) RETURNS VARCHAR(10)
DETERMINISTIC
BEGIN
DECLARE lvl VARCHAR(10)$$
IF p_creditLimit > 50000 THEN
SET lvl = 'PLATINUM'$$
ELSEIF (p_creditLimit <= 50000 AND p_creditLimit >= 10000) THEN
SET lvl = 'GOLD'$$
ELSEIF p_creditLimit < 10000 THEN
SET lvl = 'SILVER'$$
END IF$$
RETURN (lvl)$$
END$$
;
-- DBZ-195 handle numeric values
CREATE TABLE dbz_195_numvalues (
id int auto_increment NOT NULL,
`search_version_read` int(11) NOT NULL DEFAULT '0', -- (11) is the display width
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4972 DEFAULT CHARSET=utf8;
INSERT INTO dbz_195_numvalues VALUES (default,0);
INSERT INTO dbz_195_numvalues VALUES (default,-2147483648);
INSERT INTO dbz_195_numvalues VALUES (default,2147483647);

View File

@ -0,0 +1,17 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: table_maintenance_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
CREATE TABLE dbz_253_table_maintenance_test (
id INT AUTO_INCREMENT NOT NULL,
other int,
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;
ANALYZE TABLE dbz_253_table_maintenance_test;
OPTIMIZE TABLE dbz_253_table_maintenance_test;
REPAIR TABLE dbz_253_table_maintenance_test;

View File

@ -0,0 +1,74 @@
-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: unsigned_integer_test
-- ----------------------------------------------------------------------------------------------------------------
-- The integration test for this database expects to scan all of the binlog events associated with this database
-- without error or problems. The integration test does not modify any records in this database, so this script
-- must contain all operations to these tables.
--
-- This relies upon MySQL 5.7's Geometries datatypes.
-- DBZ-228 handle unsigned TINYINT UNSIGNED
CREATE TABLE dbz_228_tinyint_unsigned (
id int auto_increment NOT NULL,
c1 TINYINT(3) UNSIGNED ZEROFILL NOT NULL,
c2 TINYINT(3) UNSIGNED NOT NULL,
c3 TINYINT(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 255, 255, 127);
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 155, 155, -100);
INSERT INTO dbz_228_tinyint_unsigned VALUES (default, 0, 0, -128);
-- DBZ-228 handle unsigned SMALLINT UNSIGNED
CREATE TABLE dbz_228_smallint_unsigned (
id int auto_increment NOT NULL,
c1 SMALLINT UNSIGNED ZEROFILL NOT NULL,
c2 SMALLINT UNSIGNED NOT NULL,
c3 SMALLINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 65535, 65535, 32767);
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 45535, 45535, -12767);
INSERT INTO dbz_228_smallint_unsigned VALUES (default, 0, 0, -32768);
-- DBZ-228 handle unsigned MEDIUMINT UNSIGNED
CREATE TABLE dbz_228_mediumint_unsigned (
id int auto_increment NOT NULL,
c1 MEDIUMINT UNSIGNED ZEROFILL NOT NULL,
c2 MEDIUMINT UNSIGNED NOT NULL,
c3 MEDIUMINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 16777215, 16777215, 8388607);
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 10777215, 10777215, -6388607);
INSERT INTO dbz_228_mediumint_unsigned VALUES (default, 0, 0, -8388608);
-- DBZ-228 handle unsigned INT UNSIGNED
CREATE TABLE dbz_228_int_unsigned (
id int auto_increment NOT NULL,
c1 int(11) UNSIGNED ZEROFILL NOT NULL,
c2 int(11) UNSIGNED NOT NULL,
c3 int(11) NOT NULL,
c4 int(5) UNSIGNED ZEROFILL NOT NULL,
c5 int(5) UNSIGNED NOT NULL ,
c6 int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_int_unsigned VALUES (default, 4294967295, 4294967295, 2147483647, 4294967295, 4294967295, 2147483647);
INSERT INTO dbz_228_int_unsigned VALUES (default, 3294967295, 3294967295, -1147483647, 3294967295, 3294967295, -1147483647);
INSERT INTO dbz_228_int_unsigned VALUES (default, 0, 0, -2147483648, 0, 0, -2147483648);
-- DBZ-228 handle unsigned BIGINT UNSIGNED
CREATE TABLE dbz_228_bigint_unsigned (
id int auto_increment NOT NULL,
c1 BIGINT UNSIGNED ZEROFILL NOT NULL,
c2 BIGINT UNSIGNED NOT NULL,
c3 BIGINT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 18446744073709551615, 18446744073709551615, 9223372036854775807);
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 14446744073709551615, 14446744073709551615, -1223372036854775807);
INSERT INTO dbz_228_bigint_unsigned VALUES (default, 0, 0, -9223372036854775808);