public void Should_Construct_CounterResponse_From_DtUpdateResp()
        {
            var key     = new RiakString("riak_generated_key");
            var context = new RiakString("1234");

            var updateResp = new DtUpdateResp();

            updateResp.key           = key;
            updateResp.context       = context;
            updateResp.counter_value = DefaultIncrement;

            var update = new UpdateCounter.Builder(DefaultIncrement)
                         .WithBucketType(BucketType)
                         .WithBucket(Bucket)
                         .Build();

            update.OnSuccess(updateResp);

            CounterResponse response = update.Response;

            Assert.NotNull(response);
            Assert.AreEqual(key, response.Key);
            Assert.AreEqual(RiakString.ToBytes(context), response.Context);
            Assert.AreEqual(DefaultIncrement, response.Value);
        }
Esempio n. 2
0
        public void Riak_Can_Generate_Key()
        {
            CounterResponse r = SaveCounter();

            Assert.IsNotNullOrEmpty(r.Key);
            Log.DebugFormat("Riak Generated Key: {0}", r.Key);
        }
        public void Riak_Can_Generate_Key()
        {
            CounterResponse r = SaveCounter();

            Assert.True(EnumerableUtil.NotNullOrEmpty((string)r.Key));
            Log.DebugFormat("Riak Generated Key: {0}", r.Key);
        }
        public override Task <CounterResponse> GetCurrent(Empty request, ServerCallContext context)
        {
            Current++;
            var reply = new CounterResponse()
            {
                Value = Current
            };

            return(Task.FromResult(reply));
        }
Esempio n. 5
0
        public CounterResponse RegisterCounter(CounterData counterData)
        {
            var data = counterData.ToCounterData();

            var jsonFormatter = new JsonMediaTypeFormatter();
            var content       = new ObjectContent <RegisterCounterRequest>(data, jsonFormatter);

            var x        = ExecuteQuery <RegisterCounterRequest, RegisterCounterResponse>(content, "counter", "register");
            var response = new CounterResponse();

            return(response);
        }
        public void Fetching_An_Unknown_Counter_Results_In_Not_Found()
        {
            var fetch = new FetchCounter.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(Guid.NewGuid().ToString())
                        .Build();

            RiakResult rslt = client.Execute(fetch);

            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);
            CounterResponse response = fetch.Response;

            Assert.IsTrue(response.NotFound);
        }
        public void CountersIdAndFetch()
        {
            FetchCounter cmd = new FetchCounter.Builder()
                               .WithBucketType("counters")
                               .WithBucket("counters")
                               .WithKey("<insert_key_here>")
                               .Build();

            RiakResult rslt = client.Execute(cmd);

            CheckResult(rslt);

            CounterResponse response = cmd.Response;

            Assert.AreEqual(0, response.Value);

            // NB: for cleanup on test teardown
            options = cmd.Options;
        }
        public void TrafficTicketsCounterFetchAndUpdate()
        {
            var          fetchCounterOptions = new FetchCounterOptions("counters", "counters", "traffic_tickts");
            FetchCounter cmd = new FetchCounter(fetchCounterOptions);

            // NB: for cleanup on test teardown
            options = cmd.Options;

            RiakResult rslt = client.Execute(cmd);

            CheckResult(rslt);

            CounterResponse response = cmd.Response;

            Assert.AreEqual(0, response.Value);

            UpdateCounter updateCmd = new UpdateCounter.Builder()
                                      .WithBucketType("counters")
                                      .WithBucket("counters")
                                      .WithKey("traffic_tickets")
                                      .WithIncrement(1)
                                      .Build();

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

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

            updateCmd = new UpdateCounter.Builder()
                        .WithBucketType("counters")
                        .WithBucket("counters")
                        .WithKey("traffic_tickets")
                        .WithIncrement(-1)
                        .Build();

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

            response = updateCmd.Response;
            Assert.AreEqual(0, response.Value);
        }
        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 Can_Update_A_Counter()
        {
            string key = Guid.NewGuid().ToString();

            SaveCounter(key);

            var update = new UpdateCounter.Builder(DefaultIncrement)
                         .WithBucketType(BucketType)
                         .WithBucket(Bucket)
                         .WithKey(key)
                         .WithReturnBody(true)
                         .WithTimeout(TimeSpan.FromMilliseconds(20000))
                         .Build();

            RiakResult rslt = client.Execute(update);

            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);

            CounterResponse response = update.Response;

            Assert.AreEqual(20, response.Value);
        }
        public void Fetching_A_Counter_Produces_Expected_Values()
        {
            string key = Guid.NewGuid().ToString();

            SaveCounter(key);

            var fetch = new FetchCounter.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(key)
                        .Build();

            RiakResult rslt = client.Execute(fetch);

            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);

            CounterResponse response = fetch.Response;

            Assert.IsNotNull(response);

            Assert.AreEqual(DefaultIncrement, 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);
        }
Esempio n. 13
0
 public RegisterCompleteEventArgs(bool isServerOnline, CounterResponse counterResponse)
 {
     _isServerOnline  = isServerOnline;
     _counterResponse = counterResponse;
 }