Skip to content

Commit 3917b37

Browse files
committed
add unit test
1 parent ebe3a3f commit 3917b37

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlDataSourceFactoryTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.apache.flink.cdc.connectors.mysql.source.MySqlDataSourceOptions.SCAN_INCREMENTAL_SNAPSHOT_CHUNK_KEY_COLUMN;
4444
import static org.apache.flink.cdc.connectors.mysql.source.MySqlDataSourceOptions.TABLES;
4545
import static org.apache.flink.cdc.connectors.mysql.source.MySqlDataSourceOptions.TABLES_EXCLUDE;
46+
import static org.apache.flink.cdc.connectors.mysql.source.MySqlDataSourceOptions.TREAT_TINYINT1_AS_BOOLEAN_ENABLED;
4647
import static org.apache.flink.cdc.connectors.mysql.source.MySqlDataSourceOptions.USERNAME;
4748
import static org.apache.flink.cdc.connectors.mysql.source.config.MySqlSourceOptions.SCAN_NEWLY_ADDED_TABLE_ENABLED;
4849
import static org.apache.flink.cdc.connectors.mysql.testutils.MySqSourceTestUtils.TEST_PASSWORD;
@@ -232,7 +233,6 @@ public void testUnsupportedOption() {
232233
options.put(USERNAME.key(), TEST_USER);
233234
options.put(PASSWORD.key(), TEST_PASSWORD);
234235
options.put(TABLES.key(), inventoryDatabase.getDatabaseName() + ".prod\\.*");
235-
options.put("unsupported_key", "unsupported_value");
236236

237237
MySqlDataSourceFactory factory = new MySqlDataSourceFactory();
238238
Factory.Context context = new MockContext(Configuration.fromMap(options));
@@ -245,6 +245,27 @@ public void testUnsupportedOption() {
245245
+ "unsupported_key");
246246
}
247247

248+
@Test
249+
public void testOptionalOption() {
250+
Map<String, String> options = new HashMap<>();
251+
options.put(HOSTNAME.key(), MYSQL_CONTAINER.getHost());
252+
options.put(PORT.key(), String.valueOf(MYSQL_CONTAINER.getDatabasePort()));
253+
options.put(USERNAME.key(), TEST_USER);
254+
options.put(PASSWORD.key(), TEST_PASSWORD);
255+
options.put(TABLES.key(), inventoryDatabase.getDatabaseName() + ".prod\\.*");
256+
257+
// optional option
258+
options.put(TREAT_TINYINT1_AS_BOOLEAN_ENABLED.key(), "false");
259+
260+
Factory.Context context = new MockContext(Configuration.fromMap(options));
261+
MySqlDataSourceFactory factory = new MySqlDataSourceFactory();
262+
assertThat(factory.optionalOptions().contains(TREAT_TINYINT1_AS_BOOLEAN_ENABLED))
263+
.isEqualTo(true);
264+
265+
MySqlDataSource dataSource = (MySqlDataSource) factory.createDataSource(context);
266+
assertThat(dataSource.getSourceConfig().isTreatTinyInt1AsBoolean()).isEqualTo(false);
267+
}
268+
248269
@Test
249270
public void testPrefixRequireOption() {
250271
inventoryDatabase.createAndInitialize();

0 commit comments

Comments
 (0)