public void Should_process_kill_cursors() { var expectedCommand = BsonDocument.Parse("{ killCursors: 'bar', cursors: [NumberLong(20)] }"); var expectedReply = BsonDocument.Parse("{ ok: 1, cursorsUnknown: [NumberLong(20)] }"); var requestMessage = MessageHelper.BuildKillCursors(10, 20); using (EventContext.BeginKillCursors(MessageHelper.DefaultCollectionNamespace)) { SendMessages(requestMessage); } var commandStartedEvent = (CommandStartedEvent)_capturedEvents.Next(); var commandSucceededEvent = (CommandSucceededEvent)_capturedEvents.Next(); commandStartedEvent.CommandName.Should().Be(expectedCommand.GetElement(0).Name); commandStartedEvent.Command.Should().Be(expectedCommand); commandStartedEvent.ConnectionId.Should().Be(_subject.ConnectionId); commandStartedEvent.DatabaseNamespace.Should().Be(MessageHelper.DefaultDatabaseNamespace); commandStartedEvent.OperationId.Should().Be(EventContext.OperationId); commandStartedEvent.RequestId.Should().Be(requestMessage.RequestId); commandSucceededEvent.CommandName.Should().Be(commandStartedEvent.CommandName); commandSucceededEvent.ConnectionId.Should().Be(commandStartedEvent.ConnectionId); commandSucceededEvent.Duration.Should().BeGreaterThan(TimeSpan.Zero); commandSucceededEvent.OperationId.Should().Be(commandStartedEvent.OperationId); commandSucceededEvent.Reply.Should().Be(expectedReply); commandSucceededEvent.RequestId.Should().Be(commandStartedEvent.RequestId); }
private async Task KillCursorsAsync(CancellationToken cancellationToken) { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = await _channelSource.GetChannelAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { if (!channel.Connection.IsExpired) { await ExecuteKillCursorsCommandAsync(channel, cancellationToken).ConfigureAwait(false); } } }
private void KillCursors(CancellationToken cancellationToken) { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = _channelSource.GetChannel(cancellationTokenSource.Token)) { if (!channel.Connection.IsExpired) { ExecuteKillCursorsCommand(channel, cancellationToken); } } }
private void KillCursor(long cursorId, CancellationToken cancellationToken) { try { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = _channelSource.GetChannel(cancellationTokenSource.Token)) { ExecuteKillCursorsProtocol(channel, cancellationToken); } } catch { // ignore exceptions } }
private async Task KillCursorsAsync(CancellationToken cancellationToken) { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = await _channelSource.GetChannelAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { if (Feature.KillCursorsCommand.IsSupported(channel.ConnectionDescription.ServerVersion)) { await ExecuteKillCursorsCommandAsync(channel, cancellationToken).ConfigureAwait(false); } else { await ExecuteKillCursorsProtocolAsync(channel, cancellationToken).ConfigureAwait(false); } } }
private void KillCursors(CancellationToken cancellationToken) { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = _channelSource.GetChannel(cancellationTokenSource.Token)) { if (Feature.KillCursorsCommand.IsSupported(channel.ConnectionDescription.ServerVersion)) { ExecuteKillCursorsCommand(channel, cancellationToken); } else { ExecuteKillCursorsProtocol(channel, cancellationToken); } } }
private async Task KillCursorAsync(long cursorId, CancellationToken cancellationToken) { try { using (EventContext.BeginOperation(_operationId)) using (EventContext.BeginKillCursors(_collectionNamespace)) using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10))) using (var channel = await _channelSource.GetChannelAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { await ExecuteKillCursorsProtocolAsync(channel, cancellationToken).ConfigureAwait(false); } } catch { // ignore exceptions } }