@@ -115,6 +115,34 @@ class MultiServerClusterSpecification extends Specification {
115115 getClusterDescription(cluster). all == getServerDescriptions(firstServer, secondServer, thirdServer)
116116 }
117117
118+ def ' should remove a secondary server whose reported host name does not match the address connected to' () {
119+ given :
120+ def seedListAddress = new ServerAddress (' 127.0.0.1:27017' )
121+ def cluster = new MultiServerCluster (CLUSTER_ID ,
122+ ClusterSettings . builder(). hosts([seedListAddress]). build(), factory,
123+ CLUSTER_LISTENER );
124+
125+ when :
126+ sendNotification(seedListAddress, ReplicaSetSecondary , [firstServer, secondServer], ' test' , firstServer)
127+
128+ then :
129+ getClusterDescription(cluster). all == getServerDescriptions(firstServer, secondServer)
130+ }
131+
132+ def ' should remove a primary server whose reported host name does not match the address connected to' () {
133+ given :
134+ def seedListAddress = new ServerAddress (' 127.0.0.1:27017' )
135+ def cluster = new MultiServerCluster (CLUSTER_ID ,
136+ ClusterSettings . builder(). hosts([seedListAddress]). build(), factory,
137+ CLUSTER_LISTENER );
138+
139+ when :
140+ sendNotification(seedListAddress, ReplicaSetPrimary , [firstServer, secondServer], ' test' , firstServer)
141+
142+ then :
143+ getClusterDescription(cluster). all == getServerDescriptions(firstServer, secondServer)
144+ }
145+
118146 def ' should remove a server when it no longer appears in hosts reported by the primary' () {
119147 given :
120148 def cluster = new MultiServerCluster (CLUSTER_ID ,
@@ -480,19 +508,25 @@ class MultiServerClusterSpecification extends Specification {
480508 sendNotification(serverAddress, serverType, hosts, [], setName)
481509 }
482510
511+ def sendNotification (ServerAddress serverAddress , ServerType serverType , List<ServerAddress > hosts , String setName ,
512+ ServerAddress trueAddress ) {
513+ factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, [], true , setName, null , trueAddress)
514+ .build())
515+ }
516+
483517 def sendNotification (ServerAddress serverAddress , ServerType serverType , List<ServerAddress > hosts , List<ServerAddress > passives ,
484518 String setName ) {
485- factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, passives, true , setName, null )
519+ factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, passives, true , setName, null , null )
486520 .build())
487521 }
488522
489523 def sendNotification (ServerAddress serverAddress , ServerType serverType , List<ServerAddress > hosts , ObjectId electionId ) {
490- factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, [], true , ' test' , electionId)
524+ factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, [], true , ' test' , electionId, null )
491525 .build())
492526 }
493527
494528 def sendNotification (ServerAddress serverAddress , ServerType serverType , List<ServerAddress > hosts , boolean ok ) {
495- factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, [], ok, null , null ). build())
529+ factory. getServer(serverAddress). sendNotification(getBuilder(serverAddress, serverType, hosts, [], ok, null , null , null ). build())
496530 }
497531
498532 def getClusterDescription (MultiServerCluster cluster ) {
@@ -508,10 +542,11 @@ class MultiServerClusterSpecification extends Specification {
508542 }
509543
510544 def getBuilder (ServerAddress serverAddress , ServerType serverType , List<ServerAddress > hosts , List<ServerAddress > passives , boolean ok ,
511- String setName , ObjectId electionId ) {
545+ String setName , ObjectId electionId , ServerAddress trueAddress ) {
512546 ServerDescription . builder()
513547 .address(serverAddress)
514548 .type(serverType)
549+ .canonicalAddress(trueAddress == null ? serverAddress. toString() : trueAddress. toString())
515550 .ok(ok)
516551 .state(Connected )
517552 .hosts(hosts* . toString() as Set )
0 commit comments