Skip to content

Commit 6e2b87c

Browse files
author
rstam
committed
Implemented CSHARP-489. Most of the work was improving the unit tests. The connection string classes only needed minor changes.
1 parent be03282 commit 6e2b87c

File tree

5 files changed

+1413
-308
lines changed

5 files changed

+1413
-308
lines changed

Driver/Core/MongoConnectionStringBuilder.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ public class MongoConnectionStringBuilder : DbConnectionStringBuilder
3737
{
3838
{ "connect", "connect" },
3939
{ "connecttimeout", "connectTimeout" },
40-
{ "connecttimeoutms", "connectTimeoutMS" },
40+
{ "connecttimeoutms", "connectTimeout" },
4141
{ "database", "database" },
4242
{ "fsync", "fsync" },
43-
{ "guids", "guids" },
44-
{ "j", "j" },
43+
{ "guids", "uuidRepresentation" },
44+
{ "j", "journal" },
45+
{ "journal", "journal" },
4546
{ "maxidletime", "maxIdleTime" },
47+
{ "maxidletimems", "maxIdleTime" },
4648
{ "maxlifetime", "maxLifeTime" },
49+
{ "maxlifetimems", "maxLifeTime" },
4750
{ "maxpoolsize", "maxPoolSize" },
4851
{ "minpoolsize", "minPoolSize" },
4952
{ "password", "password" },
@@ -53,13 +56,14 @@ public class MongoConnectionStringBuilder : DbConnectionStringBuilder
5356
{ "servers", "server" },
5457
{ "slaveok", "slaveOk" },
5558
{ "sockettimeout", "socketTimeout" },
56-
{ "sockettimeoutms", "socketTimeoutMS" },
59+
{ "sockettimeoutms", "socketTimeout" },
5760
{ "username", "username" },
61+
{ "uuidrepresentation", "uuidRepresentation" },
5862
{ "w", "w" },
5963
{ "waitqueuemultiple", "waitQueueMultiple" },
6064
{ "waitqueuesize", "waitQueueSize" },
6165
{ "waitqueuetimeout", "waitQueueTimeout" },
62-
{ "waitqueuetimeoutms", "waitQueueTimeoutMS" },
66+
{ "waitqueuetimeoutms", "waitQueueTimeout" },
6367
{ "wtimeout", "wtimeout" },
6468
{ "wtimeoutms", "wtimeout" }
6569
};
@@ -170,7 +174,7 @@ public GuidRepresentation GuidRepresentation
170174
get { return _guidRepresentation; }
171175
set
172176
{
173-
base["guids"] = _guidRepresentation = value;
177+
base["uuidRepresentation"] = _guidRepresentation = value;
174178
}
175179
}
176180

@@ -276,28 +280,28 @@ public SafeMode SafeMode
276280
if (value == null)
277281
{
278282
base["safe"] = null;
283+
base["fsync"] = null;
284+
base["journal"] = null;
279285
base["w"] = null;
280286
base["wtimeout"] = null;
281-
base["fsync"] = null;
282-
base["j"] = null;
283287
}
284288
else
285289
{
286290
if (value.Enabled)
287291
{
288292
base["safe"] = "true";
293+
base["fsync"] = (value.FSync) ? "true" : null;
294+
base["journal"] = (value.J) ? "true" : null;
289295
base["w"] = (value.W != 0) ? value.W.ToString() : (value.WMode != null) ? value.WMode : null;
290296
base["wtimeout"] = (value.W != 0 && value.WTimeout != TimeSpan.Zero) ? MongoUrlBuilder.FormatTimeSpan(value.WTimeout) : null;
291-
base["fsync"] = (value.FSync) ? "true" : null;
292-
base["j"] = (value.J) ? "true" : null;
293297
}
294298
else
295299
{
296300
base["safe"] = "false";
301+
base["fsync"] = null;
302+
base["journal"] = null;
297303
base["w"] = null;
298304
base["wtimeout"] = null;
299-
base["fsync"] = null;
300-
base["j"] = null;
301305
}
302306
}
303307
}
@@ -376,7 +380,9 @@ public double WaitQueueMultiple
376380
set
377381
{
378382
_waitQueueMultiple = value;
379-
base["waitQueueMultiple"] = (value != 0) ? XmlConvert.ToString(value) : null;
383+
_waitQueueSize = 0;
384+
base["waitQueueMultiple"] = (value != 0.0) ? XmlConvert.ToString(value) : null;
385+
base["waitQueueSize"] = null;
380386
}
381387
}
382388

@@ -389,7 +395,9 @@ public int WaitQueueSize
389395
set
390396
{
391397
_waitQueueSize = value;
398+
_waitQueueMultiple = 0.0;
392399
base["waitQueueSize"] = (value != 0) ? XmlConvert.ToString(value) : null;
400+
base["waitQueueMultiple"] = null;
393401
}
394402
}
395403

