Пример #1
0
        public void WhoopsIGotFiveTrafficTickets()
        {
            var          fetchCounterOptions = new FetchCounterOptions("counters", "counters", "traffic_tickts");
            FetchCounter cmd = new FetchCounter(fetchCounterOptions);

            // NB: for cleanup
            options = fetchCounterOptions;

            RiakResult rslt = client.Execute(cmd);

            CheckResult(rslt);

            CounterResponse response = cmd.Response;

            Assert.AreEqual(0, response.Value);

            var builder = new UpdateCounter.Builder();

            builder.WithBucketType("counters")
            .WithBucket("counters")
            .WithKey("traffic_tickets")
            .WithIncrement(5);

            UpdateCounter updateCmd = builder.Build();

            rslt = client.Execute(updateCmd);
            CheckResult(rslt);

            response = updateCmd.Response;
            Assert.AreEqual(5, response.Value);

            // Modify the builder's increment, then construct a new command
            builder.WithIncrement(-5);
            updateCmd = builder.Build();

            rslt = client.Execute(updateCmd);
            CheckResult(rslt);

            response = updateCmd.Response;
            Assert.AreEqual(0, response.Value);
        }
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var updateCounterCommandBuilder = new UpdateCounter.Builder(DefaultIncrement);

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

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

            UpdateCounter updateCounterCommand = updateCounterCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateCounterCommand.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);

            CounterOp counterOpMsg = protobuf.op.counter_op;

            Assert.AreEqual(DefaultIncrement, counterOpMsg.increment);
        }
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var updateCounterCommandBuilder = new UpdateCounter.Builder(DefaultIncrement);

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

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

            UpdateCounter updateCounterCommand = updateCounterCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateCounterCommand.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);

            CounterOp counterOpMsg = protobuf.op.counter_op;

            Assert.AreEqual(DefaultIncrement, counterOpMsg.increment);
        }
        public void WhoopsIGotFiveTrafficTickets()
        {
            var fetchCounterOptions = new FetchCounterOptions("counters", "counters", "traffic_tickts");
            FetchCounter cmd = new FetchCounter(fetchCounterOptions);

            // NB: for cleanup
            options = fetchCounterOptions;

            RiakResult rslt = client.Execute(cmd);
            CheckResult(rslt);

            CounterResponse response = cmd.Response;
            Assert.AreEqual(0, response.Value);

            var builder = new UpdateCounter.Builder();

            builder.WithBucketType("counters")
                .WithBucket("counters")
                .WithKey("traffic_tickets")
                .WithIncrement(5);

            UpdateCounter updateCmd = builder.Build();

            rslt = client.Execute(updateCmd);
            CheckResult(rslt);

            response = updateCmd.Response;
            Assert.AreEqual(5, response.Value);

            // Modify the builder's increment, then construct a new command
            builder.WithIncrement(-5);
            updateCmd = builder.Build();

            rslt = client.Execute(updateCmd);
            CheckResult(rslt);

            response = updateCmd.Response;
            Assert.AreEqual(0, response.Value);
        }