Skip to content

Commit a200c61

Browse files
author
rstam
committed
CSHARP-551: Rename HaveIdIndex to HasIdIndex. Changed Flags to call SystemFlags to share code. Added test for non-zero UserFlags.
1 parent 3ea5362 commit a200c61

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Driver/Core/CommandResults/CollectionStatsResult.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public enum CollectionSystemFlags
3636
/// <summary>
3737
/// The collection has an _id index.
3838
/// </summary>
39-
HaveIdIndex = 1
39+
HasIdIndex = 1 // called HaveIdIndex in the server but renamed here to follow .NET naming conventions
4040
}
4141

4242
/// <summary>
@@ -52,7 +52,7 @@ public enum CollectionUserFlags
5252
/// <summary>
5353
/// User power of 2 size.
5454
/// </summary>
55-
UsePowerOf2Size = 1
55+
UsePowerOf2Sizes = 1
5656
}
5757

5858
/// <summary>
@@ -106,15 +106,7 @@ public int Flags
106106
get
107107
{
108108
// flags was renamed to systemFlags in server version 2.2
109-
BsonValue flags;
110-
if (Response.TryGetValue("flags", out flags) || Response.TryGetValue("systemFlags", out flags))
111-
{
112-
return flags.AsInt32;
113-
}
114-
else
115-
{
116-
return 0;
117-
}
109+
return (int)SystemFlags;
118110
}
119111
}
120112

@@ -205,7 +197,7 @@ public CollectionSystemFlags SystemFlags
205197
{
206198
get
207199
{
208-
// systemFlags was called flags prior to server version 2.2
200+
// systemFlags was first introduced in server version 2.2 (check "flags" also for compatibility with older servers)
209201
BsonValue systemFlags;
210202
if (Response.TryGetValue("systemFlags", out systemFlags) || Response.TryGetValue("flags", out systemFlags))
211203
{

DriverUnitTests/Core/CommandResults/CollectionStatsResultTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void Test()
7171
Assert.AreEqual(1, result.ObjectCount);
7272
Assert.IsTrue(result.PaddingFactor > 0.0);
7373
Assert.IsTrue(result.StorageSize > 0);
74-
Assert.AreEqual(CollectionSystemFlags.HaveIdIndex, result.SystemFlags);
74+
Assert.AreEqual(CollectionSystemFlags.HasIdIndex, result.SystemFlags);
7575
Assert.IsTrue(result.TotalIndexSize > 0);
7676
Assert.AreEqual(CollectionUserFlags.None, result.UserFlags);
7777
}

DriverUnitTests/Core/MongoCollectionTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,27 @@ public void TestSortAndLimit()
13411341
[Test]
13421342
public void TestGetStats()
13431343
{
1344-
var dataSize = _collection.GetStats();
1344+
var stats = _collection.GetStats();
1345+
}
1346+
1347+
[Test]
1348+
public void TestGetStatsUsePowerOf2Sizes()
1349+
{
1350+
if (_server.BuildInfo.Version >= new Version(2, 2))
1351+
{
1352+
_collection.Drop();
1353+
_database.CreateCollection(_collection.Name); // collMod command only works if collection exists
1354+
1355+
var command = new CommandDocument
1356+
{
1357+
{ "collMod", _collection.Name },
1358+
{ "usePowerOf2Sizes", true }
1359+
};
1360+
_database.RunCommand(command);
1361+
1362+
var stats = _collection.GetStats();
1363+
Assert.IsTrue((stats.UserFlags & CollectionUserFlags.UsePowerOf2Sizes) != 0);
1364+
}
13451365
}
13461366

13471367
[Test]

0 commit comments

Comments
 (0)