@@ -510,6 +510,132 @@ public void testPropertyAssumptionInvalidation() {
510
510
assertFalse (assumption .toString (), assumption .isValid ());
511
511
}
512
512
513
+ /**
514
+ * Tests that property assumptions are blocked after remove property transitions.
515
+ */
516
+ @ Test
517
+ public void testPropertyAssumptionInvalidAfterRemove () {
518
+ Shape emptyShape = Shape .newBuilder ().propertyAssumptions (true ).build ();
519
+
520
+ DynamicObject h1 = new TestDynamicObject (emptyShape );
521
+ DynamicObjectLibrary on = createLibrary (DynamicObjectLibrary .class , h1 );
522
+ DynamicObjectLibrary off = createLibrary (DynamicObjectLibrary .class , h1 );
523
+
524
+ // initialize caches
525
+ on .put (h1 , "name" , h1 );
526
+ on .put (h1 , "alias" , h1 );
527
+ off .removeKey (h1 , "name" );
528
+ off .removeKey (h1 , "alias" );
529
+
530
+ DynamicObject h2 = new TestDynamicObject (emptyShape );
531
+ // repeat on another object with cached transitions
532
+ on .put (h2 , "name" , h2 );
533
+ on .put (h2 , "alias" , h2 );
534
+
535
+ Assumption aliasAssumption = h2 .getShape ().getPropertyAssumption ("alias" );
536
+ assertFalse ("Property assumption for 'alias' should already be invalid: " + aliasAssumption , aliasAssumption .isValid ());
537
+
538
+ on .put (h2 , "alias" , h2 );
539
+ off .removeKey (h2 , "name" );
540
+ off .removeKey (h2 , "alias" );
541
+ }
542
+
543
+ /**
544
+ * Tests that property assumptions are blocked after replace property transitions.
545
+ */
546
+ @ Test
547
+ public void testPropertyAssumptionInvalidAfterReplace1 () {
548
+ assumeExtLayout ();
549
+
550
+ Shape emptyShape = Shape .newBuilder ().propertyAssumptions (true ).build ();
551
+
552
+ int flag = 2 ;
553
+ DynamicObject h1 = new TestDynamicObject (emptyShape );
554
+ DynamicObjectLibrary on = createLibrary (DynamicObjectLibrary .class , h1 );
555
+ DynamicObjectLibrary off = createLibrary (DynamicObjectLibrary .class , h1 );
556
+
557
+ // initialize caches
558
+ on .put (h1 , "name" , h1 );
559
+ on .put (h1 , "alias" , h1 );
560
+ off .setPropertyFlags (h1 , "name" , flag );
561
+ off .setPropertyFlags (h1 , "alias" , flag );
562
+
563
+ DynamicObject h2 = new TestDynamicObject (emptyShape );
564
+ // repeat cached operations on another object
565
+ on .put (h2 , "name" , h2 );
566
+ on .put (h2 , "alias" , h2 );
567
+
568
+ Assumption aliasAssumption = h2 .getShape ().getPropertyAssumption ("alias" );
569
+ assertFalse ("Property assumption for 'alias' should already be invalid: " + aliasAssumption , aliasAssumption .isValid ());
570
+
571
+ on .put (h2 , "alias" , h2 );
572
+ off .setPropertyFlags (h2 , "name" , flag );
573
+ off .setPropertyFlags (h2 , "alias" , flag );
574
+
575
+ assertEquals (flag , h2 .getShape ().getProperty ("name" ).getFlags ());
576
+ assertEquals (flag , h2 .getShape ().getProperty ("alias" ).getFlags ());
577
+ }
578
+
579
+ /**
580
+ * Tests that property assumptions are blocked after replace property transitions.
581
+ */
582
+ @ Test
583
+ public void testPropertyAssumptionInvalidAfterReplace2 () {
584
+ assumeExtLayout ();
585
+
586
+ Shape emptyShape = Shape .newBuilder ().propertyAssumptions (true ).build ();
587
+
588
+ int flag = 2 ;
589
+ DynamicObject h1 = new TestDynamicObject (emptyShape );
590
+ DynamicObjectLibrary on = createLibrary (DynamicObjectLibrary .class , h1 );
591
+ DynamicObjectLibrary off = createLibrary (DynamicObjectLibrary .class , h1 );
592
+
593
+ // initialize caches
594
+ on .put (h1 , "name" , h1 );
595
+ on .put (h1 , "alias" , h1 );
596
+ off .putWithFlags (h1 , "name" , h1 , flag );
597
+ off .putWithFlags (h1 , "alias" , h1 , flag );
598
+
599
+ DynamicObject h2 = new TestDynamicObject (emptyShape );
600
+ // repeat cached operations on another object
601
+ on .put (h2 , "name" , h2 );
602
+ on .put (h2 , "alias" , h2 );
603
+
604
+ Assumption aliasAssumption = h2 .getShape ().getPropertyAssumption ("alias" );
605
+ assertFalse ("Property assumption for 'alias' should already be invalid: " + aliasAssumption , aliasAssumption .isValid ());
606
+
607
+ on .put (h2 , "alias" , h2 );
608
+ off .putWithFlags (h2 , "name" , h2 , flag );
609
+ off .putWithFlags (h2 , "alias" , h2 , flag );
610
+
611
+ assertEquals (flag , h2 .getShape ().getProperty ("name" ).getFlags ());
612
+ assertEquals (flag , h2 .getShape ().getProperty ("alias" ).getFlags ());
613
+ }
614
+
615
+ /**
616
+ * Tests that property assumptions are invalid after value type transitions.
617
+ */
618
+ @ Test
619
+ public void testPropertyAssumptionInvalidAfterTypeTransition () {
620
+ Shape emptyShape = Shape .newBuilder ().propertyAssumptions (true ).build ();
621
+
622
+ DynamicObject h1 = new TestDynamicObject (emptyShape );
623
+ DynamicObjectLibrary lib = createLibrary (DynamicObjectLibrary .class , h1 );
624
+
625
+ // initialize caches
626
+ lib .put (h1 , "name" , 42 );
627
+ lib .put (h1 , "alias" , 43 );
628
+
629
+ Assumption aliasAssumption = h1 .getShape ().getPropertyAssumption ("alias" );
630
+
631
+ DynamicObject h2 = new TestDynamicObject (emptyShape );
632
+ // repeat cached operations on another object
633
+ lib .put (h2 , "name" , 42 );
634
+ lib .put (h2 , "alias" , h1 );
635
+
636
+ assertFalse ("Property assumption for 'alias' should be invalid: " + aliasAssumption , aliasAssumption .isValid ());
637
+ }
638
+
513
639
static class TestDynamicObject extends DynamicObject {
514
640
protected TestDynamicObject (Shape shape ) {
515
641
super (shape );
0 commit comments