|
48 | 48 | import java.util.List; |
49 | 49 | import java.util.Optional; |
50 | 50 |
|
51 | | -public class JdbcSourceChunkSplitterTest { |
| 51 | +class JdbcSourceChunkSplitterTest { |
52 | 52 |
|
53 | 53 | @Test |
54 | | - public void splitColumnTest() throws SQLException { |
| 54 | + void splitColumnTest() throws SQLException { |
55 | 55 | TestJdbcSourceChunkSplitter testJdbcSourceChunkSplitter = |
56 | 56 | new TestJdbcSourceChunkSplitter(null, new TestSourceDialect()); |
57 | 57 | Column splitColumn = |
58 | 58 | testJdbcSourceChunkSplitter.getSplitColumn( |
59 | 59 | null, new TestSourceDialect(), new TableId("", "", "")); |
60 | | - Assertions.assertEquals(splitColumn.typeName(), "tinyint"); |
| 60 | + Assertions.assertEquals("varchar", splitColumn.typeName()); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void splitColumnTestWithUniqueKey() throws SQLException { |
| 65 | + TestJdbcSourceChunkSplitter testJdbcSourceChunkSplitter = |
| 66 | + new TestJdbcSourceChunkSplitter(null, new TestSourceDialectWithUniqueKey()); |
| 67 | + Column splitColumn = |
| 68 | + testJdbcSourceChunkSplitter.getSplitColumn( |
| 69 | + null, new TestSourceDialectWithUniqueKey(), new TableId("", "", "")); |
| 70 | + Assertions.assertEquals("bigint", splitColumn.typeName()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void splitColumnTestWithUniqueKey_2() throws SQLException { |
| 75 | + TestJdbcSourceChunkSplitter testJdbcSourceChunkSplitter = |
| 76 | + new TestJdbcSourceChunkSplitter(null, new TestSourceDialectWithUniqueKey_2()); |
| 77 | + Column splitColumn = |
| 78 | + testJdbcSourceChunkSplitter.getSplitColumn( |
| 79 | + null, new TestSourceDialectWithUniqueKey_2(), new TableId("", "", "")); |
| 80 | + Assertions.assertEquals("int", splitColumn.typeName()); |
61 | 81 | } |
62 | 82 |
|
63 | 83 | private class TestJdbcSourceChunkSplitter extends AbstractJdbcSourceChunkSplitter { |
@@ -247,4 +267,66 @@ public List<ConstraintKey> getUniqueKeys(JdbcConnection jdbcConnection, TableId |
247 | 267 | return new ArrayList<ConstraintKey>(); |
248 | 268 | } |
249 | 269 | } |
| 270 | + |
| 271 | + private class TestSourceDialectWithUniqueKey extends TestSourceDialect { |
| 272 | + |
| 273 | + @Override |
| 274 | + public Optional<PrimaryKey> getPrimaryKey(JdbcConnection jdbcConnection, TableId tableId) |
| 275 | + throws SQLException { |
| 276 | + return Optional.of(PrimaryKey.of("pkName", Arrays.asList("bigint_col"))); |
| 277 | + } |
| 278 | + |
| 279 | + @Override |
| 280 | + public List<ConstraintKey> getUniqueKeys(JdbcConnection jdbcConnection, TableId tableId) |
| 281 | + throws SQLException { |
| 282 | + List<ConstraintKey> keys = new ArrayList<>(); |
| 283 | + |
| 284 | + keys.add( |
| 285 | + ConstraintKey.of( |
| 286 | + ConstraintKey.ConstraintType.UNIQUE_KEY, |
| 287 | + "uk_1", |
| 288 | + Arrays.asList( |
| 289 | + ConstraintKey.ConstraintKeyColumn.of( |
| 290 | + "string_col", ConstraintKey.ColumnSortType.ASC), |
| 291 | + ConstraintKey.ConstraintKeyColumn.of( |
| 292 | + "int", ConstraintKey.ColumnSortType.ASC)))); |
| 293 | + |
| 294 | + return keys; |
| 295 | + } |
| 296 | + } |
| 297 | + |
| 298 | + private class TestSourceDialectWithUniqueKey_2 extends TestSourceDialect { |
| 299 | + |
| 300 | + @Override |
| 301 | + public Optional<PrimaryKey> getPrimaryKey(JdbcConnection jdbcConnection, TableId tableId) |
| 302 | + throws SQLException { |
| 303 | + return Optional.of(PrimaryKey.of("pkName", Arrays.asList("bigint_col"))); |
| 304 | + } |
| 305 | + |
| 306 | + @Override |
| 307 | + public List<ConstraintKey> getUniqueKeys(JdbcConnection jdbcConnection, TableId tableId) |
| 308 | + throws SQLException { |
| 309 | + List<ConstraintKey> keys = new ArrayList<>(); |
| 310 | + |
| 311 | + keys.add( |
| 312 | + ConstraintKey.of( |
| 313 | + ConstraintKey.ConstraintType.UNIQUE_KEY, |
| 314 | + "uk_1", |
| 315 | + Arrays.asList( |
| 316 | + ConstraintKey.ConstraintKeyColumn.of( |
| 317 | + "string_col", ConstraintKey.ColumnSortType.ASC)))); |
| 318 | + |
| 319 | + keys.add( |
| 320 | + ConstraintKey.of( |
| 321 | + ConstraintKey.ConstraintType.UNIQUE_KEY, |
| 322 | + "uk_2", |
| 323 | + Arrays.asList( |
| 324 | + ConstraintKey.ConstraintKeyColumn.of( |
| 325 | + "int", ConstraintKey.ColumnSortType.ASC), |
| 326 | + ConstraintKey.ConstraintKeyColumn.of( |
| 327 | + "smallint", ConstraintKey.ColumnSortType.ASC)))); |
| 328 | + |
| 329 | + return keys; |
| 330 | + } |
| 331 | + } |
250 | 332 | } |
0 commit comments