public bool OneTimeSetup() { __capturedEvents = new EventCapturer() .Capture <CommandStartedEvent>(e => __commandsToCapture.Contains(e.CommandName)) .Capture <CommandSucceededEvent>(e => __commandsToCapture.Contains(e.CommandName)) .Capture <CommandFailedEvent>(e => __commandsToCapture.Contains(e.CommandName)); var settings = new MongoClientSettings { ClusterConfigurator = cb => { cb = CoreTestConfiguration.ConfigureCluster(cb); cb.Subscribe(__capturedEvents); // never heartbeat... cb.ConfigureServer(ss => ss.With(heartbeatInterval: Timeout.InfiniteTimeSpan)); } }; settings.RetryWrites = false; __client = new MongoClient(settings); return(true); }
private DisposableMongoClient CreateDisposableClient(EventCapturer eventCapturer) { return(DriverTestConfiguration.CreateDisposableClient( (MongoClientSettings settings) => { settings.ClusterConfigurator = c => { c = CoreTestConfiguration.ConfigureCluster(c); c.Subscribe(eventCapturer); c.ConfigureServer(ss => ss.With(heartbeatInterval: Timeout.InfiniteTimeSpan)); }; })); }
public void Command_should_use_serverApi([Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.CommandMessage); var serverApi = new ServerApi(ServerApiVersion.V1); var eventCapturer = new EventCapturer().Capture <CommandStartedEvent>(e => e.CommandName == "ping"); var builder = CoreTestConfiguration .ConfigureCluster(new ClusterBuilder()) .Subscribe(eventCapturer) .ConfigureCluster(x => x.With(serverApi: serverApi)); using (var cluster = CoreTestConfiguration.CreateCluster(builder)) using (var session = cluster.StartSession()) { var cancellationToken = CancellationToken.None; var server = (Server)cluster.SelectServer(WritableServerSelector.Instance, cancellationToken); using (var channel = server.GetChannel(cancellationToken)) { var command = BsonDocument.Parse("{ ping : 1 }"); if (async) { channel .CommandAsync( session, ReadPreference.Primary, DatabaseNamespace.Admin, command, null, // payloads NoOpElementNameValidator.Instance, null, // additionalOptions null, // postWriteAction CommandResponseHandling.Return, BsonDocumentSerializer.Instance, new MessageEncoderSettings(), cancellationToken) .GetAwaiter() .GetResult(); } else { channel.Command( session, ReadPreference.Primary, DatabaseNamespace.Admin, command, null, // payloads NoOpElementNameValidator.Instance, null, // additionalOptions null, // postWriteAction CommandResponseHandling.Return, BsonDocumentSerializer.Instance, new MessageEncoderSettings(), cancellationToken); } } } var commandStartedEvent = eventCapturer.Next().Should().BeOfType <CommandStartedEvent>().Subject; commandStartedEvent.Command["apiVersion"].AsString.Should().Be("1"); }