Skip to content

Commit ff777fb

Browse files
committed
Change behavior of ClusterFixture.getServerVersion to wait for an ok server
Replace ClusterFixture.getConnectedServerVersion with ClusterFixture.getServerVersion
1 parent 2f1c00f commit ff777fb

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

driver-core/src/test/functional/com/mongodb/ClusterFixture.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.mongodb.operation.DropDatabaseOperation;
5050
import com.mongodb.operation.ReadOperation;
5151
import com.mongodb.operation.WriteOperation;
52+
import com.mongodb.selector.ServerSelector;
5253
import org.bson.BsonDocument;
5354
import org.bson.BsonDocumentWrapper;
5455
import org.bson.BsonInt32;
@@ -103,25 +104,30 @@ public static boolean clusterIsType(final ClusterType clusterType) {
103104
return getCluster().getDescription().getType() == clusterType;
104105
}
105106

106-
@SuppressWarnings("deprecation")
107107
public static ServerVersion getServerVersion() {
108-
return getCluster().getDescription().getAny().get(0).getVersion();
108+
return getCluster().selectServer(new ServerSelector() {
109+
@Override
110+
@SuppressWarnings("deprecation")
111+
public List<ServerDescription> select(final ClusterDescription clusterDescription) {
112+
return clusterDescription.getAny();
113+
}
114+
}).getDescription().getVersion();
109115
}
110116

111117
public static boolean serverVersionAtLeast(final List<Integer> versionArray) {
112-
return getConnectedServerVersion().compareTo(new ServerVersion(versionArray)) >= 0;
118+
return getServerVersion().compareTo(new ServerVersion(versionArray)) >= 0;
113119
}
114120

115121
public static boolean serverVersionAtLeast(final int majorVersion, final int minorVersion) {
116122
return serverVersionAtLeast(asList(majorVersion, minorVersion, 0));
117123
}
118124

119125
public static boolean serverVersionLessThan(final String versionString) {
120-
return getConnectedServerVersion().compareTo(new ServerVersion(getVersionList(versionString).subList(0, 3))) < 0;
126+
return getServerVersion().compareTo(new ServerVersion(getVersionList(versionString).subList(0, 3))) < 0;
121127
}
122128

123129
public static boolean serverVersionGreaterThan(final String versionString) {
124-
return getConnectedServerVersion().compareTo(new ServerVersion(getVersionList(versionString).subList(0, 3))) > 0;
130+
return getServerVersion().compareTo(new ServerVersion(getVersionList(versionString).subList(0, 3))) > 0;
125131
}
126132

127133
private static List<Integer> getVersionList(final String versionString) {
@@ -163,25 +169,6 @@ public static boolean supportsFsync() {
163169
return storageEngine != null && !storageEngine.get("name").equals("inMemory");
164170
}
165171

166-
@SuppressWarnings("deprecation")
167-
public static ServerVersion getConnectedServerVersion() {
168-
ClusterDescription clusterDescription = getCluster().getDescription();
169-
int retries = 0;
170-
while (clusterDescription.getAny().isEmpty() && retries <= 3) {
171-
try {
172-
Thread.sleep(1000);
173-
retries++;
174-
} catch (InterruptedException e) {
175-
throw new RuntimeException("Interrupted", e);
176-
}
177-
clusterDescription = getCluster().getDescription();
178-
}
179-
if (clusterDescription.getAny().isEmpty()) {
180-
throw new RuntimeException("There are no servers available in " + clusterDescription);
181-
}
182-
return clusterDescription.getAny().get(0).getVersion();
183-
}
184-
185172
public static boolean isNotAtLeastJava7() {
186173
return javaVersionStartsWith("1.6");
187174
}

0 commit comments

Comments
 (0)