public void CreateCommand_should_return_the_expected_result_when_using_causal_consistency( [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel?level) { var readConcern = level.HasValue ? new ReadConcern(level.Value) : ReadConcern.Default; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var session = OperationTestHelper.CreateSession(isCausallyConsistent: true, operationTime: new BsonTimestamp(100)); var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.ReadConcern.FirstSupportedVersion, supportsSessions: true); var result = subject.CreateCommand(session, connectionDescription); var expectedReadConcernDocument = readConcern.ToBsonDocument(); expectedReadConcernDocument["afterClusterTime"] = new BsonTimestamp(100); var expectedResult = new BsonDocument { { "mapReduce", _collectionNamespace.CollectionName }, { "map", _mapFunction }, { "reduce", _reduceFunction }, { "out", new BsonDocument("inline", 1) }, { "readConcern", expectedReadConcernDocument } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set( [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel?level) { var readConcern = level.HasValue ? new ReadConcern(level.Value) : ReadConcern.Default; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var session = OperationTestHelper.CreateSession(); var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.ReadConcern.FirstSupportedVersion); var result = subject.CreateCommand(session, connectionDescription); var expectedResult = new BsonDocument { { "mapReduce", _collectionNamespace.CollectionName }, { "map", _mapFunction }, { "reduce", _reduceFunction }, { "out", new BsonDocument("inline", 1) }, { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_throw_when_ReadConcern_is_set_but_not_supported() { var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, _mapFunction, _reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = ReadConcern.Majority }; var exception = Record.Exception(() => subject.CreateCommand(Feature.ReadConcern.LastNotSupportedVersion)); exception.Should().BeOfType <MongoClientException>(); }
public void CreateCommand_should_throw_when_read_concern_is_not_supported() { var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = ReadConcern.Majority }; Action act = () => subject.CreateCommand(new SemanticVersion(3, 0, 0)); act.ShouldThrow <MongoClientException>(); }
public void CreateCommand_should_include_read_concern_when_appropriate( [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel) { var readConcern = new ReadConcern(readConcernLevel); var mapFunction = "function() { emit(this.x, this.v); }"; var reduceFunction = "function(key, values) { var sum = 0; for (var i = 0; i < values.length; i++) { sum += values[i]; }; return sum; }"; var subject = new MapReduceOperation <BsonDocument>(_collectionNamespace, mapFunction, reduceFunction, _resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var command = subject.CreateCommand(new SemanticVersion(3, 2, 0)); if (readConcern.IsServerDefault) { command.Contains("readConcern").Should().BeFalse(); } else { command["readConcern"].Should().Be(readConcern.ToBsonDocument()); } }