@@ -115,11 +115,11 @@ public void publishAndLoadASnapshot() {
115
115
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
116
116
Assert .assertFalse (idx .containsDuplicates ());
117
117
118
- assertTypeB (idx , 1 , "1" );
119
- assertTypeB (idx , 2 , null );
120
- assertTypeB (idx , 3 , null );
121
- assertTypeB (idx , 4 , "4" );
122
- assertTypeB (idx , 5 , "6" );
118
+ assertTypeBOrE (idx , 1 , "1" );
119
+ assertTypeBOrE (idx , 2 , null );
120
+ assertTypeBOrE (idx , 3 , null );
121
+ assertTypeBOrE (idx , 4 , "4" );
122
+ assertTypeBOrE (idx , 5 , "6" );
123
123
124
124
consumer .triggerRefreshTo (finalVersion );
125
125
@@ -271,11 +271,11 @@ public void publishAndLoadASnapshotDirectly() {
271
271
Assert .assertFalse (idx .containsDuplicates ());
272
272
273
273
// backing producer was never initialized, so only records added to the incremental producer are here
274
- assertTypeB (idx , 1 , null );
275
- assertTypeB (idx , 2 , null );
276
- assertTypeB (idx , 3 , null );
277
- assertTypeB (idx , 4 , null );
278
- assertTypeB (idx , 5 , "6" );
274
+ assertTypeBOrE (idx , 1 , null );
275
+ assertTypeBOrE (idx , 2 , null );
276
+ assertTypeBOrE (idx , 3 , null );
277
+ assertTypeBOrE (idx , 4 , null );
278
+ assertTypeBOrE (idx , 5 , "6" );
279
279
280
280
consumer .triggerRefreshTo (finalVersion );
281
281
@@ -330,12 +330,12 @@ public void publishDirectlyAndRestore() {
330
330
Assert .assertFalse (idx .containsDuplicates ());
331
331
332
332
// backing producer was never initialized, so only records added to the incremental producer are here
333
- assertTypeB (idx , 1 , null );
334
- assertTypeB (idx , 2 , null );
335
- assertTypeB (idx , 3 , null );
336
- assertTypeB (idx , 4 , null );
337
- assertTypeB (idx , 5 , "5" );
338
- assertTypeB (idx , 6 , "6" );
333
+ assertTypeBOrE (idx , 1 , null );
334
+ assertTypeBOrE (idx , 2 , null );
335
+ assertTypeBOrE (idx , 3 , null );
336
+ assertTypeBOrE (idx , 4 , null );
337
+ assertTypeBOrE (idx , 5 , "5" );
338
+ assertTypeBOrE (idx , 6 , "6" );
339
339
340
340
// Create NEW incremental producer which will restore from the state left by the previous incremental producer
341
341
/// adding a new type this time (TypeB).
@@ -375,12 +375,12 @@ public void publishDirectlyAndRestore() {
375
375
Assert .assertFalse (idx .containsDuplicates ());
376
376
377
377
// backing producer was never initialized, so only records added to the incremental producer are here
378
- assertTypeB (idx , 1 , "1" );
379
- assertTypeB (idx , 2 , "2" );
380
- assertTypeB (idx , 3 , "3" );
381
- assertTypeB (idx , 4 , "4" );
382
- assertTypeB (idx , 5 , null );
383
- assertTypeB (idx , 6 , "6" );
378
+ assertTypeBOrE (idx , 1 , "1" );
379
+ assertTypeBOrE (idx , 2 , "2" );
380
+ assertTypeBOrE (idx , 3 , "3" );
381
+ assertTypeBOrE (idx , 4 , "4" );
382
+ assertTypeBOrE (idx , 5 , null );
383
+ assertTypeBOrE (idx , 6 , "6" );
384
384
385
385
}
386
386
@@ -431,7 +431,7 @@ public void populate(WriteState state) throws Exception {
431
431
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
432
432
Assert .assertFalse (idx .containsDuplicates ());
433
433
434
- assertTypeB (idx , 3 , "three" );
434
+ assertTypeBOrE (idx , 3 , "three" );
435
435
}
436
436
437
437
@ Test
@@ -442,6 +442,7 @@ public void canRemoveAndModifyNewTypesFromRestoredState() {
442
442
long originalVersion = genesisProducer .runCycle (new Populator () {
443
443
public void populate (WriteState state ) throws Exception {
444
444
state .add (new TypeA (1 , "one" , 1 ));
445
+ state .add (new TypeB (2 , "two" ));
445
446
}
446
447
});
447
448
@@ -452,22 +453,22 @@ public void populate(WriteState state) throws Exception {
452
453
.noIntegrityCheck ()
453
454
.build ();
454
455
455
- /// adding a new type this time (TypeB).
456
- backingProducer .initializeDataModel (TypeA .class , TypeB .class );
456
+ /// adding a new type this time (TypeE) and removing TypeB
457
+ backingProducer .initializeDataModel (TypeA .class , TypeE .class );
457
458
458
459
/// now create our HollowIncrementalProducer
459
460
HollowIncrementalProducer incrementalProducer = new HollowIncrementalProducer (backingProducer );
460
461
incrementalProducer .restore (originalVersion , blobStore );
461
462
462
463
incrementalProducer .addOrModify (new TypeA (1 , "one" , 2 ));
463
- incrementalProducer .addOrModify (new TypeA (2 , "two " , 2 ));
464
- incrementalProducer .addOrModify (new TypeB ( 3 , "three " ));
465
- incrementalProducer .addOrModify (new TypeB ( 4 , "four " ));
464
+ incrementalProducer .addOrModify (new TypeA (3 , "three " , 3 ));
465
+ incrementalProducer .addOrModify (new TypeE ( 4 , "four " ));
466
+ incrementalProducer .addOrModify (new TypeE ( 5 , "five " ));
466
467
467
468
incrementalProducer .runCycle ();
468
469
469
- incrementalProducer .delete (new RecordPrimaryKey ("TypeB " , new Object [] { 3 }));
470
- incrementalProducer .addOrModify (new TypeB ( 4 , "four !" ));
470
+ incrementalProducer .delete (new RecordPrimaryKey ("TypeE " , new Object [] { 4 }));
471
+ incrementalProducer .addOrModify (new TypeE ( 5 , "five !" ));
471
472
472
473
long version2 = incrementalProducer .runCycle ();
473
474
@@ -479,17 +480,21 @@ public void populate(WriteState state) throws Exception {
479
480
Assert .assertFalse (idx .containsDuplicates ());
480
481
481
482
assertTypeA (idx , 1 , "one" , 2L );
482
- assertTypeA (idx , 2 , "two " , 2L );
483
+ assertTypeA (idx , 3 , "three " , 3L );
483
484
484
485
/// consumers with established data models don't have visibility into new types.
485
486
consumer = HollowConsumer .withBlobRetriever (blobStore ).build ();
486
487
consumer .triggerRefreshTo (version2 );
487
488
488
- idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
489
+ Assert .assertNotNull (consumer .getStateEngine ().getTypeState ("TypeA" ));
490
+ Assert .assertNull (consumer .getStateEngine ().getTypeState ("TypeB" ));
491
+ Assert .assertNotNull (consumer .getStateEngine ().getTypeState ("TypeE" ));
492
+
493
+ idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeE" , "id" );
489
494
Assert .assertFalse (idx .containsDuplicates ());
490
495
491
- assertEquals (-1 , idx .getMatchingOrdinal (3 ));
492
- assertTypeB (idx , 4 , "four !" );
496
+ assertEquals (-1 , idx .getMatchingOrdinal (4 ));
497
+ assertTypeBOrE (idx , 5 , "five !" );
493
498
}
494
499
495
500
@ Test
@@ -541,7 +546,7 @@ public void populate(WriteState state) throws Exception {
541
546
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
542
547
Assert .assertFalse (idx .containsDuplicates ());
543
548
544
- assertTypeB (idx , 3 , "three" );
549
+ assertTypeBOrE (idx , 3 , "three" );
545
550
}
546
551
547
552
@ Test (expected = RuntimeException .class )
@@ -627,11 +632,11 @@ public void publishUsingThreadConfig() {
627
632
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
628
633
Assert .assertFalse (idx .containsDuplicates ());
629
634
630
- assertTypeB (idx , 1 , "1" );
631
- assertTypeB (idx , 2 , null );
632
- assertTypeB (idx , 3 , null );
633
- assertTypeB (idx , 4 , "4" );
634
- assertTypeB (idx , 5 , "6" );
635
+ assertTypeBOrE (idx , 1 , "1" );
636
+ assertTypeBOrE (idx , 2 , null );
637
+ assertTypeBOrE (idx , 3 , null );
638
+ assertTypeBOrE (idx , 4 , "4" );
639
+ assertTypeBOrE (idx , 5 , "6" );
635
640
636
641
consumer .triggerRefreshTo (finalVersion );
637
642
@@ -664,7 +669,7 @@ public void discardChanges() {
664
669
665
670
HollowPrimaryKeyIndex idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
666
671
667
- assertTypeB (idx , 1 , "one" );
672
+ assertTypeBOrE (idx , 1 , "one" );
668
673
669
674
incrementalProducer .delete (new TypeB (1 , "one" ));
670
675
@@ -680,7 +685,7 @@ public void discardChanges() {
680
685
consumer = HollowConsumer .withBlobRetriever (blobStore ).build ();
681
686
consumer .triggerRefreshTo (version );
682
687
683
- assertTypeB (idx , 1 , "one" );
688
+ assertTypeBOrE (idx , 1 , "one" );
684
689
685
690
incrementalProducer .delete (new TypeB (1 , "one" ));
686
691
@@ -696,7 +701,7 @@ public void discardChanges() {
696
701
consumer = HollowConsumer .withBlobRetriever (blobStore ).build ();
697
702
consumer .triggerRefreshTo (finalVersion );
698
703
699
- assertTypeB (idx , 1 , "one" );
704
+ assertTypeBOrE (idx , 1 , "one" );
700
705
}
701
706
702
707
@ Test
@@ -780,11 +785,11 @@ public void addAndDeleteCollections() {
780
785
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
781
786
Assert .assertFalse (idx .containsDuplicates ());
782
787
783
- assertTypeB (idx , 1 , "1" );
784
- assertTypeB (idx , 2 , null );
785
- assertTypeB (idx , 3 , "3" );
786
- assertTypeB (idx , 4 , "4" );
787
- assertTypeB (idx , 5 , null );
788
+ assertTypeBOrE (idx , 1 , "1" );
789
+ assertTypeBOrE (idx , 2 , null );
790
+ assertTypeBOrE (idx , 3 , "3" );
791
+ assertTypeBOrE (idx , 4 , "4" );
792
+ assertTypeBOrE (idx , 5 , null );
788
793
789
794
consumer .triggerRefreshTo (finalVersion );
790
795
@@ -849,11 +854,11 @@ public void addAndDeleteCollectionsInParallel() {
849
854
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
850
855
Assert .assertFalse (idx .containsDuplicates ());
851
856
852
- assertTypeB (idx , 1 , "1" );
853
- assertTypeB (idx , 2 , null );
854
- assertTypeB (idx , 3 , "3" );
855
- assertTypeB (idx , 4 , "4" );
856
- assertTypeB (idx , 5 , null );
857
+ assertTypeBOrE (idx , 1 , "1" );
858
+ assertTypeBOrE (idx , 2 , null );
859
+ assertTypeBOrE (idx , 3 , "3" );
860
+ assertTypeBOrE (idx , 4 , "4" );
861
+ assertTypeBOrE (idx , 5 , null );
857
862
858
863
consumer .triggerRefreshTo (finalVersion );
859
864
@@ -919,11 +924,11 @@ public void discardCollections() {
919
924
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
920
925
Assert .assertFalse (idx .containsDuplicates ());
921
926
922
- assertTypeB (idx , 1 , "1" );
923
- assertTypeB (idx , 2 , "2" );
924
- assertTypeB (idx , 3 , "3" );
925
- assertTypeB (idx , 4 , "4" );
926
- assertTypeB (idx , 5 , null );
927
+ assertTypeBOrE (idx , 1 , "1" );
928
+ assertTypeBOrE (idx , 2 , "2" );
929
+ assertTypeBOrE (idx , 3 , "3" );
930
+ assertTypeBOrE (idx , 4 , "4" );
931
+ assertTypeBOrE (idx , 5 , null );
927
932
}
928
933
929
934
@ Test
@@ -977,11 +982,11 @@ public void discardCollectionsInParallel() {
977
982
idx = new HollowPrimaryKeyIndex (consumer .getStateEngine (), "TypeB" , "id" );
978
983
Assert .assertFalse (idx .containsDuplicates ());
979
984
980
- assertTypeB (idx , 1 , "1" );
981
- assertTypeB (idx , 2 , "2" );
982
- assertTypeB (idx , 3 , "3" );
983
- assertTypeB (idx , 4 , "4" );
984
- assertTypeB (idx , 5 , null );
985
+ assertTypeBOrE (idx , 1 , "1" );
986
+ assertTypeBOrE (idx , 2 , "2" );
987
+ assertTypeBOrE (idx , 3 , "3" );
988
+ assertTypeBOrE (idx , 4 , "4" );
989
+ assertTypeBOrE (idx , 5 , null );
985
990
}
986
991
987
992
@ Test
@@ -1478,16 +1483,16 @@ private void assertTypeA(HollowPrimaryKeyIndex typeAIdx, int id1,
1478
1483
}
1479
1484
}
1480
1485
1481
- private void assertTypeB (HollowPrimaryKeyIndex typeBIdx , int id1 ,
1482
- String expectedValue ) {
1483
- int ordinal = typeBIdx .getMatchingOrdinal (id1 );
1486
+ private void assertTypeBOrE (HollowPrimaryKeyIndex typeIdx , int id1 ,
1487
+ String expectedValue ) {
1488
+ int ordinal = typeIdx .getMatchingOrdinal (id1 );
1484
1489
1485
1490
if (expectedValue == null ) {
1486
1491
Assert .assertEquals (-1 , ordinal );
1487
1492
} else {
1488
1493
Assert .assertNotEquals (-1 , ordinal );
1489
1494
GenericHollowObject obj = new GenericHollowObject (
1490
- typeBIdx .getTypeState (), ordinal );
1495
+ typeIdx .getTypeState (), ordinal );
1491
1496
Assert .assertEquals (expectedValue , obj .getObject ("value" )
1492
1497
.getString ("value" ));
1493
1498
}
@@ -1543,6 +1548,18 @@ public TypeD(int id, String name) {
1543
1548
}
1544
1549
}
1545
1550
1551
+ @ HollowPrimaryKey (fields = "id" )
1552
+ private static class TypeE {
1553
+ int id ;
1554
+ @ HollowTypeName (name = "TypeEValue" )
1555
+ String value ;
1556
+
1557
+ public TypeE (int id , String value ) {
1558
+ this .id = id ;
1559
+ this .value = value ;
1560
+ }
1561
+ }
1562
+
1546
1563
private Collection <HollowObject > getAllHollowObjects (HollowConsumer hollowConsumer , final String type ) {
1547
1564
final HollowReadStateEngine readStateEngine = hollowConsumer .getStateEngine ();
1548
1565
final HollowTypeDataAccess typeDataAccess = readStateEngine .getTypeDataAccess (type );
0 commit comments