@@ -229,9 +229,13 @@ class ParentChildRelMetadataServiceSpec extends Specification{
229
229
service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
230
230
231
231
when :
232
- service. rename(parent, newParent)
232
+ def pair = service. renameSoftInsert(parent, newParent)
233
+ service. drop(parent, Optional . of(pair))
233
234
234
235
then :
236
+ assert pair. getLeft(). size() == 1
237
+ assert pair. getRight(). isEmpty()
238
+
235
239
// Test Old Parent Name
236
240
assert service. getParents(parent). isEmpty()
237
241
assert service. getChildren(parent). isEmpty()
@@ -254,10 +258,13 @@ class ParentChildRelMetadataServiceSpec extends Specification{
254
258
255
259
// rename back
256
260
when :
257
- service. rename(newParent, parent)
261
+ pair = service. renameSoftInsert(newParent, parent)
262
+ service. drop(newParent, Optional . of(pair))
258
263
child_parent_expected = [new ParentInfo (parent. toString(), type, parentUUID)] as Set
259
264
260
265
then :
266
+ assert pair. getLeft(). size() == 1
267
+ assert pair. getRight(). isEmpty()
261
268
// Test new Parent Name
262
269
assert service. getParents(newParent). isEmpty()
263
270
assert service. getChildren(newParent). isEmpty()
@@ -290,28 +297,29 @@ class ParentChildRelMetadataServiceSpec extends Specification{
290
297
service. createParentChildRelation(parent, parentUUID, child2, child2UUID, type, props)
291
298
def newParent = QualifiedName . ofTable(catalog, database, " np" )
292
299
def child_parent_expected = [new ParentInfo (newParent. toString(), type, parentUUID)] as Set
300
+ def newParent_children_expected = [
301
+ new ChildInfo (child1. toString(), type, child1UUID),
302
+ new ChildInfo (child2. toString(), type, child2UUID)
303
+ ] as Set
293
304
294
305
when :
295
- service. rename(parent, newParent)
306
+ def pair = service. renameSoftInsert(parent, newParent)
307
+ service. drop(parent, Optional . of(pair))
296
308
297
309
then :
298
310
// Test Old Parent Name
311
+ assert pair. getLeft(). size() == 1
312
+ assert pair. getRight(). isEmpty()
299
313
assert service. getParents(parent). isEmpty()
300
314
assert service. getChildren(parent). isEmpty()
301
315
assert ! service. isChildTable(parent)
302
316
assert ! service. isParentTable(parent)
303
317
304
318
// Test New Parent Name
305
319
assert service. getParents(newParent). isEmpty()
306
- def newParent_children_expected = [
307
- new ChildInfo (child1. toString(), type, child1UUID),
308
- new ChildInfo (child2. toString(), type, child2UUID),
309
- ] as Set
310
320
assert service. getChildren(newParent) == newParent_children_expected
311
321
assert ! service. isChildTable(newParent)
312
322
assert service. isParentTable(newParent)
313
-
314
- then :
315
323
// Test Child1
316
324
assert service. getParents(child1) == child_parent_expected
317
325
assert service. isChildTable(child1)
@@ -333,8 +341,12 @@ class ParentChildRelMetadataServiceSpec extends Specification{
333
341
def newChild = QualifiedName . ofTable(catalog, database, " nc" )
334
342
335
343
when :
336
- service. rename(child, newChild)
344
+ def pair = service. renameSoftInsert(child, newChild)
345
+ service. drop(child, Optional . of(pair))
346
+
337
347
then :
348
+ assert pair. getLeft(). isEmpty()
349
+ assert pair. getRight(). size() == 1
338
350
// Test Parent
339
351
assert service. getParents(parent). isEmpty()
340
352
def parent_children_expected = [new ChildInfo (newChild. toString(), type, childUUID)] as Set
@@ -357,10 +369,13 @@ class ParentChildRelMetadataServiceSpec extends Specification{
357
369
358
370
// rename back
359
371
when :
360
- service. rename(newChild, child)
372
+ pair = service. renameSoftInsert(newChild, child)
373
+ service. drop(newChild, Optional . of(pair))
361
374
parent_children_expected = [new ChildInfo (child. toString(), type, childUUID)] as Set
362
375
363
376
then :
377
+ assert pair. getLeft(). isEmpty()
378
+ assert pair. getRight(). size() == 1
364
379
// Test Parent
365
380
assert service. getParents(parent). isEmpty()
366
381
assert parent_children_expected == service. getChildren(parent)
@@ -390,7 +405,7 @@ class ParentChildRelMetadataServiceSpec extends Specification{
390
405
def type = " clone" ;
391
406
service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
392
407
when :
393
- service. drop(child)
408
+ service. drop(child, Optional . empty() )
394
409
395
410
then :
396
411
// Test Parent
@@ -417,8 +432,9 @@ class ParentChildRelMetadataServiceSpec extends Specification{
417
432
service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
418
433
419
434
when :
420
- service. rename(child, newChild)
421
- service. drop(newChild)
435
+ def pair = service. renameSoftInsert(child, newChild)
436
+ service. drop(child, Optional . of(pair))
437
+ service. drop(newChild, Optional . empty())
422
438
423
439
then :
424
440
// Test Parent
@@ -460,14 +476,14 @@ class ParentChildRelMetadataServiceSpec extends Specification{
460
476
461
477
// rename to an existing parent
462
478
when :
463
- service. rename (parent1, parent2)
479
+ service. renameSoftInsert (parent1, parent2)
464
480
then :
465
481
def e = thrown(Exception )
466
482
assert e. message. contains(" is already a parent table" )
467
483
468
484
// rename to an existing child
469
485
when :
470
- service. rename (child2, child1)
486
+ service. renameSoftInsert (child2, child1)
471
487
then :
472
488
e = thrown(Exception )
473
489
assert e. message. contains(" is already a child table" )
@@ -618,4 +634,165 @@ class ParentChildRelMetadataServiceSpec extends Specification{
618
634
1 | " CLONE,5" | " CLONE,test,3;OTHER,other,2" | " CLONE,testhive/test/parent,2" | 2
619
635
1 | " CLONE,5;Other,3" | " CLONE,test,3;CLONE,other,2" | " CLONE,testhive/test/parent,2;CLONE,testhive/test/other,2" | 2
620
636
}
637
+ def " Test Parent Rename failed and remove newName" () {
638
+ setup :
639
+ def parent = QualifiedName . ofTable(catalog, database, " p" )
640
+ def parentUUID = " p_uuid"
641
+ def child = QualifiedName . ofTable(catalog, database, " c" )
642
+ def childUUID = " c_uuid"
643
+ def type = " clone" ;
644
+ def newParent = QualifiedName . ofTable(catalog, database, " np" )
645
+ service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
646
+
647
+ when :
648
+ def pair = service. renameSoftInsert(parent, newParent)
649
+ service. drop(newParent, Optional . of(pair))
650
+
651
+ then :
652
+ // Test New Parent Name
653
+ assert service. getParents(newParent). isEmpty()
654
+ assert service. getChildren(newParent). isEmpty()
655
+
656
+ // Test Old Parent Name
657
+ assert service. getParents(parent). isEmpty()
658
+ def newParent_children_expected = [new ChildInfo (child. toString(), type, childUUID)] as Set
659
+ assert service. getChildren(parent) == newParent_children_expected
660
+
661
+ // Test Child
662
+ def child_parent_expected = [new ParentInfo (parent. toString(), type, parentUUID)] as Set
663
+ assert child_parent_expected == service. getParents(child)
664
+ assert service. getChildren(child). isEmpty()
665
+ }
666
+
667
+ def " Test Child Rename failed and remove newName" () {
668
+ setup :
669
+ def parent = QualifiedName . ofTable(catalog, database, " p" )
670
+ def parentUUID = " p_uuid"
671
+ def child = QualifiedName . ofTable(catalog, database, " c" )
672
+ def childUUID = " c_uuid"
673
+ def type = " clone"
674
+ service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
675
+ def newChild = QualifiedName . ofTable(catalog, database, " nc" )
676
+
677
+ when :
678
+ def pair = service. renameSoftInsert(child, newChild)
679
+ service. drop(newChild, Optional . of(pair))
680
+ then :
681
+ // Test Parent
682
+ assert service. getParents(parent). isEmpty()
683
+ def parent_children_expected = [new ChildInfo (child. toString(), type, childUUID)] as Set
684
+ assert parent_children_expected == service. getChildren(parent)
685
+
686
+ // Test New Child
687
+ assert service. getParents(newChild). isEmpty()
688
+ assert service. getChildren(newChild). isEmpty()
689
+
690
+ // Test Child
691
+ def child_parent_expected = [new ParentInfo (parent. toString(), type, parentUUID)] as Set
692
+ assert child_parent_expected == service. getParents(child)
693
+ assert service. getChildren(child). isEmpty()
694
+ }
695
+
696
+ def " Test rename to an existing table in the parent child rel service" () {
697
+ given :
698
+ def parent = QualifiedName . ofTable(catalog, database, " p" )
699
+ def parentUUID = " p_uuid"
700
+ def child = QualifiedName . ofTable(catalog, database, " c" )
701
+ def childUUID = " c_uuid"
702
+ def type = " clone"
703
+ service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
704
+ def newParentQualifiedName = QualifiedName . ofTable(catalog, database, " np_name" )
705
+ def newChildQualifiedName = QualifiedName . ofTable(catalog, database, " nc_name" )
706
+ insertNewParentChildRecord(newParentQualifiedName. toString(), " np_uuid" , newChildQualifiedName. toString(), " nc_uuid" , " random" )
707
+
708
+ when :
709
+ service. renameSoftInsert(parent, newParentQualifiedName)
710
+ then :
711
+ def e = thrown(RuntimeException )
712
+ assert e. message. contains(" is already a parent table" )
713
+
714
+ when :
715
+ service. renameSoftInsert(child, newChildQualifiedName)
716
+
717
+ then :
718
+ e = thrown(RuntimeException )
719
+ assert e. message. contains(" is already a child table" )
720
+ }
721
+
722
+ // Add a test where between rename and drop old/new name with the same name but different uuid is added
723
+ // only those get from rename should be drop
724
+ // This case is not possible in reality but wanted to add a test to prove this
725
+ def " Simulate Rename child: drop only impacted uuids" () {
726
+ setup :
727
+ def parent = QualifiedName . ofTable(catalog, database, " p" )
728
+ def parentUUID = " p_uuid"
729
+ def child = QualifiedName . ofTable(catalog, database, " c" )
730
+ def childUUID = " c_uuid"
731
+ def type = " clone"
732
+ service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
733
+ def newChild = QualifiedName . ofTable(catalog, database, " nc" )
734
+
735
+ when :
736
+ def pair = service. renameSoftInsert(child, newChild)
737
+ def child_parent_expected = [new ParentInfo (parent. toString(), type, parentUUID)] as Set
738
+ // Add a record with the same child name but different uuid and since this record is added after rename
739
+ // this record should not be dropped during the service.drop
740
+ insertNewParentChildRecord(parent. toString(), parentUUID, child. toString(), " c_uuid2" , type)
741
+ service. drop(child, Optional . of(pair))
742
+ then :
743
+ // Test Parent
744
+ assert service. getParents(parent). isEmpty()
745
+ def parent_children_expected = [new ChildInfo (newChild. toString(), type, childUUID),
746
+ new ChildInfo (child. toString(), type, " c_uuid2" )] as Set
747
+ assert parent_children_expected == service. getChildren(parent)
748
+
749
+ // Test new child
750
+ assert service. getParents(newChild) == child_parent_expected
751
+ assert service. getChildren(newChild). isEmpty()
752
+
753
+ // Test old child
754
+ assert service. getParents(child) == child_parent_expected
755
+ assert service. getChildren(child). isEmpty()
756
+ }
757
+
758
+ // Add a test where between rename and drop old/new name same name but different uuid is added
759
+ // only those get from rename should be drop
760
+ // This case is not possible in reality but wanted to add a test to prove this
761
+ def " Simulate Rename Parent: drop only impacted uuids" () {
762
+ setup :
763
+ def parent = QualifiedName . ofTable(catalog, database, " p" )
764
+ def parentUUID = " p_uuid"
765
+ def child = QualifiedName . ofTable(catalog, database, " c" )
766
+ def childUUID = " c_uuid"
767
+ def type = " clone"
768
+ service. createParentChildRelation(parent, parentUUID, child, childUUID, type, props)
769
+ def newParent = QualifiedName . ofTable(catalog, database, " np" )
770
+
771
+ when :
772
+ def pair = service. renameSoftInsert(parent, newParent)
773
+ // Add a record with the same parent name but different uuid and since this record is added after rename
774
+ // this record should not be dropped during the service.drop
775
+ insertNewParentChildRecord(parent. toString(), " p_uuid2" , child. toString(), " c_uuid1" , " clone" )
776
+ service. drop(parent, Optional . of(pair))
777
+ then :
778
+
779
+ // Test p
780
+ assert service. getParents(parent). isEmpty()
781
+ def parent_children_expected = [new ChildInfo (child. toString(), " clone" , " c_uuid1" )] as Set
782
+ assert parent_children_expected == service. getChildren(parent)
783
+
784
+ // Test np
785
+ assert service. getParents(newParent). isEmpty()
786
+ def new_parent_children_expected = [new ChildInfo (child. toString(), " clone" , childUUID)] as Set
787
+ assert new_parent_children_expected == service. getChildren(newParent)
788
+
789
+ // Test child
790
+ assert service. getChildren((child)). isEmpty()
791
+ def child_parent_expected = [
792
+ new ParentInfo (newParent. toString(), " clone" , parentUUID),
793
+ new ParentInfo (parent. toString(), " clone" , " p_uuid2" ),
794
+ ] as Set
795
+ assert service. getParents(child) == child_parent_expected
796
+ }
797
+
621
798
}
0 commit comments