コード例 #1
0
        public void TestEvalWithMaxTime()
        {
            RequireServer.Check().Supports(Feature.Eval);
#pragma warning disable 618
            if (!DriverTestConfiguration.Client.Settings.Credentials.Any())
            {
                if (_primary.Supports(FeatureId.MaxTime))
                {
                    using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                    {
                        if (failpoint.IsSupported())
                        {
                            failpoint.SetAlwaysOn();
                            var args = new EvalArgs
                            {
                                Code    = "return 0;",
                                MaxTime = TimeSpan.FromMilliseconds(1)
                            };
                            Assert.Throws <MongoExecutionTimeoutException>(() => _adminDatabase.Eval(args));
                        }
                    }
                }
            }
#pragma warning restore
        }
コード例 #2
0
        // private methods
        private FailPoint ConfigureFailPoint(string failpointCommand)
        {
            var cluster = DriverTestConfiguration.Client.Cluster;
            var session = NoCoreSession.NewHandle();

            return(FailPoint.Configure(cluster, session, BsonDocument.Parse(failpointCommand)));
        }
        // private methods
        private FailPoint ConfigureFailPoint(IMongoClient client, int errorCode)
        {
            var session = NoCoreSession.NewHandle();

            var args = BsonDocument.Parse($"{{ mode : {{ times : 1 }}, data : {{ failCommands : [\"insert\"], errorCode : {errorCode} }} }}");

            return(FailPoint.Configure(client.Cluster, session, "failCommand", args));
        }
コード例 #4
0
 public void TestEvalWithMaxTime()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 var args = new EvalArgs
                 {
                     Code    = "return 0;",
                     MaxTime = TimeSpan.FromMilliseconds(1)
                 };
                 Assert.Throws <ExecutionTimeoutException>(() => _database.Eval(args));
             }
         }
     }
 }
コード例 #5
0
        public void SelectServer_loadbalancing_prose_test([Values(false, true)] bool async)
        {
            RequireServer.Check()
            .Supports(Feature.ShardedTransactions, Feature.FailPointsBlockConnection)
            .ClusterType(ClusterType.Sharded);
            RequireMultipleShardRouters();

            // temporary disable the test on Win Auth topologies, due to operations timings irregularities
            if (CoreTestConfiguration.ConnectionString.Tls == true &&
                RequirePlatform.GetCurrentOperatingSystem() == SupportedOperatingSystem.Windows)
            {
                throw new SkipException("Win Auth topologies temporary not supported due to timings irregularities.");
            }

            const string applicationName              = "loadBalancingTest";
            const int    threadsCount                 = 10;
            const int    commandsPerThreadCount       = 10;
            const double maxCommandsOnSlowServerRatio = 0.3; // temporary set slow server load to 30% from 25% until find timings are investigated
            const double operationsCountTolerance     = 0.10;

            var failCommand = BsonDocument.Parse($"{{ configureFailPoint: 'failCommand', mode : {{ times : 10000 }}, data : {{ failCommands : [\"find\"], blockConnection: true, blockTimeMS: 500, appName: '{applicationName}' }} }}");

            DropCollection();
            var eventCapturer = CreateEventCapturer();

            using (var client = CreateDisposableClient(eventCapturer, applicationName))
            {
                var slowServer = client.Cluster.SelectServer(WritableServerSelector.Instance, default);
                var fastServer = client.Cluster.SelectServer(new DelegateServerSelector((_, servers) => servers.Where(s => s.ServerId != slowServer.ServerId)), default);

                using var failPoint = FailPoint.Configure(slowServer, NoCoreSession.NewHandle(), failCommand);

                var database = client.GetDatabase(_databaseName);
                CreateCollection();
                var collection = database.GetCollection <BsonDocument>(_collectionName);

                // warm up connections
                var channels = new ConcurrentBag <IChannelHandle>();
                ThreadingUtilities.ExecuteOnNewThreads(threadsCount, i =>
                {
                    channels.Add(slowServer.GetChannel(default));
                    channels.Add(fastServer.GetChannel(default));
コード例 #6
0
        public void TestAggregateMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.RemoveAll();
                        _collection.DropAllIndexes();
                        _collection.Insert(new BsonDocument("x", 1));

                        failpoint.SetAlwaysOn();
                        var query = _collection.Aggregate(new AggregateArgs
                        {
                            Pipeline = new BsonDocument[]
                            {
                                new BsonDocument("$match", Query.Exists("_id").ToBsonDocument())
                            },
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        });
                        Assert.Throws<MongoExecutionTimeoutException>(() => query.ToList());
                    }
                }
            }
        }
コード例 #7
0
        public void TestDistinctWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.Drop();
                        _collection.Insert(new BsonDocument("x", 1)); // ensure collection is not empty

                        failpoint.SetAlwaysOn();
                        var args = new DistinctArgs
                        {
                            Key = "x",
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.Distinct<BsonValue>(args));
                    }
                }
            }
        }
コード例 #8
0
 public void TestFindAndModifyWithMaxTime()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 var args = new FindAndModifyArgs
                 {
                     Update = Update.Set("x", 1),
                     MaxTime = TimeSpan.FromMilliseconds(1)
                 };
                 Assert.Throws<MongoExecutionTimeoutException>(() => _collection.FindAndModify(args));
             }
         }
     }
 }
