Skip to content

Commit 6020ee9

Browse files
committed
CSHARP-695: respect maxMessageSizeBytes when provided by the server.
1 parent 33f6cb3 commit 6020ee9

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

MongoDB.Driver/CommandResults/IsMasterResult.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ public int MaxBsonObjectSize
117117
/// </value>
118118
public int MaxMessageLength
119119
{
120-
get { return Math.Max(MongoDefaults.MaxMessageLength, MaxBsonObjectSize + 1024); }
120+
get
121+
{
122+
return Response.GetValue(
123+
"maxMessageSizeBytes",
124+
Math.Max(MongoDefaults.MaxMessageLength, MaxBsonObjectSize + 1024))
125+
.ToInt32();
126+
}
121127
}
122128

123129
/// <summary>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Copyright 2010-2013 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using MongoDB.Bson;
18+
using MongoDB.Driver;
19+
using NUnit.Framework;
20+
21+
namespace MongoDB.DriverUnitTests.CommandResults
22+
{
23+
[TestFixture]
24+
public class IsMasterResultTests
25+
{
26+
[Test]
27+
public void TestMaxMessageLengthWhenServerSupplied()
28+
{
29+
var command = new CommandDocument("ismaster", 1);
30+
var document = new BsonDocument
31+
{
32+
{ "ok", 1 },
33+
{ "maxMessageSizeBytes", 1000 },
34+
{ "maxBsonObjectSize", 1000 }
35+
};
36+
var result = new IsMasterResult();
37+
result.Initialize(command, document);
38+
39+
Assert.AreEqual(1000, result.MaxMessageLength);
40+
}
41+
42+
[Test]
43+
public void TestMaxMessageLengthWhenNotServerSuppliedUsesMongoDefaultsWhenLargerThanMaxBsonObjectSize()
44+
{
45+
var command = new CommandDocument("ismaster", 1);
46+
var document = new BsonDocument
47+
{
48+
{ "ok", 1 },
49+
{ "maxBsonObjectSize", MongoDefaults.MaxMessageLength - 2048 }
50+
};
51+
var result = new IsMasterResult();
52+
result.Initialize(command, document);
53+
54+
Assert.AreEqual(MongoDefaults.MaxMessageLength, result.MaxMessageLength);
55+
}
56+
57+
[Test]
58+
public void TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults()
59+
{
60+
var command = new CommandDocument("ismaster", 1);
61+
var document = new BsonDocument
62+
{
63+
{ "ok", 1 },
64+
{ "maxBsonObjectSize", MongoDefaults.MaxMessageLength }
65+
};
66+
var result = new IsMasterResult();
67+
result.Initialize(command, document);
68+
69+
Assert.AreEqual(MongoDefaults.MaxMessageLength + 1024, result.MaxMessageLength);
70+
}
71+
}
72+
}

MongoDB.DriverUnitTests/MongoDB.DriverUnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="Builders\UpdateBuilderTests.cs" />
104104
<Compile Include="CommandResults\CollectionStatsResultTests.cs" />
105105
<Compile Include="CommandResults\CommandResultTests.cs" />
106+
<Compile Include="CommandResults\IsMasterResultTests.cs" />
106107
<Compile Include="CommandResults\DatabaseStatsResultTests.cs" />
107108
<Compile Include="CommandResults\GetLastErrorResultTests.cs" />
108109
<Compile Include="CommandResults\ValidateCollectionResultTests.cs" />

0 commit comments

Comments
 (0)