예제 #1
0
 public void ReadMessage_should_throw_if_binaryReader_was_not_provided()
 {
     using (var stream = new MemoryStream())
         using (var binaryWriter = new BsonBinaryWriter(stream))
         {
             var    subject = new DeleteMessageBinaryEncoder(null, binaryWriter);
             Action action  = () => subject.ReadMessage();
             action.ShouldThrow <InvalidOperationException>();
         }
 }
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
     {
         var subject = new DeleteMessageBinaryEncoder(stream, __messageEncoderSettings);
         var message = subject.ReadMessage();
         message.CollectionNamespace.Should().Be(__collectionNamespace);
         message.IsMulti.Should().Be(__isMulti);
         message.Query.Should().Be(__query);
         message.RequestId.Should().Be(__requestId);
     }
 }
        public void ReadMessage_should_decode_flags_correctly(int flags, bool isMulti)
        {
            var bytes = (byte[])__testMessageBytes.Clone();

            bytes[__flagsOffset] = (byte)flags;

            using (var stream = new MemoryStream(bytes))
            {
                var subject = new DeleteMessageBinaryEncoder(stream, __messageEncoderSettings);
                var message = subject.ReadMessage();
                message.IsMulti.Should().Be(isMulti);
            }
        }
        public void ReadMessage_should_throw_when_opcode_is_invalid()
        {
            var bytes = (byte[])__testMessageBytes.Clone();

            bytes[12]++;

            using (var stream = new MemoryStream(bytes))
            {
                var subject   = new DeleteMessageBinaryEncoder(stream, __messageEncoderSettings);
                var exception = Record.Exception(() => subject.ReadMessage());
                exception.Should().BeOfType <FormatException>();
                exception.Message.Should().Be("Delete message opcode is not OP_DELETE.");
            }
        }
예제 #5
0
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
         using (var binaryReader = new BsonBinaryReader(stream))
         {
             var subject = new DeleteMessageBinaryEncoder(binaryReader, null);
             var message = subject.ReadMessage();
             message.CollectionName.Should().Be(__collectionName);
             message.DatabaseName.Should().Be(__databaseName);
             message.IsMulti.Should().Be(__isMulti);
             message.Query.Should().Be(__query);
             message.RequestId.Should().Be(__requestId);
         }
 }
 public void ReadMessage_should_throw_if_binaryReader_was_not_provided()
 {
     using (var stream = new MemoryStream())
     using (var binaryWriter = new BsonBinaryWriter(stream))
     {
         var subject = new DeleteMessageBinaryEncoder(null, binaryWriter);
         Action action = () => subject.ReadMessage();
         action.ShouldThrow<InvalidOperationException>();
     }
 }
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
     using (var binaryReader = new BsonBinaryReader(stream))
     {
         var subject = new DeleteMessageBinaryEncoder(binaryReader, null);
         var message = subject.ReadMessage();
         message.CollectionName.Should().Be(__collectionName);
         message.DatabaseName.Should().Be(__databaseName);
         message.IsMulti.Should().Be(__isMulti);
         message.Query.Should().Be(__query);
         message.RequestId.Should().Be(__requestId);
     }
 }
        public void ReadMessage_should_decode_flags_correctly(int flags, bool isMulti)
        {
            var bytes = (byte[])__testMessageBytes.Clone();
            bytes[__flagsOffset] = (byte)flags;

            using (var stream = new MemoryStream(bytes))
            using (var binaryReader = new BsonBinaryReader(stream))
            {
                var subject = new DeleteMessageBinaryEncoder(binaryReader, null);
                var message = subject.ReadMessage();
                message.IsMulti.Should().Be(isMulti);
            }
        }
        private void ProcessDeleteMessage(DeleteMessage originalMessage, Queue<RequestMessage> messageQueue, ConnectionId connectionId, DeleteMessageBinaryEncoder encoder, Stopwatch stopwatch)
        {
            var commandName = "delete";
            var operationId = EventContext.OperationId;
            int requestId = originalMessage.RequestId;
            var expectedResponseType = ExpectedResponseType.None;
            int gleRequestId;
            WriteConcern writeConcern;
            if (TryGetWriteConcernFromGLE(messageQueue, out gleRequestId, out writeConcern))
            {
                requestId = gleRequestId;
                expectedResponseType = ExpectedResponseType.GLE;
            }

            if (_startedEvent != null)
            {
                var decodedMessage = encoder.ReadMessage(RawBsonDocumentSerializer.Instance);
                try
                {
                    var entry = new BsonDocument
                    {
                        { "q", decodedMessage.Query },
                        { "limit", decodedMessage.IsMulti ? 0 : 1 }
                    };
                    var command = new BsonDocument
                    {
                        { commandName, decodedMessage.CollectionNamespace.CollectionName },
                        { "deletes", new BsonArray(new [] { entry }) }
                    };

                    if (writeConcern == null)
                    {
                        command["writeConcern"] = WriteConcern.Unacknowledged.ToBsonDocument();
                    }
                    else if (!writeConcern.IsServerDefault)
                    {
                        command["writeConcern"] = writeConcern.ToBsonDocument();
                    }

                    var @event = new CommandStartedEvent(
                        commandName,
                        command,
                        decodedMessage.CollectionNamespace.DatabaseNamespace,
                        operationId,
                        requestId,
                        connectionId);

                    _startedEvent(@event);
                }
                finally
                {
                    var disposable = decodedMessage.Query as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }

            if (_shouldTrackState)
            {
                _state.TryAdd(requestId, new CommandState
                {
                    CommandName = commandName,
                    OperationId = operationId,
                    Stopwatch = stopwatch,
                    ExpectedResponseType = expectedResponseType
                });
            }
        }
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
     {
         var subject = new DeleteMessageBinaryEncoder(stream, __messageEncoderSettings);
         var message = subject.ReadMessage();
         message.CollectionNamespace.Should().Be(__collectionNamespace);
         message.IsMulti.Should().Be(__isMulti);
         message.Query.Should().Be(__query);
         message.RequestId.Should().Be(__requestId);
     }
 }