27
27
import org .junit .Before ;
28
28
import org .junit .ClassRule ;
29
29
import org .junit .Test ;
30
+ import org .junit .runner .RunWith ;
31
+ import org .junit .runners .Parameterized ;
30
32
31
33
import java .sql .Connection ;
32
34
import java .sql .SQLException ;
36
38
import java .util .List ;
37
39
import java .util .concurrent .ExecutionException ;
38
40
41
+ import static org .apache .flink .api .common .JobStatus .RUNNING ;
39
42
import static org .hamcrest .Matchers .containsInAnyOrder ;
40
43
import static org .junit .Assert .assertEquals ;
41
44
import static org .junit .Assert .assertThat ;
42
45
import static org .testcontainers .containers .MSSQLServerContainer .MS_SQL_SERVER_PORT ;
43
46
44
47
/** Integration tests for SqlServer Table source. */
48
+ @ RunWith (Parameterized .class )
45
49
public class SqlServerConnectorITCase extends SqlServerTestBase {
46
50
47
51
private final StreamExecutionEnvironment env =
@@ -52,10 +56,28 @@ public class SqlServerConnectorITCase extends SqlServerTestBase {
52
56
53
57
@ ClassRule public static LegacyRowResource usesLegacyRows = LegacyRowResource .INSTANCE ;
54
58
59
+ // enable the parallelismSnapshot (i.e: The new source OracleParallelSource)
60
+ private final boolean parallelismSnapshot ;
61
+
62
+ public SqlServerConnectorITCase (boolean parallelismSnapshot ) {
63
+ this .parallelismSnapshot = parallelismSnapshot ;
64
+ }
65
+
66
+ @ Parameterized .Parameters (name = "parallelismSnapshot: {0}" )
67
+ public static Object [] parameters () {
68
+ return new Object [][] {new Object [] {false }, new Object [] {true }};
69
+ }
70
+
55
71
@ Before
56
72
public void before () {
57
73
TestValuesTableFactory .clearAllData ();
58
- env .setParallelism (1 );
74
+
75
+ if (parallelismSnapshot ) {
76
+ env .setParallelism (4 );
77
+ env .enableCheckpointing (200 );
78
+ } else {
79
+ env .setParallelism (1 );
80
+ }
59
81
}
60
82
61
83
@ Test
@@ -75,13 +97,15 @@ public void testConsumingAllEvents()
75
97
+ " 'port' = '%s',"
76
98
+ " 'username' = '%s',"
77
99
+ " 'password' = '%s',"
100
+ + " 'scan.incremental.snapshot.enabled' = '%s',"
78
101
+ " 'database-name' = '%s',"
79
102
+ " 'table-name' = '%s'"
80
103
+ ")" ,
81
104
MSSQL_SERVER_CONTAINER .getHost (),
82
105
MSSQL_SERVER_CONTAINER .getMappedPort (MS_SQL_SERVER_PORT ),
83
106
MSSQL_SERVER_CONTAINER .getUsername (),
84
107
MSSQL_SERVER_CONTAINER .getPassword (),
108
+ parallelismSnapshot ,
85
109
"inventory" ,
86
110
"dbo.products" );
87
111
String sinkDDL =
@@ -160,6 +184,82 @@ public void testConsumingAllEvents()
160
184
result .getJobClient ().get ().cancel ().get ();
161
185
}
162
186
187
+ @ Test
188
+ public void testStartupFromLatestOffset () throws Exception {
189
+ initializeSqlServerTable ("inventory" );
190
+
191
+ Connection connection = getJdbcConnection ();
192
+ Statement statement = connection .createStatement ();
193
+
194
+ // The following two change records will be discarded in the 'latest-offset' mode
195
+ statement .execute (
196
+ "INSERT INTO inventory.dbo.products (name,description,weight) VALUES ('jacket','water resistent white wind breaker',0.2);" ); // 110
197
+ statement .execute (
198
+ "INSERT INTO inventory.dbo.products (name,description,weight) VALUES ('scooter','Big 2-wheel scooter ',5.18);" );
199
+ Thread .sleep (5000L );
200
+
201
+ String sourceDDL =
202
+ String .format (
203
+ "CREATE TABLE debezium_source ("
204
+ + " id INT NOT NULL,"
205
+ + " name STRING,"
206
+ + " description STRING,"
207
+ + " weight DECIMAL(10,3)"
208
+ + ") WITH ("
209
+ + " 'connector' = 'sqlserver-cdc',"
210
+ + " 'hostname' = '%s',"
211
+ + " 'port' = '%s',"
212
+ + " 'username' = '%s',"
213
+ + " 'password' = '%s',"
214
+ + " 'scan.incremental.snapshot.enabled' = '%s',"
215
+ + " 'database-name' = '%s',"
216
+ + " 'table-name' = '%s',"
217
+ + " 'scan.startup.mode' = 'latest-offset'"
218
+ + ")" ,
219
+ MSSQL_SERVER_CONTAINER .getHost (),
220
+ MSSQL_SERVER_CONTAINER .getMappedPort (MS_SQL_SERVER_PORT ),
221
+ MSSQL_SERVER_CONTAINER .getUsername (),
222
+ MSSQL_SERVER_CONTAINER .getPassword (),
223
+ parallelismSnapshot ,
224
+ "inventory" ,
225
+ "dbo.products" );
226
+ String sinkDDL =
227
+ "CREATE TABLE sink "
228
+ + " WITH ("
229
+ + " 'connector' = 'values',"
230
+ + " 'sink-insert-only' = 'false'"
231
+ + ") LIKE debezium_source (EXCLUDING OPTIONS)" ;
232
+ tEnv .executeSql (sourceDDL );
233
+ tEnv .executeSql (sinkDDL );
234
+
235
+ // async submit job
236
+ TableResult result = tEnv .executeSql ("INSERT INTO sink SELECT * FROM debezium_source" );
237
+
238
+ // wait for the source startup, we don't have a better way to wait it, use sleep for now
239
+ do {
240
+ Thread .sleep (5000L );
241
+ } while (result .getJobClient ().get ().getJobStatus ().get () != RUNNING );
242
+ Thread .sleep (30000L );
243
+
244
+ statement .execute (
245
+ "INSERT INTO inventory.dbo.products (name,description,weight) VALUES ('hammer','18oz carpenters hammer',1.2);" );
246
+ statement .execute (
247
+ "INSERT INTO inventory.dbo.products (name,description,weight) VALUES ('scooter','Big 3-wheel scooter',5.20);" );
248
+
249
+ waitForSinkSize ("sink" , 2 );
250
+
251
+ String [] expected =
252
+ new String [] {
253
+ "112,hammer,18oz carpenters hammer,1.200" ,
254
+ "113,scooter,Big 3-wheel scooter,5.200"
255
+ };
256
+
257
+ List <String > actual = TestValuesTableFactory .getResults ("sink" );
258
+ assertThat (actual , containsInAnyOrder (expected ));
259
+
260
+ result .getJobClient ().get ().cancel ().get ();
261
+ }
262
+
163
263
@ Test
164
264
public void testAllTypes () throws Throwable {
165
265
initializeSqlServerTable ("column_type_test" );
@@ -199,13 +299,15 @@ public void testAllTypes() throws Throwable {
199
299
+ " 'port' = '%s',"
200
300
+ " 'username' = '%s',"
201
301
+ " 'password' = '%s',"
302
+ + " 'scan.incremental.snapshot.enabled' = '%s',"
202
303
+ " 'database-name' = '%s',"
203
304
+ " 'table-name' = '%s'"
204
305
+ ")" ,
205
306
MSSQL_SERVER_CONTAINER .getHost (),
206
307
MSSQL_SERVER_CONTAINER .getMappedPort (MS_SQL_SERVER_PORT ),
207
308
MSSQL_SERVER_CONTAINER .getUsername (),
208
309
MSSQL_SERVER_CONTAINER .getPassword (),
310
+ parallelismSnapshot ,
209
311
"column_type_test" ,
210
312
"dbo.full_types" );
211
313
String sinkDDL =
@@ -288,13 +390,15 @@ public void testMetadataColumns() throws Throwable {
288
390
+ " 'port' = '%s',"
289
391
+ " 'username' = '%s',"
290
392
+ " 'password' = '%s',"
393
+ + " 'scan.incremental.snapshot.enabled' = '%s',"
291
394
+ " 'database-name' = '%s',"
292
395
+ " 'table-name' = '%s'"
293
396
+ ")" ,
294
397
MSSQL_SERVER_CONTAINER .getHost (),
295
398
MSSQL_SERVER_CONTAINER .getMappedPort (MS_SQL_SERVER_PORT ),
296
399
MSSQL_SERVER_CONTAINER .getUsername (),
297
400
MSSQL_SERVER_CONTAINER .getPassword (),
401
+ parallelismSnapshot ,
298
402
"inventory" ,
299
403
"dbo.products" );
300
404
0 commit comments