Browse files

CSHARP-646: added new properties to SystemProfileInfo for server 2.2.

  • Loading branch information...
1 parent 93b2f6e commit 351e4ba8425fc7306d4ba4d158f0060019bc8d47 rstam committed Dec 26, 2012
View
102 MongoDB.Driver/SystemProfileInfo.cs
@@ -84,7 +84,7 @@ public BsonDocument Command
/// </summary>
public long CursorId
{
- get { return (long)GetValue("CursorId", 0L); }
+ get { return (long)GetValue("CursorId", -1L); }
set { SetValue("CursorId", value); }
}
@@ -120,7 +120,7 @@ public string Exception
/// </summary>
public int ExceptionCode
{
- get { return GetValue<int>("ExceptionCode", 0); }
+ get { return GetValue<int>("ExceptionCode", -1); }
set { SetValue("ExceptionCode", value); }
}
@@ -174,7 +174,7 @@ public string Info
/// </summary>
public int KeyUpdates
{
- get { return GetValue<int>("KeyUpdates", 0); }
+ get { return GetValue<int>("KeyUpdates", -1); }
set { SetValue("KeyUpdates", value); }
}
@@ -206,11 +206,29 @@ public string Namespace
}
/// <summary>
+ /// Gets or sets the number of documents moved.
+ /// </summary>
+ public int NumberMoved
+ {
+ get { return GetValue<int>("NumberMoved", -1); }
+ set { SetValue("NumberMoved", value); }
+ }
+
+ /// <summary>
+ /// Gets or sets the number of yields.
+ /// </summary>
+ public int NumberOfYields
+ {
+ get { return GetValue<int>("NumberOfYields", -1); }
+ set { SetValue("NumberOfYields", value); }
+ }
+
+ /// <summary>
/// Gets or sets the number of documents returned.
/// </summary>
public int NumberReturned
{
- get { return GetValue<int>("NumberReturned", 0); }
+ get { return GetValue<int>("NumberReturned", -1); }
set { SetValue("NumberReturned", value); }
}
@@ -219,7 +237,7 @@ public int NumberReturned
/// </summary>
public int NumberScanned
{
- get { return GetValue<int>("NumberScanned", 0); }
+ get { return GetValue<int>("NumberScanned", -1); }
set { SetValue("NumberScanned", value); }
}
@@ -228,7 +246,7 @@ public int NumberScanned
/// </summary>
public int NumberToReturn
{
- get { return GetValue<int>("NumberToReturn", 0); }
+ get { return GetValue<int>("NumberToReturn", -1); }
set { SetValue("NumberToReturn", value); }
}
@@ -237,7 +255,7 @@ public int NumberToReturn
/// </summary>
public int NumberToSkip
{
- get { return GetValue<int>("NumberToSkip", 0); }
+ get { return GetValue<int>("NumberToSkip", -1); }
set { SetValue("NumberToSkip", value); }
}
@@ -246,20 +264,11 @@ public int NumberToSkip
/// </summary>
public int NumberUpdated
{
- get { return GetValue<int>("NumberUpdated", 0); }
+ get { return GetValue<int>("NumberUpdated", -1); }
set { SetValue("NumberUpdated", value); }
}
/// <summary>
- /// Gets or sets the number of yields.
- /// </summary>
- public int NumberOfYields
- {
- get { return GetValue<int>("NumberOfYields", 0); }
- set { SetValue("NumberOfYields", value); }
- }
-
- /// <summary>
/// Gets or sets the operation.
/// </summary>
public string Op
@@ -290,7 +299,7 @@ public BsonDocument RawDocument
/// </summary>
public int ResponseLength
{
- get { return GetValue<int>("ResponseLength", 0); }
+ get { return GetValue<int>("ResponseLength", -1); }
set { SetValue("ResponseLength", value); }
}
@@ -416,6 +425,42 @@ internal SystemProfileReadWriteLockStatistics(BsonDocument backingDocument)
// public properties
/// <summary>
+ /// Gets or sets the time spent acquiring or holding the database read lock.
+ /// </summary>
+ public TimeSpan DatabaseReadLock
+ {
+ get { return GetValue("DatabaseReadLock", TimeSpan.Zero); }
+ set { SetValue("DatabaseReadLock", value); }
+ }
+
+ /// <summary>
+ /// Gets or sets the time spent acquiring or holding the database write lock.
+ /// </summary>
+ public TimeSpan DatabaseWriteLock
+ {
+ get { return GetValue("DatabaseWriteLock", TimeSpan.Zero); }
+ set { SetValue("DatabaseWriteLock", value); }
+ }
+
+ /// <summary>
+ /// Gets or sets the time spent acquiring or holding the gobal read lock.
+ /// </summary>
+ public TimeSpan GlobalReadLock
+ {
+ get { return GetValue("GlobalReadLock", TimeSpan.Zero); }
+ set { SetValue("GlobalReadLock", value); }
+ }
+
+ /// <summary>
+ /// Gets or sets the time spent acquiring or holding the global write lock.
+ /// </summary>
+ public TimeSpan GlobalWriteLock
+ {
+ get { return GetValue("GlobalWriteLock", TimeSpan.Zero); }
+ set { SetValue("GlobalWriteLock", value); }
+ }
+
+ /// <summary>
/// Gets the raw document.
/// </summary>
public BsonDocument RawDocument
@@ -424,21 +469,23 @@ public BsonDocument RawDocument
}
/// <summary>
- /// Gets or sets the time spent for a read.
+ /// Gets or sets the time spent acquiring or holding the read lock.
/// </summary>
+ [Obsolete("Use DatabaseReadLock or GlobalReadLock instead.")]
public TimeSpan Read
{
- get { return GetValue("Read", TimeSpan.Zero); }
- set { SetValue("Read", value); }
+ get { return DatabaseReadLock; }
+ set { DatabaseReadLock = value; }
}
/// <summary>
- /// Gets or sets the time spent for a write.
+ /// Gets or sets the time spent acquiring or holding the write lock.
/// </summary>
+ [Obsolete("Use DatabaseWriteLock or GlobalWriteLock instead.")]
public TimeSpan Write
{
- get { return GetValue("Write", TimeSpan.Zero); }
- set { SetValue("Write", value); }
+ get { return DatabaseWriteLock; }
+ set { DatabaseWriteLock = value; }
}
}
@@ -473,6 +520,7 @@ public SystemProfileInfoSerializer()
RegisterMember("LockStatistics", "lockStats", SystemProfileLockStatisticsSerializer.Instance, typeof(SystemProfileLockStatistics), null);
RegisterMember("Moved", "moved", BooleanSerializer.Instance, typeof(bool), null);
RegisterMember("Namespace", "ns", StringSerializer.Instance, typeof(string), null);
+ RegisterMember("NumberMoved", "nmoved", Int32Serializer.Instance, typeof(int), null);
RegisterMember("NumberReturned", "nreturned", Int32Serializer.Instance, typeof(int), null);
RegisterMember("NumberScanned", "nscanned", Int32Serializer.Instance, typeof(int), null);
RegisterMember("NumberToReturn", "ntoreturn", Int32Serializer.Instance, typeof(int), null);
@@ -564,8 +612,10 @@ public class SystemProfileReadWriteLockStatisticsSerializer : BsonDocumentBacked
public SystemProfileReadWriteLockStatisticsSerializer()
{
var timeSpanSerializationOptions = new TimeSpanSerializationOptions(BsonType.Double, TimeSpanUnits.Microseconds);
- RegisterMember("Read", "r", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
- RegisterMember("Write", "w", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
+ RegisterMember("DatabaseReadLock", "r", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
+ RegisterMember("GlobalReadLock", "R", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
+ RegisterMember("DatabaseWriteLock", "w", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
+ RegisterMember("GlobalWriteLock", "W", TimeSpanSerializer.Instance, typeof(TimeSpan), timeSpanSerializationOptions);
}
// public static properties
View
2 MongoDB.DriverUnitTests/MongoDB.DriverUnitTests.csproj
@@ -124,7 +124,7 @@
<Compile Include="MongoUrlTests.cs" />
<Compile Include="MongoUserTests.cs" />
<Compile Include="SafeModeTests.cs" />
- <Compile Include="SystemProfileIntoTests.cs" />
+ <Compile Include="SystemProfileInfoTests.cs" />
<Compile Include="ExpectedErrorMessage.cs" />
<Compile Include="GridFS\MongoGridFSFileInfoTests.cs" />
<Compile Include="GridFS\MongoGridFSSettingsTests.cs" />
View
262 MongoDB.DriverUnitTests/SystemProfileInfoTests.cs
@@ -0,0 +1,262 @@
+/* Copyright 2010-2012 10gen Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+using MongoDB.Bson;
+using MongoDB.Bson.IO;
+using MongoDB.Bson.Serialization;
+using MongoDB.Driver;
+
+namespace MongoDB.DriverUnitTests
+{
+ [TestFixture]
+ public class SystemProfileInfoTests
+ {
+ private MongoServer _server;
+ private MongoDatabase _database;
+ private MongoCollection<BsonDocument> _collection;
+
+ [TestFixtureSetUp]
+ public void Setup()
+ {
+ _server = Configuration.TestServer;
+ _database = Configuration.TestDatabase;
+ _collection = Configuration.TestCollection;
+ }
+
+ [Test]
+ public void TestMinimal()
+ {
+ var info = new SystemProfileInfo
+ {
+ Timestamp = new DateTime(2011, 10, 7, 0, 0, 0, DateTimeKind.Utc),
+ Duration = TimeSpan.FromMilliseconds(123)
+ };
+ var expected = "{ 'ts' : ISODate('2011-10-07T00:00:00Z'), 'millis' : 123.0 }".Replace("'", "\"");
+ Assert.AreEqual(expected, info.ToJson());
+ }
+
+ [Test]
+ public void TestDeserializeAll()
+ {
+ var info = new SystemProfileInfo
+ {
+ Abbreviated = "abbreviated",
+ Client = "client",
+ Command = new BsonDocument("command", 1),
+ CursorId = 1,
+ Duration = TimeSpan.FromMilliseconds(2),
+ Error = "err",
+ Exception = "exception",
+ ExceptionCode = 3,
+ Exhaust = true,
+ FastMod = true,
+ FastModInsert = true,
+ IdHack = true,
+ Info = "info",
+ KeyUpdates = 4,
+ LockStatistics = new SystemProfileLockStatistics
+ {
+ TimeAcquiring = new SystemProfileReadWriteLockStatistics
+ {
+ DatabaseReadLock = TimeSpan.FromMilliseconds(10),
+ DatabaseWriteLock = TimeSpan.FromMilliseconds(20),
+ GlobalReadLock = TimeSpan.FromMilliseconds(30),
+ GlobalWriteLock = TimeSpan.FromMilliseconds(40)
+ },
+ TimeLocked = new SystemProfileReadWriteLockStatistics
+ {
+ DatabaseReadLock = TimeSpan.FromMilliseconds(50),
+ DatabaseWriteLock = TimeSpan.FromMilliseconds(60),
+ GlobalReadLock = TimeSpan.FromMilliseconds(70),
+ GlobalWriteLock = TimeSpan.FromMilliseconds(80)
+ }
+ },
+ Moved = true,
+ Namespace = "ns",
+ NumberMoved = 11,
+ NumberReturned = 5,
+ NumberScanned = 6,
+ NumberToReturn = 7,
+ NumberToSkip = 8,
+ NumberUpdated = 9,
+ NumberOfYields = 10,
+ Op = "op",
+ Query = new BsonDocument("query", 1),
+ ResponseLength = 9,
+ ScanAndOrder = true,
+ Timestamp = new DateTime(2011, 10, 7, 1, 2, 3, DateTimeKind.Utc),
+ UpdateObject = new BsonDocument("updateObject", 1),
+ Upsert = true,
+ User = "user"
+ };
+ var json = info.ToJson(new JsonWriterSettings { Indent = true });
+ var rehydrated = BsonSerializer.Deserialize<SystemProfileInfo>(json);
+ Assert.AreEqual(info.Abbreviated, rehydrated.Abbreviated);
+ Assert.AreEqual(info.Client, rehydrated.Client);
+ Assert.AreEqual(info.Command, rehydrated.Command);
+ Assert.AreEqual(info.CursorId, rehydrated.CursorId);
+ Assert.AreEqual(info.Duration, rehydrated.Duration);
+ Assert.AreEqual(info.Error, rehydrated.Error);
+ Assert.AreEqual(info.Exception, rehydrated.Exception);
+ Assert.AreEqual(info.ExceptionCode, rehydrated.ExceptionCode);
+ Assert.AreEqual(info.Exhaust, rehydrated.Exhaust);
+ Assert.AreEqual(info.FastMod, rehydrated.FastMod);
+ Assert.AreEqual(info.FastModInsert, rehydrated.FastModInsert);
+ Assert.AreEqual(info.IdHack, rehydrated.IdHack);
+ Assert.AreEqual(info.Info, rehydrated.Info);
+ Assert.AreEqual(info.KeyUpdates, rehydrated.KeyUpdates);
+ Assert.AreEqual(info.LockStatistics.RawDocument, rehydrated.LockStatistics.RawDocument);
+ Assert.AreEqual(info.LockStatistics.TimeAcquiring.DatabaseReadLock, rehydrated.LockStatistics.TimeAcquiring.DatabaseReadLock);
+ Assert.AreEqual(info.LockStatistics.TimeAcquiring.DatabaseWriteLock, rehydrated.LockStatistics.TimeAcquiring.DatabaseWriteLock);
+ Assert.AreEqual(info.LockStatistics.TimeAcquiring.GlobalReadLock, rehydrated.LockStatistics.TimeAcquiring.GlobalReadLock);
+ Assert.AreEqual(info.LockStatistics.TimeAcquiring.GlobalWriteLock, rehydrated.LockStatistics.TimeAcquiring.GlobalWriteLock);
+ Assert.AreEqual(info.LockStatistics.TimeLocked.DatabaseReadLock, rehydrated.LockStatistics.TimeLocked.DatabaseReadLock);
+ Assert.AreEqual(info.LockStatistics.TimeLocked.DatabaseWriteLock, rehydrated.LockStatistics.TimeLocked.DatabaseWriteLock);
+ Assert.AreEqual(info.LockStatistics.TimeLocked.GlobalReadLock, rehydrated.LockStatistics.TimeLocked.GlobalReadLock);
+ Assert.AreEqual(info.LockStatistics.TimeLocked.GlobalWriteLock, rehydrated.LockStatistics.TimeLocked.GlobalWriteLock);
+ Assert.AreEqual(info.Moved, rehydrated.Moved);
+ Assert.AreEqual(info.Namespace, rehydrated.Namespace);
+ Assert.AreEqual(info.NumberMoved, rehydrated.NumberMoved);
+ Assert.AreEqual(info.NumberReturned, rehydrated.NumberReturned);
+ Assert.AreEqual(info.NumberScanned, rehydrated.NumberScanned);
+ Assert.AreEqual(info.NumberToReturn, rehydrated.NumberToReturn);
+ Assert.AreEqual(info.NumberToSkip, rehydrated.NumberToSkip);
+ Assert.AreEqual(info.NumberUpdated, rehydrated.NumberUpdated);
+ Assert.AreEqual(info.NumberOfYields, rehydrated.NumberOfYields);
+ Assert.AreEqual(info.Op, rehydrated.Op);
+ Assert.AreEqual(info.Query, rehydrated.Query);
+ Assert.AreEqual(info.ResponseLength, rehydrated.ResponseLength);
+ Assert.AreEqual(info.ScanAndOrder, rehydrated.ScanAndOrder);
+ Assert.AreEqual(info.Timestamp, rehydrated.Timestamp);
+ Assert.AreEqual(info.UpdateObject, rehydrated.UpdateObject);
+ Assert.AreEqual(info.Upsert, rehydrated.Upsert);
+ Assert.AreEqual(info.User, rehydrated.User);
+ }
+
+ [Test]
+ public void TestDeserializeSystemProfileInfoReturnedFromServer()
+ {
+ _database.SetProfilingLevel(ProfilingLevel.None);
+ var systemProfileCollection = _database.GetCollection<SystemProfileInfo>("system.profile");
+ if (systemProfileCollection.Exists())
+ {
+ systemProfileCollection.Drop();
+ }
+
+ _database.SetProfilingLevel(ProfilingLevel.All);
+ try
+ {
+ _collection.Insert(new BsonDocument("foo", 1));
+ }
+ finally
+ {
+ _database.SetProfilingLevel(ProfilingLevel.None);
+ }
+
+ var systemProfileInfo = systemProfileCollection.FindOne();
+
+ // since we don't know what most of the values should be simply call all the properties and make sure they don't throw
+ var abbreviated = systemProfileInfo.Abbreviated;
+ var client = systemProfileInfo.Client;
+ var command = systemProfileInfo.Command;
+ var cursorId = systemProfileInfo.CursorId;
+ var duration = systemProfileInfo.Duration;
+ var error = systemProfileInfo.Error;
+ var exception = systemProfileInfo.Exception;
+ var exceptionCode = systemProfileInfo.ExceptionCode;
+ var exhaust = systemProfileInfo.Exhaust;
+ var fastMod = systemProfileInfo.FastMod;
+ var fastModInsert = systemProfileInfo.FastModInsert;
+ var idHack = systemProfileInfo.IdHack;
+ var info = systemProfileInfo.Info;
+ var keyUpdates = systemProfileInfo.KeyUpdates;
+ var lockStatistics = systemProfileInfo.LockStatistics;
+ var moved = systemProfileInfo.Moved;
+ var ns = systemProfileInfo.Namespace;
+ var numberMoved = systemProfileInfo.NumberMoved;
+ var numberOfYields = systemProfileInfo.NumberOfYields;
+ var numberReturned = systemProfileInfo.NumberReturned;
+ var numberScanned = systemProfileInfo.NumberScanned;
+ var numberToReturn = systemProfileInfo.NumberToReturn;
+ var numberToSkip = systemProfileInfo.NumberToSkip;
+ var numberUpdated = systemProfileInfo.NumberUpdated;
+ var op = systemProfileInfo.Op;
+ var query = systemProfileInfo.Query;
+ var rawDocument = systemProfileInfo.RawDocument;
+ var responseLength = systemProfileInfo.ResponseLength;
+ var scanAndOrder = systemProfileInfo.ScanAndOrder;
+ var timestamp = systemProfileInfo.Timestamp;
+ var updateObject = systemProfileInfo.UpdateObject;
+ var upsert = systemProfileInfo.Upsert;
+ var user = systemProfileInfo.User;
+
+ if (lockStatistics != null)
+ {
+ var timeAcquiring = lockStatistics.TimeAcquiring;
+ var timeAcquiringDatabaseReadLock = timeAcquiring.DatabaseReadLock;
+ var timeAcquiringDatabaseWriteLock = timeAcquiring.DatabaseWriteLock;
+ var timeAcquiringGlobalReadLock = timeAcquiring.GlobalReadLock;
+ var timeAcquiringGlobalWriteLock = timeAcquiring.GlobalWriteLock;
+
+ var timeLocked = lockStatistics.TimeLocked;
+ var timeLockedDatabaseReadLock = timeLocked.DatabaseReadLock;
+ var timeLockedDatabaseWriteLock = timeLocked.DatabaseWriteLock;
+ var timeLockedGlobalReadLock = timeLocked.GlobalReadLock;
+ var timeLockedGlobalWriteLock = timeLocked.GlobalWriteLock;
+ }
+ }
+
+ [Test]
+ public void TestLockStatsAreStoredInMicroSeconds()
+ {
+ string json = @"
+ {
+ ""lockStats"" : {
+ ""timeLockedMicros"" : {
+ ""r"" : NumberLong(500),
+ ""R"" : NumberLong(600),
+ ""w"" : NumberLong(1000)
+ ""W"" : NumberLong(1100)
+ },
+ ""timeAcquiringMicros"" : {
+ ""r"" : NumberLong(2500),
+ ""R"" : NumberLong(2600),
+ ""w"" : NumberLong(10000)
+ ""W"" : NumberLong(11000)
+ }
+ }
+ }";
+ var rehydrated = BsonSerializer.Deserialize<SystemProfileInfo>(json);
+
+ // 1 tick = 10 microseconds. Can't use TimeSpan.FromMilliseconds(0.5) because
+ // TimeSpan.FromMilliseconds(0.5).TotalMilliseconds gives 1.0 (which makes no sense but that's the way it is)
+ // to get precision below 1 millisecond you must use ticks.
+ Assert.AreEqual(TimeSpan.FromTicks(5000), rehydrated.LockStatistics.TimeLocked.DatabaseReadLock);
+ Assert.AreEqual(TimeSpan.FromTicks(6000), rehydrated.LockStatistics.TimeLocked.GlobalReadLock);
+ Assert.AreEqual(TimeSpan.FromTicks(10000), rehydrated.LockStatistics.TimeLocked.DatabaseWriteLock);
+ Assert.AreEqual(TimeSpan.FromTicks(11000), rehydrated.LockStatistics.TimeLocked.GlobalWriteLock);
+ Assert.AreEqual(TimeSpan.FromTicks(25000), rehydrated.LockStatistics.TimeAcquiring.DatabaseReadLock);
+ Assert.AreEqual(TimeSpan.FromTicks(26000), rehydrated.LockStatistics.TimeAcquiring.GlobalReadLock);
+ Assert.AreEqual(TimeSpan.FromTicks(100000), rehydrated.LockStatistics.TimeAcquiring.DatabaseWriteLock);
+ Assert.AreEqual(TimeSpan.FromTicks(110000), rehydrated.LockStatistics.TimeAcquiring.GlobalWriteLock);
+ }
+ }
+}
View
179 MongoDB.DriverUnitTests/SystemProfileIntoTests.cs
@@ -1,179 +0,0 @@
-/* Copyright 2010-2012 10gen Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-
-using MongoDB.Bson;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-using MongoDB.Driver;
-
-namespace MongoDB.DriverUnitTests
-{
- [TestFixture]
- public class SystemProfileInfoTests
- {
- private MongoServer _server;
- private MongoDatabase _database;
- private MongoCollection<BsonDocument> _collection;
-
- [TestFixtureSetUp]
- public void Setup()
- {
- _server = Configuration.TestServer;
- _server.Connect();
- _database = Configuration.TestDatabase;
- _collection = Configuration.TestCollection;
- }
-
- [Test]
- public void TestMinimal()
- {
- var info = new SystemProfileInfo
- {
- Timestamp = new DateTime(2011, 10, 7, 0, 0, 0, DateTimeKind.Utc),
- Duration = TimeSpan.FromMilliseconds(123)
- };
- var expected = "{ 'ts' : ISODate('2011-10-07T00:00:00Z'), 'millis' : 123.0 }".Replace("'", "\"");
- Assert.AreEqual(expected, info.ToJson());
- }
-
- [Test]
- public void TestAll()
- {
- var info = new SystemProfileInfo
- {
- Abbreviated = "abbreviated",
- Client = "client",
- Command = new BsonDocument("command", 1),
- CursorId = 1,
- Duration = TimeSpan.FromMilliseconds(2),
- Error = "err",
- Exception = "exception",
- ExceptionCode = 3,
- Exhaust = true,
- FastMod = true,
- FastModInsert = true,
- IdHack = true,
- Info = "info",
- KeyUpdates = 4,
- LockStatistics = new SystemProfileLockStatistics
- {
- TimeAcquiring = new SystemProfileReadWriteLockStatistics
- {
- Read = TimeSpan.FromMilliseconds(10),
- Write = TimeSpan.FromMilliseconds(20)
- },
- TimeLocked = new SystemProfileReadWriteLockStatistics
- {
- Read = TimeSpan.FromMilliseconds(5),
- Write = TimeSpan.FromMilliseconds(30)
- }
- },
- Moved = true,
- Namespace = "ns",
- NumberReturned = 5,
- NumberScanned = 6,
- NumberToReturn = 7,
- NumberToSkip = 8,
- NumberUpdated = 9,
- NumberOfYields = 10,
- Op = "op",
- Query = new BsonDocument("query", 1),
- ResponseLength = 9,
- ScanAndOrder = true,
- Timestamp = new DateTime(2011, 10, 7, 1, 2, 3, DateTimeKind.Utc),
- UpdateObject = new BsonDocument("updateObject", 1),
- Upsert = true,
- User = "user"
- };
- var json = info.ToJson(new JsonWriterSettings { Indent = true });
- var rehydrated = BsonSerializer.Deserialize<SystemProfileInfo>(json);
- Assert.AreEqual(info.Abbreviated, rehydrated.Abbreviated);
- Assert.AreEqual(info.Client, rehydrated.Client);
- Assert.AreEqual(info.Command, rehydrated.Command);
- Assert.AreEqual(info.CursorId, rehydrated.CursorId);
- Assert.AreEqual(info.Duration, rehydrated.Duration);
- Assert.AreEqual(info.Error, rehydrated.Error);
- Assert.AreEqual(info.Exception, rehydrated.Exception);
- Assert.AreEqual(info.ExceptionCode, rehydrated.ExceptionCode);
- Assert.AreEqual(info.Exhaust, rehydrated.Exhaust);
- Assert.AreEqual(info.FastMod, rehydrated.FastMod);
- Assert.AreEqual(info.FastModInsert, rehydrated.FastModInsert);
- Assert.AreEqual(info.IdHack, rehydrated.IdHack);
- Assert.AreEqual(info.Info, rehydrated.Info);
- Assert.AreEqual(info.KeyUpdates, rehydrated.KeyUpdates);
- Assert.AreEqual(info.LockStatistics.RawDocument, rehydrated.LockStatistics.RawDocument);
- Assert.AreEqual(info.Moved, rehydrated.Moved);
- Assert.AreEqual(info.Namespace, rehydrated.Namespace);
- Assert.AreEqual(info.NumberReturned, rehydrated.NumberReturned);
- Assert.AreEqual(info.NumberScanned, rehydrated.NumberScanned);
- Assert.AreEqual(info.NumberToReturn, rehydrated.NumberToReturn);
- Assert.AreEqual(info.NumberToSkip, rehydrated.NumberToSkip);
- Assert.AreEqual(info.NumberUpdated, rehydrated.NumberUpdated);
- Assert.AreEqual(info.NumberOfYields, rehydrated.NumberOfYields);
- Assert.AreEqual(info.Op, rehydrated.Op);
- Assert.AreEqual(info.Query, rehydrated.Query);
- Assert.AreEqual(info.ResponseLength, rehydrated.ResponseLength);
- Assert.AreEqual(info.ScanAndOrder, rehydrated.ScanAndOrder);
- Assert.AreEqual(info.Timestamp, rehydrated.Timestamp);
- Assert.AreEqual(info.UpdateObject, rehydrated.UpdateObject);
- Assert.AreEqual(info.Upsert, rehydrated.Upsert);
- Assert.AreEqual(info.User, rehydrated.User);
- }
-
- [Test]
- public void LockStatsPropertyIsNotInMilliseconds()
- {
- _database.SetProfilingLevel(ProfilingLevel.All);
- _collection.Insert(new BsonDocument("foo", 1));
- var info = _database.GetCollection("system.profile").FindOneAs<SystemProfileInfo>();
-
- Assert.IsTrue(info.RawDocument.Contains("lockStats"));
- Assert.IsFalse(info.RawDocument.Contains("lockStatMillis"));
- }
-
- [Test]
- public void LockStatsAreStoredInMicroSeconds()
- {
- string json = @"
- {
- ""lockStats"" : {
- ""timeLockedMicros"" : {
- ""r"" : NumberLong(500),
- ""w"" : NumberLong(1000)
- },
- ""timeAcquiringMicros"" : {
- ""r"" : NumberLong(2500),
- ""w"" : NumberLong(10000)
- }
- }
- }";
- var rehydrated = BsonSerializer.Deserialize<SystemProfileInfo>(json);
-
- //1 tick = 10 microseconds. Can't use TimeSpan.FromMilliseconds(0.5) because
- //TimeSpan.FromMilliseconds(0.5).TotalMilliseconds gives 1.0 (which makes no sense but that's the way it is)
- //To get precision below 1 millisecond you must use ticks.
- Assert.AreEqual(TimeSpan.FromTicks(5000), rehydrated.LockStatistics.TimeLocked.Read);
- Assert.AreEqual(TimeSpan.FromMilliseconds(1d), rehydrated.LockStatistics.TimeLocked.Write);
- Assert.AreEqual(TimeSpan.FromTicks(25000), rehydrated.LockStatistics.TimeAcquiring.Read);
- Assert.AreEqual(TimeSpan.FromMilliseconds(10d), rehydrated.LockStatistics.TimeAcquiring.Write);
- }
- }
-}

0 comments on commit 351e4ba

Please sign in to comment.