コード例 #1
0
        public void IndexesAreSavedWithAnObject()
        {
            var o = new RiakObject(Bucket, "the_object", "{ value: \"this is an object\" }");
            o.AddIndex("tacos", "are great!");
            o.AddIndex("age", 12);

            Client.Put(o);

            var result = Client.Get(o.ToRiakObjectId());

            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
            var ro = result.Value;

            ro.BinIndexes.Count.ShouldEqual(1);
            ro.IntIndexes.Count.ShouldEqual(1);
        }
コード例 #2
0
        public void RiakIndexNameManglingIsHandledAutomatically()
        {
            var riakObject = new RiakObject(Bucket, Key, "value");
            riakObject.AddIndex("name", "jeremiah");
            riakObject.AddIndex("state_bin", "oregon");
            riakObject.AddIndex("age", 32);
            riakObject.AddIndex("cats_int", 2);

            riakObject.Indexes.Keys.Contains("name").ShouldBeFalse();
            riakObject.Indexes.Keys.Contains("age").ShouldBeFalse();
            riakObject.Indexes.Keys.Contains("state").ShouldBeFalse();
            riakObject.Indexes.Keys.Contains("state_bin_bin").ShouldBeFalse();
            riakObject.Indexes.Keys.Contains("cats").ShouldBeFalse();
            riakObject.Indexes.Keys.Contains("cats_int_int").ShouldBeFalse();

            riakObject.Indexes.Keys.Contains("name_bin").ShouldBeTrue();
            riakObject.Indexes.Keys.Contains("age_int").ShouldBeTrue();
            riakObject.Indexes.Keys.Contains("state_bin").ShouldBeTrue();
            riakObject.Indexes.Keys.Contains("cats_int").ShouldBeTrue();
        }
コード例 #3
0
        public void BinIndexGetReturnsListOfKeys()
        {
            for (var i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{ value: \"this is an object\" }");
                o.AddIndex("age", "32");

                Client.Put(o);
            }

            var result = Client.IndexGet(Bucket, "age", "32");
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
            result.Value.Count.ShouldEqual(10);

            foreach (var v in result.Value)
            {
                var key = int.Parse(v);
                key.ShouldBeLessThan(10);
                key.ShouldBeGreaterThan(-1);
            }
        }
コード例 #4
0
        public void QueryingByIntIndexReturnsAListOfKeys()
        {
            for (var i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{\"value\":\"this is an object\"}");
                o.AddIndex("age", 32);

                Client.Put(o);
            }

            var mr = new RiakMapReduceQuery()
                .Inputs(RiakIndex.Match(Bucket, "age", 32));

            var result = Client.MapReduce(mr);
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);

            var keys = result.Value.PhaseResults.SelectMany(x => x.GetObjects<RiakObjectId>()).ToList();

            keys.Count().ShouldEqual(10);

            foreach (var key in keys)
            {
                key.Bucket.ShouldNotBeNullOrEmpty();
                key.Key.ShouldNotBeNullOrEmpty();
            }
        }
コード例 #5
0
        public void IntRangeQueriesReturnMultipleKeys()
        {
            for (var i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{ value: \"this is an object\" }");
                o.AddIndex("age", 25 + i);

                Client.Put(o);
            }

            var mr = new RiakMapReduceQuery()
                .Inputs(RiakIndex.Range(Bucket, "age", 27, 30))
                .ReduceErlang(r => r.ModFun("riak_kv_mapreduce", "reduce_identity").Keep(true));

            var result = Client.MapReduce(mr);
            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);

            // TODO write tests verifying results
        }