@@ -394,7 +394,7 @@ public void Should_remove_server_from_the_seed_list_that_is_not_in_the_hosts_lis
394
394
}
395
395
396
396
[ Test ]
397
- public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_and_current_election_id_is_null ( )
397
+ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_and_current_set_version_and_election_id_are_null ( )
398
398
{
399
399
_settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
400
400
@@ -418,7 +418,7 @@ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_and_c
418
418
}
419
419
420
420
[ Test ]
421
- public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_an_election_id_and_current_id_is_null ( )
421
+ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_an_election_id_and_current_set_version_and_election_id_are_null ( )
422
422
{
423
423
_settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
424
424
@@ -427,7 +427,7 @@ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_
427
427
_capturedEvents . Clear ( ) ;
428
428
429
429
PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary ) ;
430
- PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
430
+ PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
431
431
432
432
var description = subject . Description ;
433
433
description . Servers . Should ( ) . BeEquivalentTo (
@@ -442,16 +442,16 @@ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_
442
442
}
443
443
444
444
[ Test ]
445
- public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_a_higher_election_id ( )
445
+ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_a_higher_set_version ( )
446
446
{
447
447
_settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
448
448
449
449
var subject = CreateSubject ( ) ;
450
450
subject . Initialize ( ) ;
451
451
_capturedEvents . Clear ( ) ;
452
452
453
- PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , electionId : new ElectionId ( ObjectId . Empty ) ) ;
454
- PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
453
+ PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . Empty ) ) ;
454
+ PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , setVersion : 2 , electionId : new ElectionId ( ObjectId . Empty ) ) ;
455
455
456
456
var description = subject . Description ;
457
457
description . Servers . Should ( ) . BeEquivalentTo (
@@ -466,16 +466,64 @@ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_
466
466
}
467
467
468
468
[ Test ]
469
- public void Should_invalidate_new_primary_when_it_shows_up_with_a_lesser_election_id ( )
469
+ public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_with_the_same_set_version_and_a_higher_election_id ( )
470
470
{
471
471
_settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
472
472
473
473
var subject = CreateSubject ( ) ;
474
474
subject . Initialize ( ) ;
475
475
_capturedEvents . Clear ( ) ;
476
476
477
- PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
478
- PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , electionId : new ElectionId ( ObjectId . Empty ) ) ;
477
+ PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . Empty ) ) ;
478
+ PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
479
+
480
+ var description = subject . Description ;
481
+ description . Servers . Should ( ) . BeEquivalentTo (
482
+ new [ ] { GetDisconnectedDescription ( _firstEndPoint ) }
483
+ . Concat ( GetDescriptions ( _secondEndPoint , _thirdEndPoint ) ) ) ;
484
+
485
+ _serverFactory . GetServer ( _firstEndPoint ) . Received ( ) . Invalidate ( ) ;
486
+
487
+ _capturedEvents . Next ( ) . Should ( ) . BeOfType < ClusterDescriptionChangedEvent > ( ) ;
488
+ _capturedEvents . Next ( ) . Should ( ) . BeOfType < ClusterDescriptionChangedEvent > ( ) ;
489
+ _capturedEvents . Any ( ) . Should ( ) . BeFalse ( ) ;
490
+ }
491
+
492
+ [ Test ]
493
+ public void Should_invalidate_new_primary_when_it_shows_up_with_a_lesser_set_version ( )
494
+ {
495
+ _settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
496
+
497
+ var subject = CreateSubject ( ) ;
498
+ subject . Initialize ( ) ;
499
+ _capturedEvents . Clear ( ) ;
500
+
501
+ PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , setVersion : 2 , electionId : new ElectionId ( ObjectId . Empty ) ) ;
502
+ PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
503
+
504
+ var description = subject . Description ;
505
+ description . Servers . Should ( ) . BeEquivalentTo (
506
+ new [ ] { GetDisconnectedDescription ( _secondEndPoint ) }
507
+ . Concat ( GetDescriptions ( _firstEndPoint , _thirdEndPoint ) ) ) ;
508
+
509
+ _serverFactory . GetServer ( _secondEndPoint ) . Received ( ) . Invalidate ( ) ;
510
+
511
+ _capturedEvents . Next ( ) . Should ( ) . BeOfType < ClusterDescriptionChangedEvent > ( ) ;
512
+ _capturedEvents . Next ( ) . Should ( ) . BeOfType < ClusterDescriptionChangedEvent > ( ) ;
513
+ _capturedEvents . Any ( ) . Should ( ) . BeFalse ( ) ;
514
+ }
515
+
516
+ [ Test ]
517
+ public void Should_invalidate_new_primary_when_it_shows_up_with_the_same_set_version_and_a_lesser_election_id ( )
518
+ {
519
+ _settings = _settings . With ( endPoints : new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ) ;
520
+
521
+ var subject = CreateSubject ( ) ;
522
+ subject . Initialize ( ) ;
523
+ _capturedEvents . Clear ( ) ;
524
+
525
+ PublishDescription ( _firstEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . GenerateNewId ( ) ) ) ;
526
+ PublishDescription ( _secondEndPoint , ServerType . ReplicaSetPrimary , setVersion : 1 , electionId : new ElectionId ( ObjectId . Empty ) ) ;
479
527
480
528
var description = subject . Description ;
481
529
description . Servers . Should ( ) . BeEquivalentTo (
@@ -617,15 +665,15 @@ private void PublishDisconnectedDescription(EndPoint endPoint)
617
665
_serverFactory . PublishDescription ( description ) ;
618
666
}
619
667
620
- private void PublishDescription ( EndPoint endPoint , ServerType serverType , IEnumerable < EndPoint > hosts = null , string setName = null , EndPoint primary = null , ElectionId electionId = null , EndPoint canonicalEndPoint = null )
668
+ private void PublishDescription ( EndPoint endPoint , ServerType serverType , IEnumerable < EndPoint > hosts = null , string setName = null , EndPoint primary = null , ElectionId electionId = null , EndPoint canonicalEndPoint = null , int ? setVersion = null )
621
669
{
622
670
var current = _serverFactory . GetServerDescription ( endPoint ) ;
623
671
624
672
var config = new ReplicaSetConfig (
625
673
hosts ?? new [ ] { _firstEndPoint , _secondEndPoint , _thirdEndPoint } ,
626
674
setName ?? "test" ,
627
675
primary ,
628
- null ) ;
676
+ setVersion ) ;
629
677
630
678
var description = current . With (
631
679
averageRoundTripTime : TimeSpan . FromMilliseconds ( 10 ) ,
0 commit comments