コード例 #9
0
        public void TestValidateWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime) && _primary.InstanceType != MongoServerInstanceType.ShardRouter)
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.Drop();
                        _collection.Insert(new BsonDocument("x", 1)); // ensure collection is not empty

                        failpoint.SetAlwaysOn();
                        var args = new ValidateCollectionArgs
                        {
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.Validate(args));
                    }
                }
            }
        }
コード例 #10
0
 public void TestCountWithMaxTimeFromFind()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 Assert.Throws<MongoExecutionTimeoutException>(() => _collection.Find(Query.EQ("x", 1)).SetMaxTime(TimeSpan.FromMilliseconds(1)).Count());
             }
         }
     }
 }
コード例 #11
0
        public void TestGroupWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.Drop();
                        _collection.Insert(new BsonDocument("x", 1)); // ensure collection is not empty

                        failpoint.SetAlwaysOn();
                        var args = new GroupArgs
                        {
                            KeyFields = GroupBy.Keys("x"),
                            Initial = new BsonDocument("count", 0),
                            ReduceFunction = "function(doc, prev) { prev.count += 1 }",
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.Group(args));
                    }
                }
            }
        }
コード例 #12
0
        public void TestMapReduceInlineWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.RemoveAll();
                        _collection.Insert(new BsonDocument("x", 1)); // make sure collection has at least one document so map gets called

                        failpoint.SetAlwaysOn();
                        var args = new MapReduceArgs
                        {
                            MapFunction = "function() { }",
                            ReduceFunction = "function(key, value) { return 0; }",
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.MapReduce(args));
                    }
                }
            }
        }
コード例 #13
0
 public void TestEvalWithMaxTime()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 var args = new EvalArgs
                 {
                     Code = "return 0;",
                     MaxTime = TimeSpan.FromMilliseconds(1)
                 };
                 Assert.Throws<ExecutionTimeoutException>(() => _database.Eval(args));
             }
         }
     }
 }
コード例 #14
0
        public void TestGeoNearWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        if (_collection.Exists()) { _collection.Drop(); }
                        _collection.Insert(new BsonDocument("loc", new BsonArray { 0, 0 }));
                        _collection.CreateIndex(IndexKeys.GeoSpatial("loc"));

                        failpoint.SetAlwaysOn();
                        var args = new GeoNearArgs
                        {
                            Near = new XYPoint(0, 0),
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.GeoNearAs<BsonDocument>(args));
                    }
                }
            }
        }
コード例 #15
0
        public void TestGeoHaystackSearchWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                if (_primary.InstanceType != MongoServerInstanceType.ShardRouter)
                {
                    using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                    {
                        if (failpoint.IsSupported())
                        {
                            if (_collection.Exists()) { _collection.Drop(); }
                            _collection.Insert(new Place { Location = new[] { 34.2, 33.3 }, Type = "restaurant" });
                            _collection.Insert(new Place { Location = new[] { 34.2, 37.3 }, Type = "restaurant" });
                            _collection.Insert(new Place { Location = new[] { 59.1, 87.2 }, Type = "office" });
                            _collection.CreateIndex(IndexKeys.GeoSpatialHaystack("Location", "Type"), IndexOptions.SetBucketSize(1));

                            failpoint.SetAlwaysOn();
                            var args = new GeoHaystackSearchArgs
                            {
                                Near = new XYPoint(33, 33),
                                AdditionalFieldName = "Type",
                                AdditionalFieldValue = "restaurant",
                                Limit = 30,
                                MaxDistance = 6,
                                MaxTime = TimeSpan.FromMilliseconds(1)
                            };
                            Assert.Throws<MongoExecutionTimeoutException>(() => _collection.GeoHaystackSearchAs<Place>(args));
                        }
                    }
                }
            }
        }
コード例 #16
0
        public void TestFindWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        if (_collection.Exists()) { _collection.Drop(); }
                        _collection.Insert(new BsonDocument("x", 1));

                        failpoint.SetAlwaysOn();
                        var maxTime = TimeSpan.FromMilliseconds(1);
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.FindAll().SetMaxTime(maxTime).ToList());
                    }
                }
            }
        }
コード例 #17
0
        public void TestFindOneAsWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.RemoveAll();
                        _collection.Insert(new BsonDocument { { "X", 1 } });

                        failpoint.SetAlwaysOn();
                        var args = new FindOneArgs { MaxTime = TimeSpan.FromMilliseconds(1) };
                        Assert.Throws<MongoExecutionTimeoutException>(() => _collection.FindOneAs(typeof(TestClass), args));
                    }
                }
            }
        }
コード例 #18
0
 public void TestCountWithMaxTime()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 var args = new CountArgs { MaxTime = TimeSpan.FromMilliseconds(1) };
                 Assert.Throws<ExecutionTimeoutException>(() => _collection.Count(args));
             }
         }
     }
 }
コード例 #19
0
 public void TestEvalWithMaxTime()
 {
     if (!DriverTestConfiguration.Client.Settings.Credentials.Any())
     {
         if (_primary.Supports(FeatureId.MaxTime))
         {
             using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
             {
                 if (failpoint.IsSupported())
                 {
                     failpoint.SetAlwaysOn();
                     var args = new EvalArgs
                     {
                         Code = "return 0;",
                         MaxTime = TimeSpan.FromMilliseconds(1)
                     };
                     Assert.Throws<MongoExecutionTimeoutException>(() => _adminDatabase.Eval(args));
                 }
             }
         }
     }
 }