2
2
3
3
import com .linkedin .common .AuditStamp ;
4
4
import com .linkedin .data .template .RecordTemplate ;
5
+ import com .linkedin .data .template .SetMode ;
5
6
import com .linkedin .metadata .dao .builder .BaseLocalRelationshipBuilder .LocalRelationshipUpdates ;
6
7
import com .linkedin .metadata .dao .producer .BaseMetadataEventProducer ;
7
8
import com .linkedin .metadata .dao .producer .BaseTrackingMetadataEventProducer ;
@@ -437,39 +438,55 @@ public Object[][] addBackfillForNoopCases() {
437
438
AuditStamp oldAuditStamp = makeAuditStamp ("susActor" , 6L );
438
439
439
440
// case 1 - emitTime doesn't exist
440
- IngestionTrackingContext contextWithNoEmitTime = new IngestionTrackingContext ();
441
- contextWithNoEmitTime .setBackfill (true );
442
-
443
- // case 2 - emitTime < old stamp
444
- IngestionTrackingContext contextWithSmallEmitTime = new IngestionTrackingContext ();
445
- contextWithSmallEmitTime .setBackfill (true );
446
- contextWithSmallEmitTime .setEmitTime (5L );
441
+ IngestionTrackingContext context1 = new IngestionTrackingContext ();
442
+ context1 .setBackfill (true );
443
+
444
+ // case 2 - new emit time < old emit time
445
+ IngestionTrackingContext context2 = new IngestionTrackingContext ();
446
+ context2 .setBackfill (true );
447
+ context2 .setEmitTime (4L );
448
+ long oldEmitTime2 = 5L ;
449
+
450
+ // case 3 - new emit time < old emit time (same as case 2, but old stamp < new emit time)
451
+ IngestionTrackingContext context3 = new IngestionTrackingContext ();
452
+ context3 .setBackfill (true );
453
+ context3 .setEmitTime (10L );
454
+ long oldEmitTime3 = 11L ;
455
+
456
+ // case 4 - old emit time = null, new emit time < old audit stamp
457
+ IngestionTrackingContext context4 = new IngestionTrackingContext ();
458
+ context4 .setBackfill (true );
459
+ context4 .setEmitTime (3L );
447
460
448
461
return new Object [][] {
449
- { contextWithNoEmitTime , oldAuditStamp },
450
- { contextWithSmallEmitTime , oldAuditStamp }
462
+ { context1 , oldAuditStamp , null },
463
+ { context2 , oldAuditStamp , oldEmitTime2 },
464
+ { context3 , oldAuditStamp , oldEmitTime3 },
465
+ { context4 , oldAuditStamp , null }
451
466
};
452
467
}
453
468
454
469
@ Test (description = "Each test case represents a scenario where a backfill event should NOT be backfilled" ,
455
470
dataProvider = "addBackfillForNoopCases" )
456
- public void testAddBackfillEmitTimeLargerThanOldAuditTime (
457
- IngestionTrackingContext ingestionTrackingContext , AuditStamp oldAuditStamp
471
+ public void testAddForBackfillEventsWhenWeShouldNotDoBackfill (
472
+ IngestionTrackingContext ingestionTrackingContext , AuditStamp oldAuditStamp , Long oldEmitTime
458
473
) throws URISyntaxException {
459
474
FooUrn urn = new FooUrn (1 );
460
475
AspectFoo oldFoo = new AspectFoo ().setValue ("oldFoo" );
461
476
AspectFoo newFoo = new AspectFoo ().setValue ("newFoo" );
462
477
463
478
ExtraInfo extraInfo = new ExtraInfo ();
464
479
extraInfo .setAudit (oldAuditStamp );
480
+ extraInfo .setEmitTime (oldEmitTime , SetMode .IGNORE_NULL );
465
481
466
482
DummyLocalDAO dummyLocalDAO = new DummyLocalDAO (_mockGetLatestFunction , _mockTrackingEventProducer , _mockTrackingManager ,
467
483
_dummyLocalDAO ._transactionRunner );
468
484
dummyLocalDAO .setEmitAuditEvent (true );
469
485
dummyLocalDAO .setAlwaysEmitAuditEvent (true );
470
486
dummyLocalDAO .setEmitAspectSpecificAuditEvent (true );
471
487
dummyLocalDAO .setAlwaysEmitAspectSpecificAuditEvent (true );
472
- expectGetLatest (urn , AspectFoo .class , Collections .singletonList (makeAspectEntry (oldFoo , oldAuditStamp )));
488
+ BaseLocalDAO .AspectEntry <AspectFoo > aspectEntry = new BaseLocalDAO .AspectEntry <>(oldFoo , extraInfo );
489
+ expectGetLatest (urn , AspectFoo .class , Collections .singletonList (aspectEntry ));
473
490
474
491
dummyLocalDAO .add (urn , newFoo , _dummyAuditStamp , ingestionTrackingContext );
475
492
@@ -479,27 +496,54 @@ public void testAddBackfillEmitTimeLargerThanOldAuditTime(
479
496
verifyNoMoreInteractions (_mockTrackingEventProducer );
480
497
}
481
498
482
- @ Test (description = "Event should be processed for backfill event" )
483
- public void testAddForBackfill () throws URISyntaxException {
499
+ @ DataProvider (name = "addBackfillForCasesThatShouldBackfill" )
500
+ public Object [][] addBackfillForCasesThatShouldBackfill () {
501
+ AuditStamp oldAuditStamp = makeAuditStamp ("susActor" , 6L );
502
+
503
+ // case 1 - emitTime exists and is larger than old emit time
504
+ IngestionTrackingContext context1 = new IngestionTrackingContext ();
505
+ context1 .setBackfill (true );
506
+ context1 .setEmitTime (5L );
507
+ long oldEmitTime1 = 4L ;
508
+
509
+ // case 2 - emitTime exists and is larger than old emit time
510
+ IngestionTrackingContext context2 = new IngestionTrackingContext ();
511
+ context2 .setBackfill (true );
512
+ context2 .setEmitTime (10L );
513
+ long oldEmitTime2 = 4L ;
514
+
515
+ // case 3 - emitTime exists, old emitTime doesn't exist, emitTime > old audit stamp
516
+ IngestionTrackingContext context3 = new IngestionTrackingContext ();
517
+ context3 .setBackfill (true );
518
+ context3 .setEmitTime (7L );
519
+
520
+ return new Object [][] {
521
+ { context1 , oldAuditStamp , oldEmitTime1 },
522
+ { context2 , oldAuditStamp , oldEmitTime2 },
523
+ { context3 , oldAuditStamp , null }
524
+ };
525
+ }
526
+
527
+ @ Test (description = "Event should be processed for backfill event" , dataProvider = "addBackfillForCasesThatShouldBackfill" )
528
+ public void testAddForBackfill (
529
+ IngestionTrackingContext ingestionTrackingContext , AuditStamp oldAuditStamp , Long oldEmitTime
530
+ ) throws URISyntaxException {
484
531
FooUrn urn = new FooUrn (1 );
485
532
AspectFoo oldFoo = new AspectFoo ().setValue ("oldFoo" );
486
533
AspectFoo newFoo = new AspectFoo ().setValue ("newFoo" );
487
534
488
535
ExtraInfo extraInfo = new ExtraInfo ();
489
- AuditStamp oldAuditStamp = makeAuditStamp ("nonSusActor" , 5L );
490
536
extraInfo .setAudit (oldAuditStamp );
537
+ extraInfo .setEmitTime (oldEmitTime , SetMode .IGNORE_NULL );
491
538
492
539
DummyLocalDAO dummyLocalDAO = new DummyLocalDAO (_mockGetLatestFunction , _mockTrackingEventProducer , _mockTrackingManager ,
493
540
_dummyLocalDAO ._transactionRunner );
494
541
dummyLocalDAO .setEmitAuditEvent (true );
495
542
dummyLocalDAO .setAlwaysEmitAuditEvent (true );
496
543
dummyLocalDAO .setEmitAspectSpecificAuditEvent (true );
497
544
dummyLocalDAO .setAlwaysEmitAspectSpecificAuditEvent (true );
498
- expectGetLatest (urn , AspectFoo .class , Collections .singletonList (makeAspectEntry (oldFoo , oldAuditStamp )));
499
-
500
- IngestionTrackingContext ingestionTrackingContext = new IngestionTrackingContext ();
501
- ingestionTrackingContext .setBackfill (true );
502
- ingestionTrackingContext .setEmitTime (6L );
545
+ BaseLocalDAO .AspectEntry <AspectFoo > aspectEntry = new BaseLocalDAO .AspectEntry <>(oldFoo , extraInfo );
546
+ expectGetLatest (urn , AspectFoo .class , Collections .singletonList (aspectEntry ));
503
547
504
548
dummyLocalDAO .add (urn , newFoo , _dummyAuditStamp , ingestionTrackingContext );
505
549
0 commit comments