Inheritance: global::ProtoBuf.IExtensible
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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]);
        }
        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"]);
        }