public void LastModifiedShouldChangeAfterAPutRequest()
        {
            var o = new RiakObject(TestBucket, "1234", new { value = 1234 });

            Client.Put(o);

            var lm2  = o.LastModified;
            var lmu2 = o.LastModifiedUsec;

            Thread.Sleep(500);
            o.SetObject(new { value = 12345 });
            Client.Put(o);

            var lm3  = o.LastModified;
            var lmu3 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm3);
            lmu2.ShouldNotEqual(lmu3);

            Thread.Sleep(500);
            o.SetObject(new { value = 76543 });
            o = Client.Put(o, new RiakPutOptions {
                ReturnBody = false
            }).Value;

            var lm4  = o.LastModified;
            var lmu4 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm4);
            lmu2.ShouldNotEqual(lmu4);
        }
        public void ObjectsAreConvertedProperly()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email = "*****@*****.**",
                Name = new Name
                {
                    FirstName = "OJ",
                    Surname = "Reeves"
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };
            var obj = new RiakObject("bucket", "key");
            obj.SetObject(testPerson);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();
            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject<Person>();
            deserialisedPerson.ShouldEqual(testPerson);
        }
Esempio n. 3
0
        public void ObjectsAreConvertedProperly()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email       = "*****@*****.**",
                Name        = new Name
                {
                    FirstName = "OJ",
                    Surname   = "Reeves"
                },
                PhoneNumbers = new List <PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number     = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };
            var obj = new RiakObject("bucket", "key");

            obj.SetObject(testPerson);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();

            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject <Person>();

            deserialisedPerson.ShouldEqual(testPerson);
        }
        public void CustomSerializerWillSerializeJson()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email = "*****@*****.**",
                Name = new Name
                {
                    FirstName = "OJ",
                    Surname = "Reeves"
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };

            var sots = new SerializeObjectToString<Person>(JsonConvert.SerializeObject);

            var obj = new RiakObject("bucket", "key");
            obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();
            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject<Person>();
            deserialisedPerson.ShouldEqual(testPerson);
        }
Esempio n. 5
0
        public void SavedObjectsShouldBeIdentical()
        {
            // create a proto-contract class (https://code.google.com/p/protobuf-net/wiki/GettingStarted)
            //var testPerson = new ProtoBufPerson()
            //{
            //    Id = 42,
            //    Name = "alex",
            //    Address = new Address()
            //    {
            //        Line1 = "16 dusty road",
            //        Line2 = "santa fe, nm 87508"
            //    }
            //};
            const string bucketName = "test";
            var          ojPerson   = new Person()
            {
                Name = "oj", CurrentlyDrinking = "tea"
            };

            var oj = new RiakObject(bucketName, OJ)
            {
                ContentType = RiakConstants.ContentTypes.ProtocolBuffers
            };

            oj.SetObject(ojPerson);

            var putResult = Client.Put(oj);

            var getResult = Client.Get(bucketName, OJ);
            var newPerson = getResult.GetObject <Person>();

            ojPerson.Name.ShouldEqual(newPerson.Name);


            var testPerson = new ProtoBufPerson()
            {
                Id      = 42,
                Name    = "alex",
                Address = new Address()
                {
                    Line1 = "16 dusty road",
                    Line2 = "santa fe, nm 87508"
                }
            };

            var ro = new RiakObject(bucketName, testPerson.Id.ToString());

            ro.ContentType = RiakConstants.ContentTypes.ProtocolBuffers;
            ro.SetObject(testPerson);

            var putResult2 = Client.Put(ro);

            var getResult2  = Client.Get(bucketName, testPerson.Id.ToString());
            var testPerson2 = getResult2.GetObject <ProtoBufPerson>();

            testPerson.Id.ShouldEqual(testPerson2.Id);
            testPerson.Name.ShouldEqual(testPerson2.Name);
            testPerson.Address.Line1.ShouldEqual(testPerson2.Address.Line1);
            testPerson.Address.Line2.ShouldEqual(testPerson2.Address.Line2);
        }
Esempio n. 6
0
        public virtual string Save(TModel model)
        {
            var riakObjectId = new RiakObjectId(BucketName, model.ID);
            RiakResult <RiakObject> result = client.Get(riakObjectId);

            CheckResult(result, true);

            RiakObject objToUpdate = null;

            if (result.Value != null)
            {
                objToUpdate = result.Value;
                if (objToUpdate.Siblings.Count > 0)
                {
                    // Provide a better sibling resolution strategy here in production
                    objToUpdate = objToUpdate.Siblings[0];
                }

                objToUpdate.SetObject <TModel>(model);
            }
            else
            {
                objToUpdate = new RiakObject(riakObjectId, model);
            }

            result = client.Put(objToUpdate);
            CheckResult(result);
            RiakObject value = result.Value;

            return(value.Key);
        }
