Exemple #1
0
        public void Execute_should_throw_when_binding_is_null(
            [Values(false, true)]
            bool async)
        {
            var          subject = new MapReduceLegacyOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
            IReadBinding binding = null;

            Action act = () => ExecuteOperation(subject, binding, async);

            act.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("binding");
        }
        public void CreateOutputOptions_should_return_expected_result()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var subject = new MapReduceLegacyOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
#pragma warning restore CS0618 // Type or member is obsolete
            var subjectReflector = new Reflector(subject);
            var expectedResult   = new BsonDocument("inline", 1);

            var result = subjectReflector.CreateOutputOptions();

            result.Should().Be(expectedResult);
        }
        public void constructor_should_initialize_instance()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var subject = new MapReduceLegacyOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
#pragma warning restore CS0618 // Type or member is obsolete

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.MapFunction.Should().BeSameAs(_mapFunction);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            subject.Filter.Should().BeNull();
            subject.ReduceFunction.Should().BeSameAs(_reduceFunction);
        }
Exemple #4
0
        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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings)
            {
                ReadConcern = ReadConcern.Majority
            };

            Action act = () => subject.CreateCommand(new SemanticVersion(3, 0, 0));

            act.ShouldThrow <MongoClientException>();
        }
        public void Execute_should_throw_when_binding_is_null(
            [Values(false, true)]
            bool async)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var subject = new MapReduceLegacyOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
#pragma warning restore CS0618 // Type or member is obsolete
            IReadBinding binding = null;

            Action act = () => ExecuteOperation(subject, binding, async);

            act.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("binding");
        }
Exemple #6
0
        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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings)
            {
                ReadConcern = ReadConcern.Majority
            };

            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.ReadConcern.LastNotSupportedVersion);

            Action act = () => subject.CreateCommand(session, connectionDescription);

            act.ShouldThrow <MongoClientException>();
        }
Exemple #7
0
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check();
            EnsureTestData();
            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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings);
            var expectedResults = new List <BsonDocument>
            {
                new BsonDocument {
                    { "_id", 1 }, { "value", 3 }
                },
                new BsonDocument {
                    { "_id", 2 }, { "value", 4 }
                },
            };

            VerifySessionIdWasSentWhenSupported(subject, "mapreduce", async);
        }
Exemple #8
0
        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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _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());
            }
        }
Exemple #9
0
        public void CreateCommand_should_include_readConcern_when_using_causal_consistency(
            [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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings)
            {
                ReadConcern = readConcern
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.ReadConcern.FirstSupportedVersion, supportsSessions: true);
            var session = OperationTestHelper.CreateSession(true, new BsonTimestamp(100));

            var result = subject.CreateCommand(connectionDescription, session);

            var expectedReadConcernDocument = readConcern.ToBsonDocument();

            expectedReadConcernDocument["afterClusterTime"] = new BsonTimestamp(100);

            result["readConcern"].Should().Be(expectedReadConcernDocument);
        }
        public void Execute_should_return_expected_results(
            [Values(false, true)]
            bool async)
        {
            EnsureTestData();

            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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings);
            var expectedResults = new List <BsonDocument>
            {
                new BsonDocument {
                    { "_id", 1 }, { "value", 3 }
                },
                new BsonDocument {
                    { "_id", 2 }, { "value", 4 }
                },
            };

            var result = ExecuteOperation(subject, async);

            result["results"].Should().Be(new BsonArray(expectedResults));
        }
Exemple #11
0
        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 MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings)
            {
                ReadConcern = readConcern
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.ReadConcern.FirstSupportedVersion);

            var result = subject.CreateCommand(session, connectionDescription);

            if (readConcern.IsServerDefault)
            {
                result.Contains("readConcern").Should().BeFalse();
            }
            else
            {
                result["readConcern"].Should().Be(readConcern.ToBsonDocument());
            }
        }
        public void CreateCommand_should_include_readConcern_when_using_causal_consistency(
            [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; }";

#pragma warning disable CS0618 // Type or member is obsolete
            var subject = new MapReduceLegacyOperation(_collectionNamespace, mapFunction, reduceFunction, _messageEncoderSettings)
#pragma warning restore CS0618 // Type or member is obsolete
            {
                ReadConcern = readConcern
            };

            var session = OperationTestHelper.CreateSession(isCausallyConsistent: true, operationTime: new BsonTimestamp(100));
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

            var result = subject.CreateCommand(session, connectionDescription);

            var expectedReadConcernDocument = readConcern.ToBsonDocument();
            expectedReadConcernDocument["afterClusterTime"] = new BsonTimestamp(100);

            result["readConcern"].Should().Be(expectedReadConcernDocument);
        }
Exemple #13
0
 // constructor
 public Reflector(MapReduceLegacyOperation instance)
 {
     _instance = instance;
 }
#pragma warning restore CS0618 // Type or member is obsolete

            // constructor
#pragma warning disable CS0618 // Type or member is obsolete
            public Reflector(MapReduceLegacyOperation instance)
#pragma warning restore CS0618 // Type or member is obsolete
            {
                _instance = instance;
            }