Skip to content

Commit 52d0c81

Browse files
committed
JAVA-2578: The logicSessionTimeoutMinutes should be the minimum of all reporting servers
1 parent e3c4894 commit 52d0c81

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

driver-core/src/main/com/mongodb/connection/ClusterDescription.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ public boolean apply(final ServerDescription serverDescription) {
184184
if (cur.getLogicalSessionTimeoutMinutes() == null) {
185185
return null;
186186
}
187-
retVal = cur.getLogicalSessionTimeoutMinutes();
187+
if (retVal == null) {
188+
retVal = cur.getLogicalSessionTimeoutMinutes();
189+
} else {
190+
retVal = Math.min(retVal, cur.getLogicalSessionTimeoutMinutes());
191+
}
188192
}
189193
return retVal;
190194
}

driver-core/src/test/unit/com/mongodb/connection/ClusterDescriptionTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,76 @@ public void clusterDescriptionWithCompatibleServerShouldBeCompatible() throws Un
231231
assertTrue(description.isCompatibleWithDriver());
232232
}
233233

234+
@Test
235+
public void testLogicalSessionTimeoutMinutes() {
236+
ClusterDescription description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
237+
builder().state(CONNECTING)
238+
.address(new ServerAddress("loc:27017")).build()
239+
));
240+
assertEquals(null, description.getLogicalSessionTimeoutMinutes());
241+
242+
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
243+
builder().state(CONNECTED)
244+
.address(new ServerAddress("loc:27017"))
245+
.build()
246+
));
247+
assertEquals(null, description.getLogicalSessionTimeoutMinutes());
248+
249+
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
250+
builder().state(CONNECTED)
251+
.ok(true)
252+
.address(new ServerAddress("loc:27017"))
253+
.build()
254+
));
255+
assertEquals(null, description.getLogicalSessionTimeoutMinutes());
256+
257+
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
258+
builder().state(CONNECTED)
259+
.ok(true)
260+
.address(new ServerAddress("loc:27017"))
261+
.logicalSessionTimeoutMinutes(5)
262+
.build(),
263+
builder().state(CONNECTING)
264+
.address(new ServerAddress("loc:27018"))
265+
.build()
266+
));
267+
assertEquals(new Integer(5), description.getLogicalSessionTimeoutMinutes());
268+
269+
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
270+
builder().state(CONNECTED)
271+
.ok(true)
272+
.address(new ServerAddress("loc:27017"))
273+
.logicalSessionTimeoutMinutes(5)
274+
.build(),
275+
builder().state(CONNECTED)
276+
.ok(true)
277+
.address(new ServerAddress("loc:27018"))
278+
.logicalSessionTimeoutMinutes(3)
279+
.build(),
280+
builder().state(CONNECTING)
281+
.address(new ServerAddress("loc:27017"))
282+
.build()
283+
));
284+
assertEquals(new Integer(3), description.getLogicalSessionTimeoutMinutes());
285+
286+
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
287+
builder().state(CONNECTED)
288+
.ok(true)
289+
.address(new ServerAddress("loc:27017"))
290+
.logicalSessionTimeoutMinutes(3)
291+
.build(),
292+
builder().state(CONNECTED)
293+
.ok(true)
294+
.address(new ServerAddress("loc:27018"))
295+
.logicalSessionTimeoutMinutes(5)
296+
.build(),
297+
builder().state(CONNECTING)
298+
.address(new ServerAddress("loc:27017"))
299+
.build()
300+
));
301+
assertEquals(new Integer(3), description.getLogicalSessionTimeoutMinutes());
302+
}
303+
234304
@Test
235305
public void testObjectOverrides() throws UnknownHostException {
236306
ClusterDescription description =

0 commit comments

Comments
 (0)