@@ -395,34 +395,36 @@ describe("StandardMetadataManager", () => {
395
395
const update = metadataUpdates [ 0 ] ! ;
396
396
const operations = update . operations ! ;
397
397
398
- // Should have: 1 collapsed increment, 1 collapsed set, 2 appends
399
- // (delete operations on non-existent keys are not queued)
400
- expect ( operations ) . toHaveLength ( 4 ) ;
401
-
402
- // Find each operation type
403
- const incrementOp = operations . find ( ( op ) => op . type === "increment" ) ;
404
- const setOp = operations . find ( ( op ) => op . type === "set" ) ;
405
- const appendOps = operations . filter ( ( op ) => op . type === "append" ) ;
398
+ // With order-preserving collapse, expect 6 operations:
399
+ // increment(counter, 5), set(status, processing), append(logs, ...), increment(counter, 3), set(status, completed), append(logs, ...)
400
+ expect ( operations ) . toHaveLength ( 6 ) ;
406
401
407
- expect ( incrementOp ) . toEqual ( {
402
+ expect ( operations [ 0 ] ) . toEqual ( {
408
403
type : "increment" ,
409
404
key : "counter" ,
410
- value : 8 , // 5 + 3
405
+ value : 5 ,
411
406
} ) ;
412
-
413
- expect ( setOp ) . toEqual ( {
407
+ expect ( operations [ 1 ] ) . toEqual ( {
414
408
type : "set" ,
415
409
key : "status" ,
416
- value : "completed" , // Last set value
410
+ value : "processing" ,
417
411
} ) ;
418
-
419
- expect ( appendOps ) . toHaveLength ( 2 ) ;
420
- expect ( appendOps [ 0 ] ) . toEqual ( {
412
+ expect ( operations [ 2 ] ) . toEqual ( {
421
413
type : "append" ,
422
414
key : "logs" ,
423
415
value : "Started processing" ,
424
416
} ) ;
425
- expect ( appendOps [ 1 ] ) . toEqual ( {
417
+ expect ( operations [ 3 ] ) . toEqual ( {
418
+ type : "increment" ,
419
+ key : "counter" ,
420
+ value : 3 ,
421
+ } ) ;
422
+ expect ( operations [ 4 ] ) . toEqual ( {
423
+ type : "set" ,
424
+ key : "status" ,
425
+ value : "completed" ,
426
+ } ) ;
427
+ expect ( operations [ 5 ] ) . toEqual ( {
426
428
type : "append" ,
427
429
key : "logs" ,
428
430
value : "Processing completed" ,
@@ -454,42 +456,48 @@ describe("StandardMetadataManager", () => {
454
456
const update = metadataUpdates [ 1 ] ! ;
455
457
const operations = update . operations ! ;
456
458
457
- // Should have: 1 collapsed increment, 1 collapsed set, 2 appends, 2 collapsed deletes
458
- expect ( operations ) . toHaveLength ( 6 ) ;
459
-
460
- // Find each operation type
461
- const incrementOp = operations . find ( ( op ) => op . type === "increment" ) ;
462
- const setOp = operations . find ( ( op ) => op . type === "set" ) ;
463
- const appendOps = operations . filter ( ( op ) => op . type === "append" ) ;
464
- const deleteOps = operations . filter ( ( op ) => op . type === "delete" ) ;
459
+ // With order-preserving collapse, expect 8 operations:
460
+ // increment(counter, 5), set(status, processing), append(logs, ...), increment(counter, 3), set(status, completed), append(logs, ...), delete(tempData1), delete(tempData2)
461
+ expect ( operations ) . toHaveLength ( 8 ) ;
465
462
466
- expect ( incrementOp ) . toEqual ( {
463
+ expect ( operations [ 0 ] ) . toEqual ( {
467
464
type : "increment" ,
468
465
key : "counter" ,
469
- value : 8 , // 5 + 3
466
+ value : 5 ,
470
467
} ) ;
471
-
472
- expect ( setOp ) . toEqual ( {
468
+ expect ( operations [ 1 ] ) . toEqual ( {
473
469
type : "set" ,
474
470
key : "status" ,
475
- value : "completed" , // Last set value
471
+ value : "processing" ,
476
472
} ) ;
477
-
478
- expect ( appendOps ) . toHaveLength ( 2 ) ;
479
- expect ( appendOps [ 0 ] ) . toEqual ( {
473
+ expect ( operations [ 2 ] ) . toEqual ( {
480
474
type : "append" ,
481
475
key : "logs" ,
482
476
value : "Started processing" ,
483
477
} ) ;
484
- expect ( appendOps [ 1 ] ) . toEqual ( {
478
+ expect ( operations [ 3 ] ) . toEqual ( {
479
+ type : "increment" ,
480
+ key : "counter" ,
481
+ value : 3 ,
482
+ } ) ;
483
+ expect ( operations [ 4 ] ) . toEqual ( {
484
+ type : "set" ,
485
+ key : "status" ,
486
+ value : "completed" ,
487
+ } ) ;
488
+ expect ( operations [ 5 ] ) . toEqual ( {
485
489
type : "append" ,
486
490
key : "logs" ,
487
491
value : "Processing completed" ,
488
492
} ) ;
489
-
490
- expect ( deleteOps ) . toHaveLength ( 2 ) ;
491
- const deleteKeys = deleteOps . map ( ( op ) => ( op as any ) . key ) . sort ( ) ;
492
- expect ( deleteKeys ) . toEqual ( [ "tempData1" , "tempData2" ] ) ;
493
+ expect ( operations [ 6 ] ) . toEqual ( {
494
+ type : "delete" ,
495
+ key : "tempData1" ,
496
+ } ) ;
497
+ expect ( operations [ 7 ] ) . toEqual ( {
498
+ type : "delete" ,
499
+ key : "tempData2" ,
500
+ } ) ;
493
501
} ) ;
494
502
495
503
test ( "should collapse operations across different keys independently" , async ( ) => {
@@ -504,26 +512,30 @@ describe("StandardMetadataManager", () => {
504
512
expect ( metadataUpdates ) . toHaveLength ( 1 ) ;
505
513
506
514
const update = metadataUpdates [ 0 ] ! ;
507
- expect ( update . operations ) . toHaveLength ( 2 ) ;
508
-
509
- // Should have separate collapsed increments for each key
510
- const filesOp = update . operations ! . find (
511
- ( op ) => op . type === "increment" && ( op as any ) . key === "filesProcessed"
512
- ) ;
513
- const errorsOp = update . operations ! . find (
514
- ( op ) => op . type === "increment" && ( op as any ) . key === "errorsCount"
515
- ) ;
515
+ const operations = update . operations ! ;
516
516
517
- expect ( filesOp ) . toEqual ( {
517
+ // With order-preserving collapse, expect 4 operations:
518
+ // increment(filesProcessed, 10), increment(errorsCount, 1), increment(filesProcessed, 5), increment(errorsCount, 2)
519
+ expect ( operations ) . toHaveLength ( 4 ) ;
520
+ expect ( operations [ 0 ] ) . toEqual ( {
518
521
type : "increment" ,
519
522
key : "filesProcessed" ,
520
- value : 15 , // 10 + 5
523
+ value : 10 ,
521
524
} ) ;
522
-
523
- expect ( errorsOp ) . toEqual ( {
525
+ expect ( operations [ 1 ] ) . toEqual ( {
526
+ type : "increment" ,
527
+ key : "errorsCount" ,
528
+ value : 1 ,
529
+ } ) ;
530
+ expect ( operations [ 2 ] ) . toEqual ( {
531
+ type : "increment" ,
532
+ key : "filesProcessed" ,
533
+ value : 5 ,
534
+ } ) ;
535
+ expect ( operations [ 3 ] ) . toEqual ( {
524
536
type : "increment" ,
525
537
key : "errorsCount" ,
526
- value : 3 , // 1 + 2
538
+ value : 2 ,
527
539
} ) ;
528
540
} ) ;
529
541
0 commit comments