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); }
private CounterResponse SaveCounter(string key = null) { var updateBuilder = new UpdateCounter.Builder(DefaultIncrement) .WithBucketType(BucketType) .WithBucket(Bucket) .WithTimeout(TimeSpan.FromMilliseconds(20000)); if (!string.IsNullOrEmpty(key)) { updateBuilder.WithKey(key); } UpdateCounter cmd = updateBuilder.Build(); RiakResult rslt = client.Execute(cmd); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); CounterResponse response = cmd.Response; Keys.Add(response.Key); return(response); }
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); }
private CounterResponse SaveCounter(string key = null) { var updateBuilder = new UpdateCounter.Builder(DefaultIncrement) .WithBucketType(BucketType) .WithBucket(Bucket) .WithTimeout(TimeSpan.FromMilliseconds(20000)); if (!string.IsNullOrEmpty(key)) { updateBuilder.WithKey(key); } UpdateCounter cmd = updateBuilder.Build(); RiakResult rslt = client.Execute(cmd); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); CounterResponse response = cmd.Response; Keys.Add(response.Key); return response; }