|
18 | 18 | import com.linkedin.metadata.AspectGenerationUtils;
|
19 | 19 | import com.linkedin.metadata.Constants;
|
20 | 20 | import com.linkedin.metadata.EbeanTestUtils;
|
21 |
| -import com.linkedin.metadata.aspect.patch.GenericJsonPatch; |
22 |
| -import com.linkedin.metadata.aspect.patch.PatchOperationType; |
23 | 21 | import com.linkedin.metadata.config.EbeanConfiguration;
|
24 | 22 | import com.linkedin.metadata.config.PreProcessHooks;
|
25 | 23 | import com.linkedin.metadata.entity.ebean.EbeanAspectDao;
|
@@ -384,360 +382,6 @@ public void testSystemMetadataDuplicateKey() throws Exception {
|
384 | 382 | "Expected version 0 with systemMeta version 3 accounting for the the collision");
|
385 | 383 | }
|
386 | 384 |
|
387 |
| - @Test |
388 |
| - public void testBatchDuplicate() throws Exception { |
389 |
| - Urn entityUrn = UrnUtils.getUrn("urn:li:corpuser:batchDuplicateTest"); |
390 |
| - SystemMetadata systemMetadata = AspectGenerationUtils.createSystemMetadata(); |
391 |
| - ChangeItemImpl item1 = |
392 |
| - ChangeItemImpl.builder() |
393 |
| - .urn(entityUrn) |
394 |
| - .aspectName(STATUS_ASPECT_NAME) |
395 |
| - .recordTemplate(new Status().setRemoved(true)) |
396 |
| - .systemMetadata(systemMetadata.copy()) |
397 |
| - .auditStamp(TEST_AUDIT_STAMP) |
398 |
| - .build(TestOperationContexts.emptyAspectRetriever(null)); |
399 |
| - ChangeItemImpl item2 = |
400 |
| - ChangeItemImpl.builder() |
401 |
| - .urn(entityUrn) |
402 |
| - .aspectName(STATUS_ASPECT_NAME) |
403 |
| - .recordTemplate(new Status().setRemoved(false)) |
404 |
| - .systemMetadata(systemMetadata.copy()) |
405 |
| - .auditStamp(TEST_AUDIT_STAMP) |
406 |
| - .build(TestOperationContexts.emptyAspectRetriever(null)); |
407 |
| - _entityServiceImpl.ingestAspects( |
408 |
| - opContext, |
409 |
| - AspectsBatchImpl.builder() |
410 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
411 |
| - .items(List.of(item1, item2)) |
412 |
| - .build(), |
413 |
| - false, |
414 |
| - true); |
415 |
| - |
416 |
| - // List aspects urns |
417 |
| - ListUrnsResult batch = _entityServiceImpl.listUrns(opContext, entityUrn.getEntityType(), 0, 2); |
418 |
| - |
419 |
| - assertEquals(batch.getStart().intValue(), 0); |
420 |
| - assertEquals(batch.getCount().intValue(), 1); |
421 |
| - assertEquals(batch.getTotal().intValue(), 1); |
422 |
| - assertEquals(batch.getEntities().size(), 1); |
423 |
| - assertEquals(entityUrn.toString(), batch.getEntities().get(0).toString()); |
424 |
| - |
425 |
| - EnvelopedAspect envelopedAspect = |
426 |
| - _entityServiceImpl.getLatestEnvelopedAspect( |
427 |
| - opContext, CORP_USER_ENTITY_NAME, entityUrn, STATUS_ASPECT_NAME); |
428 |
| - assertEquals( |
429 |
| - envelopedAspect.getSystemMetadata().getVersion(), |
430 |
| - "2", |
431 |
| - "Expected version 2 accounting for duplicates"); |
432 |
| - assertEquals( |
433 |
| - envelopedAspect.getValue().toString(), |
434 |
| - "{removed=false}", |
435 |
| - "Expected 2nd item to be the latest"); |
436 |
| - } |
437 |
| - |
438 |
| - @Test |
439 |
| - public void testBatchPatchWithTrailingNoOp() throws Exception { |
440 |
| - Urn entityUrn = |
441 |
| - UrnUtils.getUrn( |
442 |
| - "urn:li:dataset:(urn:li:dataPlatform:snowflake,testBatchPatchWithTrailingNoOp,PROD)"); |
443 |
| - TagUrn tag1 = TagUrn.createFromString("urn:li:tag:tag1"); |
444 |
| - Urn tag2 = UrnUtils.getUrn("urn:li:tag:tag2"); |
445 |
| - Urn tagOther = UrnUtils.getUrn("urn:li:tag:other"); |
446 |
| - |
447 |
| - SystemMetadata systemMetadata = AspectGenerationUtils.createSystemMetadata(); |
448 |
| - |
449 |
| - ChangeItemImpl initialAspectTag1 = |
450 |
| - ChangeItemImpl.builder() |
451 |
| - .urn(entityUrn) |
452 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
453 |
| - .recordTemplate( |
454 |
| - new GlobalTags() |
455 |
| - .setTags(new TagAssociationArray(new TagAssociation().setTag(tag1)))) |
456 |
| - .systemMetadata(systemMetadata.copy()) |
457 |
| - .auditStamp(TEST_AUDIT_STAMP) |
458 |
| - .build(TestOperationContexts.emptyAspectRetriever(null)); |
459 |
| - |
460 |
| - PatchItemImpl patchAdd2 = |
461 |
| - PatchItemImpl.builder() |
462 |
| - .urn(entityUrn) |
463 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
464 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
465 |
| - .aspectSpec( |
466 |
| - _testEntityRegistry |
467 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
468 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
469 |
| - .patch( |
470 |
| - GenericJsonPatch.builder() |
471 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
472 |
| - .patch(List.of(tagPatchOp(PatchOperationType.ADD, tag2))) |
473 |
| - .build() |
474 |
| - .getJsonPatch()) |
475 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
476 |
| - .build(_testEntityRegistry); |
477 |
| - |
478 |
| - PatchItemImpl patchRemoveNonExistent = |
479 |
| - PatchItemImpl.builder() |
480 |
| - .urn(entityUrn) |
481 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
482 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
483 |
| - .aspectSpec( |
484 |
| - _testEntityRegistry |
485 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
486 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
487 |
| - .patch( |
488 |
| - GenericJsonPatch.builder() |
489 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
490 |
| - .patch(List.of(tagPatchOp(PatchOperationType.REMOVE, tagOther))) |
491 |
| - .build() |
492 |
| - .getJsonPatch()) |
493 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
494 |
| - .build(_testEntityRegistry); |
495 |
| - |
496 |
| - // establish base entity |
497 |
| - _entityServiceImpl.ingestAspects( |
498 |
| - opContext, |
499 |
| - AspectsBatchImpl.builder() |
500 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
501 |
| - .items(List.of(initialAspectTag1)) |
502 |
| - .build(), |
503 |
| - false, |
504 |
| - true); |
505 |
| - |
506 |
| - _entityServiceImpl.ingestAspects( |
507 |
| - opContext, |
508 |
| - AspectsBatchImpl.builder() |
509 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
510 |
| - .items(List.of(patchAdd2, patchRemoveNonExistent)) |
511 |
| - .build(), |
512 |
| - false, |
513 |
| - true); |
514 |
| - |
515 |
| - // List aspects urns |
516 |
| - ListUrnsResult batch = _entityServiceImpl.listUrns(opContext, entityUrn.getEntityType(), 0, 1); |
517 |
| - |
518 |
| - assertEquals(batch.getStart().intValue(), 0); |
519 |
| - assertEquals(batch.getCount().intValue(), 1); |
520 |
| - assertEquals(batch.getTotal().intValue(), 1); |
521 |
| - assertEquals(batch.getEntities().size(), 1); |
522 |
| - assertEquals(entityUrn.toString(), batch.getEntities().get(0).toString()); |
523 |
| - |
524 |
| - EnvelopedAspect envelopedAspect = |
525 |
| - _entityServiceImpl.getLatestEnvelopedAspect( |
526 |
| - opContext, DATASET_ENTITY_NAME, entityUrn, GLOBAL_TAGS_ASPECT_NAME); |
527 |
| - assertEquals( |
528 |
| - envelopedAspect.getSystemMetadata().getVersion(), |
529 |
| - "2", |
530 |
| - "Expected version 3. 1 - Initial, + 1 add, 1 remove"); |
531 |
| - assertEquals( |
532 |
| - new GlobalTags(envelopedAspect.getValue().data()) |
533 |
| - .getTags().stream().map(TagAssociation::getTag).collect(Collectors.toSet()), |
534 |
| - Set.of(tag1, tag2), |
535 |
| - "Expected both tags"); |
536 |
| - } |
537 |
| - |
538 |
| - @Test |
539 |
| - public void testBatchPatchAdd() throws Exception { |
540 |
| - Urn entityUrn = |
541 |
| - UrnUtils.getUrn("urn:li:dataset:(urn:li:dataPlatform:snowflake,testBatchPatchAdd,PROD)"); |
542 |
| - TagUrn tag1 = TagUrn.createFromString("urn:li:tag:tag1"); |
543 |
| - TagUrn tag2 = TagUrn.createFromString("urn:li:tag:tag2"); |
544 |
| - TagUrn tag3 = TagUrn.createFromString("urn:li:tag:tag3"); |
545 |
| - |
546 |
| - SystemMetadata systemMetadata = AspectGenerationUtils.createSystemMetadata(); |
547 |
| - |
548 |
| - ChangeItemImpl initialAspectTag1 = |
549 |
| - ChangeItemImpl.builder() |
550 |
| - .urn(entityUrn) |
551 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
552 |
| - .recordTemplate( |
553 |
| - new GlobalTags() |
554 |
| - .setTags(new TagAssociationArray(new TagAssociation().setTag(tag1)))) |
555 |
| - .systemMetadata(systemMetadata.copy()) |
556 |
| - .auditStamp(TEST_AUDIT_STAMP) |
557 |
| - .build(TestOperationContexts.emptyAspectRetriever(null)); |
558 |
| - |
559 |
| - PatchItemImpl patchAdd3 = |
560 |
| - PatchItemImpl.builder() |
561 |
| - .urn(entityUrn) |
562 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
563 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
564 |
| - .aspectSpec( |
565 |
| - _testEntityRegistry |
566 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
567 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
568 |
| - .patch( |
569 |
| - GenericJsonPatch.builder() |
570 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
571 |
| - .patch(List.of(tagPatchOp(PatchOperationType.ADD, tag3))) |
572 |
| - .build() |
573 |
| - .getJsonPatch()) |
574 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
575 |
| - .build(_testEntityRegistry); |
576 |
| - |
577 |
| - PatchItemImpl patchAdd2 = |
578 |
| - PatchItemImpl.builder() |
579 |
| - .urn(entityUrn) |
580 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
581 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
582 |
| - .aspectSpec( |
583 |
| - _testEntityRegistry |
584 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
585 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
586 |
| - .patch( |
587 |
| - GenericJsonPatch.builder() |
588 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
589 |
| - .patch(List.of(tagPatchOp(PatchOperationType.ADD, tag2))) |
590 |
| - .build() |
591 |
| - .getJsonPatch()) |
592 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
593 |
| - .build(_testEntityRegistry); |
594 |
| - |
595 |
| - PatchItemImpl patchAdd1 = |
596 |
| - PatchItemImpl.builder() |
597 |
| - .urn(entityUrn) |
598 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
599 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
600 |
| - .aspectSpec( |
601 |
| - _testEntityRegistry |
602 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
603 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
604 |
| - .patch( |
605 |
| - GenericJsonPatch.builder() |
606 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
607 |
| - .patch(List.of(tagPatchOp(PatchOperationType.ADD, tag1))) |
608 |
| - .build() |
609 |
| - .getJsonPatch()) |
610 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
611 |
| - .build(_testEntityRegistry); |
612 |
| - |
613 |
| - // establish base entity |
614 |
| - _entityServiceImpl.ingestAspects( |
615 |
| - opContext, |
616 |
| - AspectsBatchImpl.builder() |
617 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
618 |
| - .items(List.of(initialAspectTag1)) |
619 |
| - .build(), |
620 |
| - false, |
621 |
| - true); |
622 |
| - |
623 |
| - _entityServiceImpl.ingestAspects( |
624 |
| - opContext, |
625 |
| - AspectsBatchImpl.builder() |
626 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
627 |
| - .items(List.of(patchAdd3, patchAdd2, patchAdd1)) |
628 |
| - .build(), |
629 |
| - false, |
630 |
| - true); |
631 |
| - |
632 |
| - // List aspects urns |
633 |
| - ListUrnsResult batch = _entityServiceImpl.listUrns(opContext, entityUrn.getEntityType(), 0, 1); |
634 |
| - |
635 |
| - assertEquals(batch.getStart().intValue(), 0); |
636 |
| - assertEquals(batch.getCount().intValue(), 1); |
637 |
| - assertEquals(batch.getTotal().intValue(), 1); |
638 |
| - assertEquals(batch.getEntities().size(), 1); |
639 |
| - assertEquals(entityUrn.toString(), batch.getEntities().get(0).toString()); |
640 |
| - |
641 |
| - EnvelopedAspect envelopedAspect = |
642 |
| - _entityServiceImpl.getLatestEnvelopedAspect( |
643 |
| - opContext, DATASET_ENTITY_NAME, entityUrn, GLOBAL_TAGS_ASPECT_NAME); |
644 |
| - assertEquals(envelopedAspect.getSystemMetadata().getVersion(), "3", "Expected version 4"); |
645 |
| - assertEquals( |
646 |
| - new GlobalTags(envelopedAspect.getValue().data()) |
647 |
| - .getTags().stream().map(TagAssociation::getTag).collect(Collectors.toSet()), |
648 |
| - Set.of(tag1, tag2, tag3), |
649 |
| - "Expected all tags"); |
650 |
| - } |
651 |
| - |
652 |
| - @Test |
653 |
| - public void testBatchPatchAddDuplicate() throws Exception { |
654 |
| - Urn entityUrn = |
655 |
| - UrnUtils.getUrn("urn:li:dataset:(urn:li:dataPlatform:snowflake,testBatchPatchAdd,PROD)"); |
656 |
| - List<TagAssociation> initialTags = |
657 |
| - List.of( |
658 |
| - TagUrn.createFromString("urn:li:tag:__default_large_table"), |
659 |
| - TagUrn.createFromString("urn:li:tag:__default_low_queries"), |
660 |
| - TagUrn.createFromString("urn:li:tag:__default_low_changes"), |
661 |
| - TagUrn.createFromString("urn:li:tag:!10TB+ tables")) |
662 |
| - .stream() |
663 |
| - .map(tag -> new TagAssociation().setTag(tag)) |
664 |
| - .collect(Collectors.toList()); |
665 |
| - TagUrn tag2 = TagUrn.createFromString("urn:li:tag:$ 1TB+"); |
666 |
| - |
667 |
| - SystemMetadata systemMetadata = AspectGenerationUtils.createSystemMetadata(); |
668 |
| - |
669 |
| - SystemMetadata patchSystemMetadata = new SystemMetadata(); |
670 |
| - patchSystemMetadata.setLastObserved(systemMetadata.getLastObserved() + 1); |
671 |
| - patchSystemMetadata.setProperties(new StringMap(Map.of(APP_SOURCE, METADATA_TESTS_SOURCE))); |
672 |
| - |
673 |
| - ChangeItemImpl initialAspectTag1 = |
674 |
| - ChangeItemImpl.builder() |
675 |
| - .urn(entityUrn) |
676 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
677 |
| - .recordTemplate(new GlobalTags().setTags(new TagAssociationArray(initialTags))) |
678 |
| - .systemMetadata(systemMetadata.copy()) |
679 |
| - .auditStamp(TEST_AUDIT_STAMP) |
680 |
| - .build(TestOperationContexts.emptyAspectRetriever(null)); |
681 |
| - |
682 |
| - PatchItemImpl patchAdd2 = |
683 |
| - PatchItemImpl.builder() |
684 |
| - .urn(entityUrn) |
685 |
| - .entitySpec(_testEntityRegistry.getEntitySpec(DATASET_ENTITY_NAME)) |
686 |
| - .aspectName(GLOBAL_TAGS_ASPECT_NAME) |
687 |
| - .aspectSpec( |
688 |
| - _testEntityRegistry |
689 |
| - .getEntitySpec(DATASET_ENTITY_NAME) |
690 |
| - .getAspectSpec(GLOBAL_TAGS_ASPECT_NAME)) |
691 |
| - .patch( |
692 |
| - GenericJsonPatch.builder() |
693 |
| - .arrayPrimaryKeys(Map.of("properties", List.of("tag"))) |
694 |
| - .patch(List.of(tagPatchOp(PatchOperationType.ADD, tag2))) |
695 |
| - .build() |
696 |
| - .getJsonPatch()) |
697 |
| - .systemMetadata(patchSystemMetadata) |
698 |
| - .auditStamp(AuditStampUtils.createDefaultAuditStamp()) |
699 |
| - .build(_testEntityRegistry); |
700 |
| - |
701 |
| - // establish base entity |
702 |
| - _entityServiceImpl.ingestAspects( |
703 |
| - opContext, |
704 |
| - AspectsBatchImpl.builder() |
705 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
706 |
| - .items(List.of(initialAspectTag1)) |
707 |
| - .build(), |
708 |
| - false, |
709 |
| - true); |
710 |
| - |
711 |
| - _entityServiceImpl.ingestAspects( |
712 |
| - opContext, |
713 |
| - AspectsBatchImpl.builder() |
714 |
| - .retrieverContext(opContext.getRetrieverContext().get()) |
715 |
| - .items(List.of(patchAdd2, patchAdd2)) // duplicate |
716 |
| - .build(), |
717 |
| - false, |
718 |
| - true); |
719 |
| - |
720 |
| - // List aspects urns |
721 |
| - ListUrnsResult batch = _entityServiceImpl.listUrns(opContext, entityUrn.getEntityType(), 0, 1); |
722 |
| - |
723 |
| - assertEquals(batch.getStart().intValue(), 0); |
724 |
| - assertEquals(batch.getCount().intValue(), 1); |
725 |
| - assertEquals(batch.getTotal().intValue(), 1); |
726 |
| - assertEquals(batch.getEntities().size(), 1); |
727 |
| - assertEquals(entityUrn.toString(), batch.getEntities().get(0).toString()); |
728 |
| - |
729 |
| - EnvelopedAspect envelopedAspect = |
730 |
| - _entityServiceImpl.getLatestEnvelopedAspect( |
731 |
| - opContext, DATASET_ENTITY_NAME, entityUrn, GLOBAL_TAGS_ASPECT_NAME); |
732 |
| - assertEquals(envelopedAspect.getSystemMetadata().getVersion(), "2", "Expected version 2"); |
733 |
| - assertEquals( |
734 |
| - new GlobalTags(envelopedAspect.getValue().data()) |
735 |
| - .getTags().stream().map(TagAssociation::getTag).collect(Collectors.toSet()), |
736 |
| - Stream.concat(initialTags.stream().map(TagAssociation::getTag), Stream.of(tag2)) |
737 |
| - .collect(Collectors.toSet()), |
738 |
| - "Expected all tags"); |
739 |
| - } |
740 |
| - |
741 | 385 | @Test
|
742 | 386 | public void dataGeneratorThreadingTest() {
|
743 | 387 | DataGenerator dataGenerator = new DataGenerator(opContext, _entityServiceImpl);
|
|
0 commit comments