Esempio n. 7
0
        private void UpdateCoach(string team, string newCoach)
        {
            var id        = new RiakObjectId("siblings", "coaches", team);
            var getResult = client.Get(id);

            CheckResult(getResult);

            RiakObject obj = getResult.Value;

            obj.SetObject <string>(newCoach, RiakConstants.ContentTypes.TextPlain);
            var rslt = client.Put(obj);

            CheckResult(rslt);
        }
Esempio n. 8
0
        public void JsonConversionTimerTest()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email       = "*****@*****.**",
                Name        = new Name
                {
                    FirstName = "OJ",
                    Surname   = "Reeves"
                },
                PhoneNumbers = new List <PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number     = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };
            var obj = new RiakObject("bucket", "key");

            var sw = new Stopwatch();

            sw.Start();
            const int iterations = 1000000;

            for (var i = 0; i < iterations; ++i)
            {
                obj.SetObject(testPerson);
            }
            sw.Stop();
            Console.WriteLine("Serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));

            sw.Reset();
            sw.Start();

            for (var i = 0; i < iterations; ++i)
            {
                var result = obj.GetObject <Person>();
            }
            sw.Stop();
            Console.WriteLine("De" +
                              "serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
        }
Esempio n. 9
0
        private async Task <bool> UpdateTimeDb(string streamId, Func <IEnumerable <Quantum>, IEnumerable <Quantum> > updateAction)
        {
            var retries = 0;

            while (retries < 5)
            {
                var options = new RiakGetOptions {
                    BasicQuorum = true, NotFoundOk = false
                };
                options.SetRw(Quorum.WellKnown.Quorum);

                var id = new RiakObjectId("default", "Timeseries", streamId);
                _logger.Debug("Getting timeseries db of id {0}", id.Key);
                var result = await _client.Async.Get(id, options).ConfigureAwait(false);

                RiakObject timedb = result.Value;
                if (!result.IsSuccess)
                {
                    timedb = await CreateNewDb(streamId).ConfigureAwait(false);
                }
                if (timedb == null)
                {
                    _logger.Error("Could not find or create ts db for metric {0}", streamId);
                    continue;
                }

                var quantums = timedb.GetObject <IEnumerable <Quantum> >();
                quantums = updateAction(quantums);

                timedb.SetObject(quantums);

                var uptOptions = new RiakPutOptions {
                    IfNoneMatch = false, IfNotModified = true, ReturnHead = true, ReturnBody = false
                };
                uptOptions.SetW(Quorum.WellKnown.Quorum);
                var updated = await _client.Async.Put(timedb, uptOptions).ConfigureAwait(false);

                if (updated.IsSuccess)
                {
                    return(true);
                }
                retries++;
            }
            return(false);
        }
        public void JsonConversionTimerTest()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email = "*****@*****.**",
                Name = new Name
                {
                    FirstName = "OJ",
                    Surname = "Reeves"
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };
            var obj = new RiakObject("bucket", "key");

            var sw = new Stopwatch();
            sw.Start();
            const int iterations = 1000000;

            for (var i = 0; i < iterations; ++i)
            {
                obj.SetObject(testPerson);
            }
            sw.Stop();
            Console.WriteLine("Serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));

            sw.Reset();
            sw.Start();

            for (var i = 0; i < iterations; ++i)
            {
                var result = obj.GetObject<Person>();
            }
            sw.Stop();
            Console.WriteLine("De" +
                "serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
        }
Esempio n. 11
0
        public void CausalContext()
        {
            id = new RiakObjectId("sports", "nba", "champion");
            var obj = new RiakObject(id, "Washington Generals",
                                     RiakConstants.ContentTypes.TextPlain);

            CheckResult(client.Put(obj));

            var rslt = client.Get(id);

            CheckResult(rslt);

            obj = rslt.Value;
            obj.SetObject("Harlem Globetrotters", RiakConstants.ContentTypes.TextPlain);
            rslt = client.Put(obj);
            CheckResult(rslt);

            Assert.IsTrue(EnumerableUtil.IsNullOrEmpty(rslt.Value.Siblings));
            Assert.AreEqual("Harlem Globetrotters", Encoding.UTF8.GetString(rslt.Value.Value));
        }
        public void ResolvingSiblingsWithUpdate()
        {
            id = PutNickolodeonCharacters();

            // First, fetch the object
            var getResult = client.Get(id);

            // Then, modify the object's value
            RiakObject obj = getResult.Value;

            obj.SetObject <string>("Stimpy", RiakConstants.ContentTypes.TextPlain);

            // Then, store the object which has vector clock attached
            var putRslt = client.Put(obj);

            CheckResult(putRslt);

            obj = putRslt.Value;
            // Voila, no more siblings!
            Debug.Assert(obj.Siblings.Count == 0);
            Assert.AreEqual(0, obj.Siblings.Count);
        }
Esempio n. 13
0
        public void CustomSerializerWillSerializeJson()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email       = "*****@*****.**",
                Name        = new Name
                {
                    FirstName = "OJ",
                    Surname   = "Reeves"
                },
                PhoneNumbers = new List <PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number     = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };

            var sots = new SerializeObjectToString <Person>(JsonConvert.SerializeObject);

            var obj = new RiakObject("bucket", "key");

            obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();

            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject <Person>();

            deserialisedPerson.ShouldEqual(testPerson);
        }
