Skip to content

Commit

Permalink
CSHARP-695: respect maxMessageSizeBytes when provided by the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Mar 1, 2013
1 parent 33f6cb3 commit 6020ee9
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MongoDB.Driver/CommandResults/IsMasterResult.cs
Expand Up @@ -117,7 +117,13 @@ public int MaxBsonObjectSize
/// </value>
public int MaxMessageLength
{
get { return Math.Max(MongoDefaults.MaxMessageLength, MaxBsonObjectSize + 1024); }
get
{
return Response.GetValue(
"maxMessageSizeBytes",
Math.Max(MongoDefaults.MaxMessageLength, MaxBsonObjectSize + 1024))
.ToInt32();
}
}

/// <summary>
Expand Down
72 changes: 72 additions & 0 deletions MongoDB.DriverUnitTests/CommandResults/IsMasterResultTests.cs
@@ -0,0 +1,72 @@
/* Copyright 2010-2013 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 MongoDB.Bson;
using MongoDB.Driver;
using NUnit.Framework;

namespace MongoDB.DriverUnitTests.CommandResults
{
[TestFixture]
public class IsMasterResultTests
{
[Test]
public void TestMaxMessageLengthWhenServerSupplied()
{
var command = new CommandDocument("ismaster", 1);
var document = new BsonDocument
{
{ "ok", 1 },
{ "maxMessageSizeBytes", 1000 },
{ "maxBsonObjectSize", 1000 }
};
var result = new IsMasterResult();
result.Initialize(command, document);

Assert.AreEqual(1000, result.MaxMessageLength);
}

[Test]
public void TestMaxMessageLengthWhenNotServerSuppliedUsesMongoDefaultsWhenLargerThanMaxBsonObjectSize()
{
var command = new CommandDocument("ismaster", 1);
var document = new BsonDocument
{
{ "ok", 1 },
{ "maxBsonObjectSize", MongoDefaults.MaxMessageLength - 2048 }
};
var result = new IsMasterResult();
result.Initialize(command, document);

Assert.AreEqual(MongoDefaults.MaxMessageLength, result.MaxMessageLength);
}

[Test]
public void TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults()
{
var command = new CommandDocument("ismaster", 1);
var document = new BsonDocument
{
{ "ok", 1 },
{ "maxBsonObjectSize", MongoDefaults.MaxMessageLength }
};
var result = new IsMasterResult();
result.Initialize(command, document);

Assert.AreEqual(MongoDefaults.MaxMessageLength + 1024, result.MaxMessageLength);
}
}
}
1 change: 1 addition & 0 deletions MongoDB.DriverUnitTests/MongoDB.DriverUnitTests.csproj
Expand Up @@ -103,6 +103,7 @@
<Compile Include="Builders\UpdateBuilderTests.cs" />
<Compile Include="CommandResults\CollectionStatsResultTests.cs" />
<Compile Include="CommandResults\CommandResultTests.cs" />
<Compile Include="CommandResults\IsMasterResultTests.cs" />
<Compile Include="CommandResults\DatabaseStatsResultTests.cs" />
<Compile Include="CommandResults\GetLastErrorResultTests.cs" />
<Compile Include="CommandResults\ValidateCollectionResultTests.cs" />
Expand Down

0 comments on commit 6020ee9

Please sign in to comment.