public void QueryingByIntIndexReturnsAListOfKeys()
        {
            for (int i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{ value: \"this is an object\" }");
                o.AddIntIndex("age_int", 32);

                Client.Put(o);
            }

            var input = new RiakIntIndexEqualityInput(Bucket, "age_int", 32);

            var mr = new RiakMapReduceQuery();

            mr.Inputs(input)
            .ReduceJs(r => r.Name("mapValuesJson").Keep(true));

            var result = Client.MapReduce(mr);

            result.IsSuccess.ShouldBeTrue();

            var keys = result.Value.PhaseResults.OrderBy(pr => pr.Phase).ElementAt(0).GetObjects <RiakObjectId>();

            keys.Count().ShouldEqual(10);

            foreach (var key in keys)
            {
                key.Bucket.ShouldNotBeNullOrEmpty();
                key.Key.ShouldNotBeNullOrEmpty();
            }
        }
        public void RiakIndexNameManglingIsHandledAutomatically()
        {
            var riakObject = new RiakObject(Bucket, Key, "value");
            riakObject.AddBinIndex("name", "jeremiah");
            riakObject.AddBinIndex("state_bin", "oregon");
            riakObject.AddIntIndex("age", 32);
            riakObject.AddIntIndex("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();
        }
Exemple #3
0
        public void RiakIndexNameManglingIsHandledAutomatically()
        {
            var riakObject = new RiakObject(Bucket, Key, "value");

            riakObject.AddBinIndex("name", "jeremiah");
            riakObject.AddBinIndex("state_bin", "oregon");
            riakObject.AddIntIndex("age", 32);
            riakObject.AddIntIndex("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();
        }
        public void RiakObjectIdCanBeCreatedFromJsonArrayOrObject()
        {
            for (int i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{ value: \"this is an object\" }");
                o.AddIntIndex("age_int", 32);

                Client.Put(o);
            }

            var input = new RiakIntIndexEqualityInput(Bucket, "age_int", 32);

            var mr = new RiakMapReduceQuery()
                     .Inputs(input)
                     .ReduceJs(r => r.Name("mapValuesJson").Keep(true));

            var result = Client.MapReduce(mr);

            result.IsSuccess.ShouldBeTrue();
            var keysOne = result.Value.PhaseResults.OrderBy(pr => pr.Phase).ElementAt(0).GetObjects <RiakObjectId>();

            mr = new RiakMapReduceQuery()
                 .Inputs(input)
                 .ReduceErlang(r => r.ModFun("riak_kv_mapreduce", "reduce_identity").Keep(true));

            result = Client.MapReduce(mr);
            result.IsSuccess.ShouldBeTrue();
            var keysTwo = result.Value.PhaseResults.OrderBy(pr => pr.Phase).ElementAt(0).GetObjects <RiakObjectId>();

            keysOne.Count().ShouldEqual(keysTwo.Count());

            foreach (var key in keysOne)
            {
                key.Key.ShouldNotBeNullOrEmpty();
                key.Bucket.ShouldNotBeNullOrEmpty();

                keysTwo.Contains(key).ShouldBeTrue();
            }

            foreach (var key in keysTwo)
            {
                key.Key.ShouldNotBeNullOrEmpty();
                key.Bucket.ShouldNotBeNullOrEmpty();

                keysOne.Contains(key).ShouldBeTrue();
            }
        }
        public void IndexesAreSavedWithAnObject()
        {
            var o = new RiakObject(Bucket, "the_object", "{ value: \"this is an object\" }");

            o.AddBinIndex("tacos", "are great!");
            o.AddIntIndex("age", 12);

            Client.Put(o);

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

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

            ro.BinIndexes.Count.ShouldEqual(1);
            ro.IntIndexes.Count.ShouldEqual(1);
        }
        public void IntRangeQueriesReturnMultipleKeys()
        {
            for (var i = 0; i < 10; i++)
            {
                var o = new RiakObject(Bucket, i.ToString(), "{ value: \"this is an object\" }");
                o.AddIntIndex("age_int", 25 + i);

                Client.Put(o);
            }

            var input = new RiakIntIndexRangeInput(Bucket, "age_int", 27, 30);

            var mr = new RiakMapReduceQuery()
                     .Inputs(input)
                     .ReduceErlang(r => r.ModFun("riak_kv_mapreduce", "reduce_identity").Keep(true));

            var result = Client.MapReduce(mr);

            result.IsSuccess.ShouldBeTrue();

            // TODO write tests verifying results
        }
        public void SaveDinner(Dinner dinner)
        {
            var ro = new RiakObject(DinnerBucket, dinner.DinnerID, dinner);
            ro.AddIntIndex("EventDate_int", dinner.EventDateToInt());

            _client.Put(ro);
        }