public override RpbReq ConstructPbRequest()
        {
            var req = new DtUpdateReq();

            req.type   = CommandOptions.BucketType;
            req.bucket = CommandOptions.Bucket;
            req.key    = CommandOptions.Key;

            req.w  = CommandOptions.W;
            req.pw = CommandOptions.PW;
            req.dw = CommandOptions.DW;

            req.return_body = CommandOptions.ReturnBody;

            req.timeout = (uint)CommandOptions.Timeout;

            req.context         = CommandOptions.Context;
            req.include_context = CommandOptions.IncludeContext;

            if (req.include_context)
            {
                req.return_body = true;
            }

            req.op = GetRequestOp();

            return(req);
        }
        /// <summary>
        /// Compress all operations in a RiakDtCounter into a single DtUpdateReq
        /// </summary>
        /// <param name="options">The RiakDtUpdateOptions</param>
        /// <returns>Returns a valid DtUpdateReq or null.</returns>
        /// <remarks>A null value will be returned when the net of all counter
        /// operations will produce no change to the counter value. That is:
        /// when the sum of all operations is 0, null will be returned. In these
        /// situations, the caller should not submit any changes to Riak. </remarks>
        internal DtUpdateReq ToDtUpdateRequest(RiakDtUpdateOptions options)
        {
            options = options ?? new RiakDtUpdateOptions();

            var request = new DtUpdateReq
            {
                op = { counter_op = ToCounterOp() }
            };

            /* We shouldn't send any operations in to Riak in this case.
             * This means that whatever calls ToDtUpdateRequest needs to
             * be aware of possible null values
             */
            if (request.op.counter_op == null || request.op.counter_op.increment == 0)
            {
                return(null);
            }

            if (options.IncludeContext && context != null)
            {
                request.context = context;
            }

            options.Populate(request);

            return(request);
        }
        internal void Populate(DtUpdateReq request)
        {
            request.w  = W;
            request.dw = Dw;
            request.pw = Pw;

            request.return_body = ReturnBody;

            request.timeout = (uint)Timeout;

            request.sloppy_quorum = SloppyQuorum;

            if (NVal != null)
            {
                request.n_val = NVal;
            }

            request.include_context = IncludeContext;
        }
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var updateSetCommandBuilder = new UpdateSet.Builder(DefaultAdds, DefaultRemoves);

            var q1 = new Quorum(1);
            var q2 = new Quorum(2);
            var q3 = new Quorum(3);

            updateSetCommandBuilder
            .WithBucketType(BucketType)
            .WithBucket(Bucket)
            .WithKey(Key)
            .WithW(q3)
            .WithPW(q1)
            .WithDW(q2)
            .WithReturnBody(true)
            .WithIncludeContext(false)
            .WithContext(Context)
            .WithTimeout(TimeSpan.FromSeconds(20));

            UpdateSet updateSetCommand = updateSetCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateSetCommand.ConstructPbRequest();

            Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key);
            Assert.AreEqual(q3, protobuf.w);
            Assert.AreEqual(q1, protobuf.pw);
            Assert.AreEqual(q2, protobuf.dw);
            Assert.IsTrue(protobuf.return_body);
            Assert.IsFalse(protobuf.include_context);
            Assert.AreEqual(20000, protobuf.timeout);

            SetOp setOpMsg = protobuf.op.set_op;

            Assert.AreEqual(DefaultAdds, setOpMsg.adds);
            Assert.AreEqual(DefaultRemoves, setOpMsg.removes);
        }
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var mapOp = new UpdateMap.MapOperation()
                        .IncrementCounter("counter_1", 50)
                        .RemoveCounter("counter_2")
                        .AddToSet("set_1", "set_value_1")
                        .RemoveFromSet("set_2", "set_value_2")
                        .RemoveSet("set_3")
                        .SetRegister("register_1", "register_value_1")
                        .RemoveRegister("register_2")
                        .SetFlag("flag_1", true)
                        .RemoveFlag("flag_2")
                        .RemoveMap("map_3");

            mapOp.Map("map_2").IncrementCounter("counter_1", 50)
            .RemoveCounter("counter_2")
            .AddToSet("set_1", "set_value_1")
            .RemoveFromSet("set_2", "set_value_2")
            .RemoveSet("set_3")
            .SetRegister("register_1", "register_value_1")
            .RemoveRegister("register_2")
            .SetFlag("flag_1", true)
            .RemoveFlag("flag_2")
            .RemoveMap("map_3");

            var updateMapCommandBuilder = new UpdateMap.Builder(mapOp);

            var q1 = new Quorum(1);
            var q2 = new Quorum(2);
            var q3 = new Quorum(3);

            updateMapCommandBuilder
            .WithBucketType(BucketType)
            .WithBucket(Bucket)
            .WithKey(Key)
            .WithContext(Context)
            .WithW(q3)
            .WithPW(q1)
            .WithDW(q2)
            .WithReturnBody(true)
            .WithIncludeContext(false)
            .WithTimeout(TimeSpan.FromSeconds(20));

            UpdateMap updateMapCommand = updateMapCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateMapCommand.ConstructRequest(false);

            Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key);
            Assert.AreEqual((uint)q3, protobuf.w);
            Assert.AreEqual((uint)q1, protobuf.pw);
            Assert.AreEqual((uint)q2, protobuf.dw);
            Assert.IsTrue(protobuf.return_body);
            Assert.IsFalse(protobuf.include_context);
            Assert.AreEqual(20000, protobuf.timeout);
            Assert.AreEqual(Context, protobuf.context);

            MapOp mapOpMsg = protobuf.op.map_op;

            VerifyRemoves(mapOpMsg.removes);
            MapUpdate innerMapUpdate = VerifyUpdates(mapOpMsg.updates, true);

            VerifyRemoves(innerMapUpdate.map_op.removes);
            VerifyUpdates(innerMapUpdate.map_op.updates, false);
        }