@@ -301,7 +301,15 @@ async fn cdc_streaming() {
301
301
) ;
302
302
303
303
let mut actual_users = read_all_rows ( & client, namespace. to_string ( ) , users_table. clone ( ) ) . await ;
304
- // Drop the last column (non-deterministic sequence) before comparison.
304
+
305
+ // Sort deterministically by the primary key (id) and sequence number for stable assertions
306
+ actual_users. sort_by ( |a, b| {
307
+ let a_key = format ! ( "{:?}_{:?}" , a. values[ 0 ] , a. values[ 4 ] ) ;
308
+ let b_key = format ! ( "{:?}_{:?}" , b. values[ 0 ] , b. values[ 4 ] ) ;
309
+ a_key. cmp ( & b_key)
310
+ } ) ;
311
+
312
+ // Drop the last column (non-deterministic sequence number) before comparison.
305
313
for row in & mut actual_users {
306
314
let _ = row. values . pop ( ) ;
307
315
}
@@ -310,13 +318,13 @@ async fn cdc_streaming() {
310
318
// Note: order here is messed up due to limitations in how read_all_rows can't sort, so we sort manually
311
319
// by id and cdc operation columns
312
320
let expected_users = vec ! [
313
- // Delete of user with id 1
321
+ // Initial insert of user 1
314
322
TableRow {
315
323
values: vec![
316
324
Cell :: I64 ( 1 ) ,
317
- Cell :: String ( "" . to_string( ) ) ,
318
- Cell :: I32 ( 0 ) ,
319
- Cell :: String ( "DELETE " . to_string( ) ) ,
325
+ Cell :: String ( "user_1 " . to_string( ) ) ,
326
+ Cell :: I32 ( 1 ) ,
327
+ Cell :: String ( "UPSERT " . to_string( ) ) ,
320
328
] ,
321
329
} ,
322
330
// Update of user 1
@@ -328,52 +336,48 @@ async fn cdc_streaming() {
328
336
Cell :: String ( "UPSERT" . to_string( ) ) ,
329
337
] ,
330
338
} ,
331
- // Initial insert of user 1
339
+ // Delete of user with id 1
332
340
TableRow {
333
341
values: vec![
334
342
Cell :: I64 ( 1 ) ,
335
- Cell :: String ( "user_1 " . to_string( ) ) ,
336
- Cell :: I32 ( 1 ) ,
337
- Cell :: String ( "UPSERT " . to_string( ) ) ,
343
+ Cell :: String ( "" . to_string( ) ) ,
344
+ Cell :: I32 ( 0 ) ,
345
+ Cell :: String ( "DELETE " . to_string( ) ) ,
338
346
] ,
339
347
} ,
340
- // Update of user 2
348
+ // Initial insert of user 2
341
349
TableRow {
342
350
values: vec![
343
351
Cell :: I64 ( 2 ) ,
344
- Cell :: String ( "updated_name " . to_string( ) ) ,
345
- Cell :: I32 ( 42 ) ,
352
+ Cell :: String ( "user_2 " . to_string( ) ) ,
353
+ Cell :: I32 ( 2 ) ,
346
354
Cell :: String ( "UPSERT" . to_string( ) ) ,
347
355
] ,
348
356
} ,
349
- // Initial insert of user 2
357
+ // Update of user 2
350
358
TableRow {
351
359
values: vec![
352
360
Cell :: I64 ( 2 ) ,
353
- Cell :: String ( "user_2 " . to_string( ) ) ,
354
- Cell :: I32 ( 2 ) ,
361
+ Cell :: String ( "updated_name " . to_string( ) ) ,
362
+ Cell :: I32 ( 42 ) ,
355
363
Cell :: String ( "UPSERT" . to_string( ) ) ,
356
364
] ,
357
365
} ,
358
366
] ;
359
367
360
- // Sort deterministically by the primary key (id) and operation for stable assertions.
361
- actual_users. sort_by ( |a, b| {
362
- let a_key = format ! (
363
- "{:?}_{:?}_{:?}_{:?}" ,
364
- a. values[ 0 ] , a. values[ 1 ] , a. values[ 2 ] , a. values[ 3 ]
365
- ) ;
366
- let b_key = format ! (
367
- "{:?}_{:?}_{:?}_{:?}" ,
368
- b. values[ 0 ] , b. values[ 1 ] , b. values[ 2 ] , b. values[ 3 ]
369
- ) ;
370
- a_key. cmp ( & b_key)
371
- } ) ;
372
368
assert_eq ! ( actual_users, expected_users) ;
373
369
374
370
let mut actual_orders =
375
371
read_all_rows ( & client, namespace. to_string ( ) , orders_table. clone ( ) ) . await ;
376
- // Drop the last column (non-deterministic sequence) before comparison.
372
+
373
+ // Sort deterministically by the primary key (id) and sequence number for stable assertions
374
+ actual_orders. sort_by ( |a, b| {
375
+ let a_key = format ! ( "{:?}_{:?}" , a. values[ 0 ] , a. values[ 3 ] ) ;
376
+ let b_key = format ! ( "{:?}_{:?}" , b. values[ 0 ] , b. values[ 3 ] ) ;
377
+ a_key. cmp ( & b_key)
378
+ } ) ;
379
+
380
+ // Drop the last column (non-deterministic sequence number) before comparison.
377
381
for row in & mut actual_orders {
378
382
let _ = row. values . pop ( ) ;
379
383
}
@@ -395,14 +399,6 @@ async fn cdc_streaming() {
395
399
Cell :: String ( "UPSERT" . to_string( ) ) ,
396
400
] ,
397
401
} ,
398
- // Delete of order 2
399
- TableRow {
400
- values: vec![
401
- Cell :: I64 ( 2 ) ,
402
- Cell :: String ( "" . to_string( ) ) ,
403
- Cell :: String ( "DELETE" . to_string( ) ) ,
404
- ] ,
405
- } ,
406
402
// Initial insert of order 2
407
403
TableRow {
408
404
values: vec![
@@ -419,13 +415,16 @@ async fn cdc_streaming() {
419
415
Cell :: String ( "UPSERT" . to_string( ) ) ,
420
416
] ,
421
417
} ,
418
+ // Delete of order 2
419
+ TableRow {
420
+ values: vec![
421
+ Cell :: I64 ( 2 ) ,
422
+ Cell :: String ( "" . to_string( ) ) ,
423
+ Cell :: String ( "DELETE" . to_string( ) ) ,
424
+ ] ,
425
+ } ,
422
426
] ;
423
427
424
- actual_orders. sort_by ( |a, b| {
425
- let a_key = format ! ( "{:?}_{:?}_{:?}" , a. values[ 0 ] , a. values[ 1 ] , a. values[ 2 ] ) ;
426
- let b_key = format ! ( "{:?}_{:?}_{:?}" , b. values[ 0 ] , b. values[ 1 ] , b. values[ 2 ] ) ;
427
- a_key. cmp ( & b_key)
428
- } ) ;
429
428
assert_eq ! ( actual_orders, expected_orders) ;
430
429
431
430
// Stop the pipeline to finalize writes.
0 commit comments