@@ -447,12 +455,14 @@ public override object this[string keyword]
447455
SafeMode = _safeMode;
448456
break;
449457
case "guids":
458+
case "uuidrepresentation":
450459
GuidRepresentation = (GuidRepresentation)Enum.Parse(typeof(GuidRepresentation), (string)value, true); // ignoreCase
451460
break;
452461
case "ipv6":
453462
IPv6 = Convert.ToBoolean(value);
454463
break;
455464
case "j":
465+
case "journal":
456466
if (_safeMode == null) { _safeMode = new SafeMode(false); }
457467
_safeMode.J = Convert.ToBoolean(value);
458468
SafeMode = _safeMode;
@@ -511,17 +521,16 @@ public override object this[string keyword]
511521
break;
512522
case "waitqueuemultiple":
513523
WaitQueueMultiple = Convert.ToDouble(value);
514-
WaitQueueSize = 0;
515524
break;
516525
case "waitqueuesize":
517526
WaitQueueSize = Convert.ToInt32(value);
518-
WaitQueueMultiple = 0;
519527
break;
520528
case "waitqueuetimeout":
521529
case "waitqueuetimeoutms":
522530
WaitQueueTimeout = ToTimeSpan(keyword, value);
523531
break;
524532
case "wtimeout":
533+
case "wtimeoutms":
525534
if (_safeMode == null) { _safeMode = new SafeMode(false); }
526535
_safeMode.WTimeout = ToTimeSpan(keyword, value);
527536
SafeMode = _safeMode;

Driver/Core/MongoUrlBuilder.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,27 +281,31 @@ public TimeSpan WaitQueueTimeout
281281
// these helper methods are shared with MongoConnectionStringBuilder
282282
internal static string FormatTimeSpan(TimeSpan value)
283283
{
284-
const int oneSecond = 1000; // milliseconds
285-
const int oneMinute = 60 * oneSecond;
286-
const int oneHour = 60 * oneMinute;
284+
const int msInOneSecond = 1000; // milliseconds
285+
const int msInOneMinute = 60 * msInOneSecond;
286+
const int msInOneHour = 60 * msInOneMinute;
287287

288288
var ms = (int)value.TotalMilliseconds;
289-
if ((ms % oneHour) == 0)
289+
if ((ms % msInOneHour) == 0)
290290
{
291-
return string.Format("{0}h", ms / oneHour);
291+
return string.Format("{0}h", ms / msInOneHour);
292292
}
293-
else if ((ms % oneMinute) == 0)
293+
else if ((ms % msInOneMinute) == 0 && ms < msInOneHour)
294294
{
295-
return string.Format("{0}m", ms / oneMinute);
295+
return string.Format("{0}m", ms / msInOneMinute);
296296
}
297-
else if ((ms % oneSecond) == 0)
297+
else if ((ms % msInOneSecond) == 0 && ms < msInOneMinute)
298298
{
299-
return string.Format("{0}s", ms / oneSecond);
299+
return string.Format("{0}s", ms / msInOneSecond);
300300
}
301-
else
301+
else if (ms < 1000)
302302
{
303303
return string.Format("{0}ms", ms);
304304
}
305+
else
306+
{
307+
return value.ToString();
308+
}
305309
}
306310

307311
internal static ConnectionMode ParseConnectionMode(string name, string s)
@@ -373,7 +377,7 @@ internal static bool TryParseTimeSpan(string name, string s, out TimeSpan result
373377
s = s.ToLower();
374378
var end = s.Length - 1;
375379

376-
var multiplier = 1000;
380+
var multiplier = 1000; // default units are seconds
377381
if (name.EndsWith("ms", StringComparison.Ordinal))
378382
{
379383
multiplier = 1;
@@ -508,12 +512,14 @@ public void Parse(string url)
508512
_safeMode.FSync = ParseBoolean(name, value);
509513
break;
510514
case "guids":
515+
case "uuidrepresentation":
511516
_guidRepresentation = (GuidRepresentation)Enum.Parse(typeof(GuidRepresentation), value, true); // ignoreCase
512517
break;
513518
case "ipv6":
514519
_ipv6 = ParseBoolean(name, value);
515520
break;
516521
case "j":
522+
case "journal":
517523
if (_safeMode == null) { _safeMode = new SafeMode(false); }
518524
SafeMode.J = ParseBoolean(name, value);
519525
break;
@@ -665,7 +671,7 @@ public override string ToString()
665671
}
666672
if (_safeMode.J)
667673
{
668-
query.Append("j=true;");
674+
query.Append("journal=true;");
669675
}
670676
if (_safeMode.W != 0 || _safeMode.WMode != null)
671677
{
@@ -721,7 +727,7 @@ public override string ToString()
721727
}
722728
if (_guidRepresentation != MongoDefaults.GuidRepresentation)
723729
{
724-
query.AppendFormat("guids={0};", _guidRepresentation);
730+
query.AppendFormat("uuidRepresentation={0};", _guidRepresentation);
725731
}
726732
if (query.Length != 0)
727733
{

0 commit comments

Comments
 (0)