public static RiakBucketKeyInput FromRiakObjectIds(IEnumerable<RiakObjectId> riakObjectIds)
        {
            var rbki = new RiakBucketKeyInput();

            foreach(var objectid in riakObjectIds)
            {
                rbki.AddBucketKey(objectid.Bucket, objectid.Key);
            }

            return rbki;
        }
        public void RiakBucketKeyInputSeralisesCorrectly()
        {
            var input = new RiakBucketKeyInput()
                .Add("foo", "bar")
                .Add("foo", "baz")
                .Add("dooby", "scooby");

            var s = Serialize(input.WriteJson);

            Assert.AreEqual(s, "\"inputs\":[[\"foo\",\"bar\"],[\"foo\",\"baz\"],[\"dooby\",\"scooby\"]]");
        }
Exemplo n.º 3
0
        public void LotsOfConcurrentMapRedRequestsShouldWork()
        {
            var keys = new List<string>();

            for (var i = 1; i < 11; i++)
            {
                var key = "key" + i;
                var doc = new RiakObject(MapReduceBucket, key, new { value = i });
                keys.Add(key);

                var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true });
                result.ShouldNotBeNull();
            }

            var input = new RiakBucketKeyInput();
            keys.ForEach(k => input.Add(MapReduceBucket, k));

            var query = new RiakMapReduceQuery()
                .Inputs(input)
                .MapJs(m => m.Source(@"function(o){return[1];}"))
                .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true));
            query.Compile();

            var results = new List<RiakMapReduceResult>[ThreadCount];
            var watch = Stopwatch.StartNew();
            Parallel.For(0, ThreadCount, i =>
                {
                    results[i] = DoMapRed(query);
                });
            watch.Stop();
            var executionTime = watch.Elapsed;

            var failures = 0;
            foreach (var r in results.SelectMany(l => l))
            {
                if (r != null)
                {
                    var resultValue = JsonConvert.DeserializeObject<int[]>(r.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0];
                    resultValue.ShouldEqual(10);
                    //r.Value.PhaseResults.ElementAt(1).GetObject<int[]>()[0].ShouldEqual(10);
                }
                else
                {
                    // the only acceptable result is that it ran out of retries when
                    // talking to the cluster (trying to get a connection)
                    //r.ResultCode.ShouldEqual(ResultCode.NoRetries);
                    ++failures;
                }
            }

            Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention. Execution time = {2} milliseconds, for an average of {3} milliseconds", failures, ThreadCount * ActionCount, executionTime.TotalMilliseconds, (executionTime.TotalMilliseconds/(ThreadCount * ActionCount)));
        }
Exemplo n.º 4
0
 public RiakMapReduceQuery Inputs(RiakBucketKeyInput riakBucketKeyInputs)
 {
     _inputs = riakBucketKeyInputs;
     return this;
 }
 public static RiakBucketKeyInput FromRiakObjectIds(IEnumerable<RiakObjectId> riakObjectIds)
 {
     var rbki = new RiakBucketKeyInput();
     rbki.Add(riakObjectIds);
     return rbki;
 }
Exemplo n.º 6
0
        public void RiakObjectLinksAreTheSameAsLinksRetrievedViaMapReduce()
        {
            var jeremiah = Client.Get(TestBucket, Jeremiah).Value;
            var jLinks = jeremiah.Links;

            var input = new RiakBucketKeyInput();
            input.AddBucketKey(TestBucket, Jeremiah);

            var query = new RiakMapReduceQuery()
                .Inputs(input)
                .Link(l => l.AllLinks().Keep(true));

            var mrResult = Client.MapReduce(query);
            mrResult.IsSuccess.ShouldBeTrue();

            // TODO Is *this* chunk of code acceptable?
            // This should probably be taken care of in the RiakClient.WalkLinks
            var listOfLinks = mrResult.Value.PhaseResults.OrderBy(pr => pr.Phase)
                                  .ElementAt(0).Values
                                  .Select(v => RiakLink.ParseArrayFromJsonString(v.FromRiakString()));

            var mrLinks = from link in listOfLinks
                          from item in link
                          select item;

            mrLinks.Count().ShouldEqual(jLinks.Count);
            foreach (var link in jLinks)
            {
                mrLinks.ShouldContain(link);
            }
        }
Exemplo n.º 7
0
        public void LotsOfConcurrentStreamingMapRedRequestsShouldWork()
        {
            var keys = new List<string>();

            for (var i = 1; i < 11; i++)
            {
                var key = "key" + i;
                var doc = new RiakObject(MapReduceBucket, key, new { value = i });
                keys.Add(key);

                var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true });
                result.ShouldNotBeNull();
            }

            var input = new RiakBucketKeyInput();
            keys.ForEach(k => input.Add(MapReduceBucket, k));

            var query = new RiakMapReduceQuery()
                .Inputs(input)
                .MapJs(m => m.Source(@"function(o){return[1];}"))
                .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true));
            query.Compile();

            var results = new List<RiakMapReduceResultPhase>[ThreadCount];
            var watch = Stopwatch.StartNew();
            Parallel.For(0, ThreadCount, i =>
                {
                    results[i] = DoStreamingMapRed(query);
                });
            watch.Stop();
            var executionTime = watch.Elapsed;

            var failures = 0;
            foreach (var result in results)
            {
                if (result.Count > 0)
                {
                    var lastResult = result.OrderByDescending(r => r.Phase).First();
                    var resultValue = JsonConvert.DeserializeObject<int[]>(lastResult.Values.First().FromRiakString());
                    //var resultValue = JsonConvert.DeserializeObject<int[]>(r.Value.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0];
                    // due to the speed which things happen at, we can't gaurantee all 10 will be in the result set
                    resultValue[0].IsAtLeast(5);
                    //lastResult.GetObject<int[]>()[0].ShouldEqual(10);
                }
                else
                {
                    ++failures;
                }
            }

            Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention. Execution time = {2} milliseconds, for an average of {3} milliseconds", failures, ThreadCount * ActionCount, executionTime.TotalMilliseconds, (executionTime.TotalMilliseconds / (ThreadCount * ActionCount)));
        }