Ejemplo n.º 1
0
        public void Execute_should_throw_when_maxTime_is_exceeded(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet).VersionLessThan("4.8.0");
            var subject = new GeoSearchOperation <BsonDocument>(
                _collectionNamespace,
                new BsonArray {
                1, 2
            },
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings)
            {
                MaxDistance = 20,
                Search      = new BsonDocument("Type", "restaraunt")
            };

            subject.MaxTime = TimeSpan.FromSeconds(9001);

            using (var failPoint = FailPoint.ConfigureAlwaysOn(_cluster, _session, FailPointName.MaxTimeAlwaysTimeout))
            {
                var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async));

                exception.Should().BeOfType <MongoExecutionTimeoutException>();
            }
        }
Ejemplo n.º 2
0
        public void MaxTime_get_and_set_should_work(
            [Values(-10000, 0, 1, 10000, 99999)] long maxTimeTicks)
        {
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, 5, BsonDocumentSerializer.Instance, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

            subject.MaxTime = value;
            var result = subject.MaxTime;

            result.Should().Be(value);
        }
Ejemplo n.º 3
0
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-10001, -9999, -1)] long maxTimeTicks)
        {
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, 5, BsonDocumentSerializer.Instance, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

            var exception = Record.Exception(() => subject.MaxTime = value);

            var e = exception.Should().BeOfType <ArgumentOutOfRangeException>().Subject;

            e.ParamName.Should().Be("value");
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values("3.0.0", "3.2.0")] string serverVersionString,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var serverVersion = SemanticVersion.Parse(serverVersionString);
            var filter        = new BsonDocument("x", 1);
            var limit         = 10;
            var maxDistance   = 30;
            var maxTime       = TimeSpan.FromMilliseconds(50);
            var near          = new BsonArray {
                10, 20
            };
            var readConcern = new ReadConcern(readConcernLevel);
            var subject     = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = readConcern
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion);
            var session = OperationTestHelper.CreateSession();

            if (!readConcern.IsServerDefault && !Feature.ReadConcern.IsSupported(serverVersion))
            {
                var exception = Record.Exception(() => subject.CreateCommand(connectionDescription, session));

                exception.Should().BeOfType <MongoClientException>();
            }
            else
            {
                var result = subject.CreateCommand(connectionDescription, session);

                var expectedResult = new BsonDocument
                {
                    { "geoSearch", _collectionNamespace.CollectionName },
                    { "near", near },
                    { "limit", limit },
                    { "maxDistance", maxDistance },
                    { "search", filter },
                    { "maxTimeMS", (int)maxTime.TotalMilliseconds },
                    { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault }
                };
                result.Should().Be(expectedResult);
                result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
            }
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values("3.0.0", "3.2.0")] string serverVersion,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var semanticServerVersion = SemanticVersion.Parse(serverVersion);
            var filter      = new BsonDocument("x", 1);
            var limit       = 10;
            var maxDistance = 30;
            var maxTime     = TimeSpan.FromMilliseconds(50);
            var near        = new BsonArray {
                10, 20
            };
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = new ReadConcern(readConcernLevel)
            };
            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "limit", limit },
                { "maxDistance", maxDistance },
                { "search", filter },
                { "maxTimeMS", maxTime.TotalMilliseconds }
            };

            if (!subject.ReadConcern.IsServerDefault)
            {
                expectedResult["readConcern"] = subject.ReadConcern.ToBsonDocument();
            }

            if (!subject.ReadConcern.IsSupported(semanticServerVersion))
            {
                Action act = () => subject.CreateCommand(semanticServerVersion);
                act.ShouldThrow <MongoClientException>();
            }
            else
            {
                var result = subject.CreateCommand(semanticServerVersion);
                result.Should().Be(expectedResult);
            }
        }
Ejemplo n.º 6
0
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet).VersionLessThan("4.8.0");
            EnsureTestData();
            var subject = new GeoSearchOperation <BsonDocument>(
                _collectionNamespace,
                new BsonArray {
                1, 2
            },
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings)
            {
                MaxDistance = 20,
                Search      = new BsonDocument("Type", "restaraunt")
            };

            VerifySessionIdWasSentWhenSupported(subject, "geoSearch", async);
        }
Ejemplo n.º 7
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            var subject = new GeoSearchOperation <BsonDocument>(
                _collectionNamespace,
                new BsonArray {
                1, 2
            },
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings)
            {
                MaxDistance = 20,
                Search      = new BsonDocument("Type", "restaraunt")
            };

            var result = ExecuteOperation(subject, async);

            result["results"].Should().NotBeNull();
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values(WireVersion.Server30, WireVersion.Server32)] int maxWireVersion,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var filter      = new BsonDocument("x", 1);
            var limit       = 10;
            var maxDistance = 30;
            var maxTime     = TimeSpan.FromMilliseconds(50);
            var near        = new BsonArray {
                10, 20
            };
            var readConcern = new ReadConcern(readConcernLevel);
            var subject     = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = readConcern
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(maxWireVersion);
            var session = OperationTestHelper.CreateSession();

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

            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "limit", limit },
                { "maxDistance", maxDistance },
                { "search", filter },
                { "maxTimeMS", (int)maxTime.TotalMilliseconds },
                { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
Ejemplo n.º 9
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet).VersionLessThan("4.8.0");
            EnsureTestData();
            var subject = new GeoSearchOperation <BsonDocument>(
                _collectionNamespace,
                new BsonArray {
                1, 2
            },
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings)
            {
                MaxDistance = 20,
                Search      = new BsonDocument("Type", "restaraunt")
            };

            var result = ExecuteOperation(subject, async);

            result["results"].Should().NotBeNull();
        }
Ejemplo n.º 10
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var near    = 5;
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();
            var session = OperationTestHelper.CreateSession();

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

            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }