예제 #1
0
        public override void OnSuccess(RpbResp response)
        {
            if (response == null)
            {
                Response = new SetResponse();
            }
            else
            {
                DtFetchResp fetchResp = (DtFetchResp)response;
                if (fetchResp.type != DtFetchResp.DataType.SET)
                {
                    throw new RiakException(
                              string.Format("Requested set, received {0}", fetchResp.type));
                }

                if (fetchResp.value == null)
                {
                    Response = new SetResponse();
                }
                else
                {
                    Response = new SetResponse(
                        Options.Key,
                        fetchResp.context,
                        new HashSet <byte[]>(fetchResp.value.set_value));
                }
            }
        }
예제 #2
0
        public override void OnSuccess(RpbResp response)
        {
            if (response == null)
            {
                Response = new CounterResponse();
            }
            else
            {
                DtFetchResp fetchResp = (DtFetchResp)response;
                if (fetchResp.type != DtFetchResp.DataType.COUNTER)
                {
                    throw new RiakException(
                              string.Format("Requested counter, received {0}", fetchResp.type));
                }

                if (fetchResp.value == null)
                {
                    Response = new CounterResponse();
                }
                else
                {
                    Response = new CounterResponse(Options.Key, fetchResp.context, fetchResp.value.counter_value);
                }
            }
        }
예제 #3
0
        public override void OnSuccess(RiakResp response)
        {
            if (response == null)
            {
                Response = new MapResponse();
            }
            else
            {
                DtFetchResp fetchResp = (DtFetchResp)response;
                if (fetchResp.type != DtFetchResp.DataType.MAP)
                {
                    throw new RiakException(
                              string.Format("Requested map, received {0}", fetchResp.type));
                }

                if (fetchResp.value == null)
                {
                    Response = new MapResponse();
                }
                else
                {
                    Response = new MapResponse(Options.Key, fetchResp.context, fetchResp.value.map_value);
                }
            }
        }
예제 #4
0
        public override void OnSuccess(RiakResp response)
        {
            if (response == null)
            {
                Response = new HllResponse();
            }
            else
            {
                DtFetchResp fetchResp = (DtFetchResp)response;
                if (fetchResp.type != DtFetchResp.DataType.HLL)
                {
                    throw new RiakException(
                              string.Format("Requested hyperloglog, received {0}", fetchResp.type));
                }

                if (fetchResp.value == null)
                {
                    Response = new HllResponse();
                }
                else
                {
                    Response = new HllResponse(Options.Key, fetchResp.value.hll_value);
                }
            }
        }
        public void Should_Construct_SetResponse_From_DtFetchResp()
        {
            var set_item_1 = new RiakString("set_item_1");
            var set_item_2 = new RiakString("set_item_2");
            var value      = new DtValue();

            value.set_value.Add(set_item_1);
            value.set_value.Add(set_item_2);

            var fetchResp = new DtFetchResp();

            fetchResp.value = value;
            fetchResp.type  = DtFetchResp.DataType.SET;

            var fetch = new FetchSet.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(Key)
                        .Build();

            fetch.OnSuccess(fetchResp);

            var itemList = fetch.Response.Value.Select(v => new RiakString(v)).ToList();

            Assert.AreEqual(set_item_1, itemList[0]);
            Assert.AreEqual(set_item_2, itemList[1]);
        }
        // TODO: Deprecate?

        /// <summary>
        /// Initializes a new instance of the <see cref="RiakDtCounter"/> class.
        /// </summary>
        /// <param name="bucket">The bucket name of this counter's object.</param>
        /// <param name="bucketType">The bucket type of this counter's object.</param>
        /// <param name="key">The key of this counter's object.</param>
        /// <param name="response">The response containing the counter's server-side value and context.</param>
        /// <remarks>Not used.</remarks>
        public RiakDtCounter(string bucket, string bucketType, string key, DtFetchResp response)
        {
            Bucket     = bucket;
            BucketType = bucketType;
            Key        = key;
            value      = response.value.counter_value;
            context    = response.context;
        }
        public void Should_Construct_CounterResponse_From_DtFetchResp()
        {
            var value = new DtValue();

            value.counter_value = 42;

            var fetchResp = new DtFetchResp();

            fetchResp.value = value;
            fetchResp.type  = DtFetchResp.DataType.COUNTER;

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

            fetch.OnSuccess(fetchResp);

            Assert.AreEqual(42, fetch.Response.Value);
        }
        public void Should_Construct_MapResponse_From_DtFetchResp()
        {
            var key     = new RiakString("riak_generated_key");
            var context = new RiakString("1234");

            var fetchResp = new DtFetchResp();

            fetchResp.type    = DtFetchResp.DataType.MAP;
            fetchResp.value   = new DtValue();
            fetchResp.context = context;

            Func <IEnumerable <MapEntry> > createMapEntries = () =>
            {
                var mapEntries = new List <MapEntry>();

                var mapField = new MapField();
                mapField.type = MapField.MapFieldType.COUNTER;
                mapField.name = new RiakString("counter_1");
                var mapEntry = new MapEntry();
                mapEntry.field         = mapField;
                mapEntry.counter_value = 50;
                mapEntries.Add(mapEntry);

                mapField       = new MapField();
                mapField.type  = MapField.MapFieldType.SET;
                mapField.name  = new RiakString("set_1");
                mapEntry       = new MapEntry();
                mapEntry.field = mapField;
                mapEntry.set_value.Add(RiakString.ToBytes("value_1"));
                mapEntry.set_value.Add(RiakString.ToBytes("value_2"));
                mapEntries.Add(mapEntry);

                mapField                = new MapField();
                mapField.type           = MapField.MapFieldType.REGISTER;
                mapField.name           = new RiakString("register_1");
                mapEntry                = new MapEntry();
                mapEntry.field          = mapField;
                mapEntry.register_value = RiakString.ToBytes("1234");
                mapEntries.Add(mapEntry);

                mapField            = new MapField();
                mapField.type       = MapField.MapFieldType.FLAG;
                mapField.name       = new RiakString("flag_1");
                mapEntry            = new MapEntry();
                mapEntry.field      = mapField;
                mapEntry.flag_value = true;
                mapEntries.Add(mapEntry);

                return(mapEntries);
            };

            fetchResp.value.map_value.AddRange(createMapEntries());

            var map_1_field = new MapField();

            map_1_field.type = MapField.MapFieldType.MAP;
            map_1_field.name = new RiakString("map_1");
            var map_1_entry = new MapEntry();

            map_1_entry.field = map_1_field;
            map_1_entry.map_value.AddRange(createMapEntries());

            fetchResp.value.map_value.Add(map_1_entry);

            Action <Map> verifyMap = (map) =>
            {
                Assert.AreEqual(50, map.Counters["counter_1"]);
                Assert.AreEqual(RiakString.ToBytes("value_1"), map.Sets["set_1"][0]);
                Assert.AreEqual(RiakString.ToBytes("value_2"), map.Sets["set_1"][1]);
                Assert.AreEqual(RiakString.ToBytes("1234"), map.Registers["register_1"]);
                Assert.IsTrue(map.Flags["flag_1"]);
            };

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

            fetch.OnSuccess(fetchResp);

            MapResponse response = fetch.Response;

            Assert.NotNull(response);
            Assert.AreEqual(key, response.Key);
            Assert.AreEqual(RiakString.ToBytes(context), response.Context);

            verifyMap(response.Value);
            verifyMap(response.Value.Maps["map_1"]);
        }