public void Fetching_A_Map_Produces_Expected_Values()
        {
            string key = Guid.NewGuid().ToString();
            SaveMap(key);

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

            RiakResult rslt = client.Execute(fetch);
            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);

            MapResponse response = fetch.Response;
            Assert.IsNotNull(response);

            Assert.IsNotEmpty(response.Context);
            Assert.IsNotNull(response.Value);
            Assert.AreEqual(1, response.Value.Counters["counter_1"]);
            Assert.AreEqual((RiakString)"value_1", (RiakString)response.Value.Sets["set_1"][0]);
            Assert.AreEqual((RiakString)"register_value_1", (RiakString)response.Value.Registers["register_1"]);
            Assert.AreEqual(true, response.Value.Flags["flag_1"]);

            Map map2 = response.Value.Maps["map_2"];
            Assert.AreEqual(2, map2.Counters["counter_1"]);
            Assert.AreEqual(RiakString.ToBytes("value_1"), map2.Sets["set_1"][0]);
            Assert.AreEqual(RiakString.ToBytes("register_value_1"), map2.Registers["register_1"]);
            Assert.AreEqual(true, map2.Flags["flag_1"]);

            Map map3 = map2.Maps["map_3"];
            Assert.AreEqual(3, map3.Counters["counter_1"]);
        }
Example #2
0
        public override User Get(string key, bool notFoundOK = false)
        {
            FetchMap cmd = new FetchMap.Builder()
                           .WithBucketType(BucketType)
                           .WithBucket(Bucket)
                           .WithKey(key)
                           .Build();

            RiakResult rslt = client.Execute(cmd);

            CheckResult(rslt);
            MapResponse response = cmd.Response;
            Map         map      = response.Value;

            string firstName  = map.Registers.GetValue(firstNameRegister);
            string lastName   = map.Registers.GetValue(lastNameRegister);
            var    interests  = map.Sets.GetValue(interestsSet).ToArray();
            uint   pageVisits = (uint)map.Counters.GetValue(pageVisitsCounter);

            bool accountStatus;

            map.Flags.TryGetValue(paidAccountFlag, out accountStatus);

            return(new User(firstName, lastName, interests, pageVisits, accountStatus));
        }
        protected MapResponse FetchMap(TModel model)
        {
            var cmd = new FetchMap.Builder()
                      .WithBucketType(BucketType)
                      .WithBucket(Bucket)
                      .WithKey(model.ID)
                      .WithIncludeContext(true)
                      .Build();

            RiakResult rslt = client.Execute(cmd);

            CheckResult(rslt);
            return(cmd.Response);
        }
Example #4
0
        public void Fetching_An_Unknown_Map_Results_In_Not_Found()
        {
            var fetch = new FetchMap.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(Guid.NewGuid().ToString())
                        .Build();

            RiakResult rslt = client.Execute(fetch);

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

            Assert.IsTrue(response.NotFound);
        }
Example #5
0
        public void Fetching_A_Map_Produces_Expected_Values()
        {
            string key = Guid.NewGuid().ToString();

            SaveMap(key);

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

            RiakResult rslt = client.Execute(fetch);

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

            MapResponse response = fetch.Response;

            Assert.IsNotNull(response);

            Assert.IsNotEmpty(response.Context);
            Assert.IsNotNull(response.Value);
            Assert.AreEqual(1, response.Value.Counters["counter_1"]);
            Assert.AreEqual((RiakString)"value_1", (RiakString)response.Value.Sets["set_1"][0]);
            Assert.AreEqual((RiakString)"register_value_1", (RiakString)response.Value.Registers["register_1"]);
            Assert.AreEqual(true, response.Value.Flags["flag_1"]);

            Map map2 = response.Value.Maps["map_2"];

            Assert.AreEqual(2, map2.Counters["counter_1"]);
            Assert.AreEqual(RiakString.ToBytes("value_1"), map2.Sets["set_1"][0]);
            Assert.AreEqual(RiakString.ToBytes("register_value_1"), map2.Registers["register_1"]);
            Assert.AreEqual(true, map2.Flags["flag_1"]);

            Map map3 = map2.Maps["map_3"];

            Assert.AreEqual(3, map3.Counters["counter_1"]);
        }
        public void Should_Build_DtFetchReq_Correctly()
        {
            var fetch = new FetchMap.Builder()
                        .WithBucketType(BucketType)
                        .WithBucket(Bucket)
                        .WithKey(Key)
                        .WithR((Quorum)1)
                        .WithPR((Quorum)2)
                        .WithNotFoundOK(true)
                        .WithBasicQuorum(true)
                        .WithTimeout(TimeSpan.FromMilliseconds(20000))
                        .Build();

            DtFetchReq protobuf = (DtFetchReq)fetch.ConstructPbRequest();

            Assert.AreEqual(BucketType, (RiakString)protobuf.type);
            Assert.AreEqual(Bucket, (RiakString)protobuf.bucket);
            Assert.AreEqual(Key, (RiakString)protobuf.key);
            Assert.AreEqual(1, protobuf.r);
            Assert.AreEqual(2, protobuf.pr);
            Assert.AreEqual(true, protobuf.notfound_ok);
            Assert.AreEqual(true, protobuf.basic_quorum);
            Assert.AreEqual(20000, protobuf.timeout);
        }
        public void Should_Build_DtFetchReq_Correctly()
        {
            var fetch = new FetchMap.Builder()
                .WithBucketType(BucketType)
                .WithBucket(Bucket)
                .WithKey(Key)
                .WithR((Quorum)1)
                .WithPR((Quorum)2)
                .WithNotFoundOK(true)
                .WithBasicQuorum(true)
                .WithTimeout(TimeSpan.FromMilliseconds(20000))
                .Build();

            DtFetchReq protobuf = (DtFetchReq)fetch.ConstructPbRequest();

            Assert.AreEqual(BucketType, (RiakString)protobuf.type);
            Assert.AreEqual(Bucket, (RiakString)protobuf.bucket);
            Assert.AreEqual(Key, (RiakString)protobuf.key);
            Assert.AreEqual(1, protobuf.r);
            Assert.AreEqual(2, protobuf.pr);
            Assert.AreEqual(true, protobuf.notfound_ok);
            Assert.AreEqual(true, protobuf.basic_quorum);
            Assert.AreEqual(20000, protobuf.timeout);
        }
        public void Fetching_An_Unknown_Map_Results_In_Not_Found()
        {
            var fetch = new FetchMap.Builder()
                    .WithBucketType(BucketType)
                    .WithBucket(Bucket)
                    .WithKey(Guid.NewGuid().ToString())
                    .Build();

            RiakResult rslt = client.Execute(fetch);
            Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage);
            MapResponse response = fetch.Response;
            Assert.IsTrue(response.NotFound);
        }
        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"]);
        }
        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"]);
        }