@@ -33,7 +33,7 @@ import static com.mongodb.ClusterFixture.serverVersionAtLeast
33
33
import static com.mongodb.Fixture.getDefaultDatabaseName
34
34
import static com.mongodb.Fixture.getMongoClientURI
35
35
36
- class MongoClientsSpecification extends FunctionalSpecification {
36
+ class MongoClientsSpecification extends FunctionalSpecification {
37
37
@IgnoreIf ({ !serverVersionAtLeast(3 , 4 ) || !isStandalone() })
38
38
def ' application name should appear in the system.profile collection' () {
39
39
given :
@@ -64,17 +64,22 @@ class MongoClientsSpecification extends FunctionalSpecification {
64
64
@IgnoreIf ({ !isDiscoverableReplicaSet() })
65
65
def ' should use server selector from MongoClientOptions' () {
66
66
given :
67
- def expectedWinner
67
+ def expectedWinningAddresses = [] as Set
68
68
def actualWinningAddresses = [] as Set
69
69
def optionsBuilder = MongoClientOptions . builder()
70
70
// select the suitable server with the highest port number
71
71
.serverSelector { ClusterDescription clusterDescription ->
72
+ def highestPortServer
72
73
for (ServerDescription cur : clusterDescription. getServerDescriptions()) {
73
- if (expectedWinner == null || cur. address. port > expectedWinner . address. port) {
74
- expectedWinner = cur
74
+ if (highestPortServer == null || cur. address. port > highestPortServer . address. port) {
75
+ highestPortServer = cur
75
76
}
76
77
}
77
- expectedWinner == null ? [] : [expectedWinner]
78
+ if (highestPortServer == null ) {
79
+ return []
80
+ }
81
+ expectedWinningAddresses. add(highestPortServer. address)
82
+ [highestPortServer]
78
83
}. addCommandListener(new CommandListener () {
79
84
// record each address actually used
80
85
@Override
@@ -101,7 +106,6 @@ class MongoClientsSpecification extends FunctionalSpecification {
101
106
}
102
107
103
108
then :
104
- actualWinningAddresses. size() == 1
105
- actualWinningAddresses. contains(expectedWinner. address)
109
+ actualWinningAddresses == expectedWinningAddresses
106
110
}
107
111
}
0 commit comments