Esempio n. 14
0
        public void SavedObjectsShouldBeIdentical()
        {
            // create a proto-contract class (https://code.google.com/p/protobuf-net/wiki/GettingStarted)
            //var testPerson = new ProtoBufPerson()
            //{
            //    Id = 42,
            //    Name = "alex",
            //    Address = new Address()
            //    {
            //        Line1 = "16 dusty road",
            //        Line2 = "santa fe, nm 87508"
            //    }
            //};
            const string bucketName = "test";
            var ojPerson = new Person() { Name = "oj", CurrentlyDrinking = "tea" };

            var oj = new RiakObject(bucketName, OJ) { ContentType = RiakConstants.ContentTypes.ProtocolBuffers };
            oj.SetObject(ojPerson);

            // Don't capture result to avoid compiler warning
            Client.Put(oj);

            var getResult = Client.Get(bucketName, OJ);
            var newPerson = getResult.Value.GetObject<Person>();

            ojPerson.Name.ShouldEqual(newPerson.Name);


            var testPerson = new ProtoBufPerson()
            {
                Id = 42,
                Name = "alex",
                Address = new Address()
                {
                    Line1 = "16 dusty road",
                    Line2 = "santa fe, nm 87508"
                }
            };

            var ro = new RiakObject(bucketName, testPerson.Id.ToString());
            ro.ContentType = RiakConstants.ContentTypes.ProtocolBuffers;
            ro.SetObject(testPerson);

            // Don't capture result to avoid compiler warning
            Client.Put(ro);

            var getResult2 = Client.Get(bucketName, testPerson.Id.ToString());
            var testPerson2 = getResult2.Value.GetObject<ProtoBufPerson>();

            testPerson.Id.ShouldEqual(testPerson2.Id);
            testPerson.Name.ShouldEqual(testPerson2.Name);
            testPerson.Address.Line1.ShouldEqual(testPerson2.Address.Line1);
            testPerson.Address.Line2.ShouldEqual(testPerson2.Address.Line2);
        }
        public void LastModifiedShouldChangeAfterAPutRequest()
        {
            var o = new RiakObject(TestBucket, "1234", new { value = 1234 });
            o = Client.Put(o).Value;

            var lm2 = o.LastModified;
            var lmu2 = o.LastModifiedUsec;

            Thread.Sleep(500);
            o.SetObject(new { value = 12345 });
            o = Client.Put(o).Value;

            var lm3 = o.LastModified;
            var lmu3 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm3);
            lmu2.ShouldNotEqual(lmu3);

            Thread.Sleep(500);
            o.SetObject(new { value = 76543 });
            o = Client.Put(o, new RiakPutOptions { ReturnBody = false }).Value;

            var lm4 = o.LastModified;
            var lmu4 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm4);
            lmu2.ShouldNotEqual(lmu4);
        }
        public void CausalContext()
        {
            id = new RiakObjectId("sports", "nba", "champion");
            var obj = new RiakObject(id, "Washington Generals",
                RiakConstants.ContentTypes.TextPlain);
            CheckResult(client.Put(obj));

            var rslt = client.Get(id);
            CheckResult(rslt);

            obj = rslt.Value;
            obj.SetObject("Harlem Globetrotters", RiakConstants.ContentTypes.TextPlain);
            rslt = client.Put(obj);
            CheckResult(rslt);

            Assert.IsTrue(EnumerableUtil.IsNullOrEmpty(rslt.Value.Siblings));
            Assert.AreEqual("Harlem Globetrotters", Encoding.UTF8.GetString(rslt.Value.Value));
        }