Beispiel #1
0
        public IObservable <TResult> PbcRepeatRead <TResult>(IRiakEndPoint endPoint, Func <TResult, bool> repeatRead)
            where TResult : class, new()
        {
            var pbcStreamReadIterator = Observable.Create <TResult>(async observer =>
            {
                await endPoint.GetMultipleResultViaPbc(async socket =>
                {
                    try
                    {
                        TResult result;
                        do
                        {
                            result = await PbcRead <TResult>(socket).ConfigureAwait(false);
                            observer.OnNext(result);
                        } while (repeatRead(result));
                        observer.OnCompleted();
                    }
                    catch (Exception exception)
                    {
                        observer.OnError(exception);
                    }
                }).ConfigureAwait(false);
                return(Disposable.Empty);
            });

            return(pbcStreamReadIterator);
        }
Beispiel #2
0
        //eejmplo

        public Form1()
        {
            InitializeComponent();
            IRiakEndPoint cluster = RiakCluster.FromConfig("riakConfig");

            client = cluster.CreateClient();
        }
Beispiel #3
0
        public async Task <TResult> PbcRead <TResult>(IRiakEndPoint endPoint)
            where TResult : class, new()
        {
            var result = await endPoint.GetSingleResultViaPbc(async socket => await PbcRead <TResult>(socket).ConfigureAwait(false));

            return(result);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
            {
                IRiakClient        client       = endpoint.CreateClient();
                UserRepository     userRepo     = new UserRepository(client);
                MsgRepository      msgRepo      = new MsgRepository(client);
                TimelineRepository timelineRepo = new TimelineRepository(client);
                TimelineManager    timelineMgr  = new TimelineManager(timelineRepo, msgRepo);

                // Create and save users
                var marleen = new User("marleenmgr", "Marleen Manager", "*****@*****.**");
                var joe     = new User("joeuser", "Joe User", "*****@*****.**");
                userRepo.Save(marleen);
                userRepo.Save(joe);

                // Create new Msg, post to timelines
                Msg msg = new Msg(marleen.UserName, joe.UserName, "Welcome to the company!");
                timelineMgr.PostMsg(msg);

                // Get Joe's inbox for today, get first message
                Timeline joesInboxToday = timelineMgr.GetTimeline(joe.UserName, Timeline.TimelineType.Inbox, DateTime.UtcNow);
                Msg      joesFirstMsg   = msgRepo.Get(joesInboxToday.MsgKeys.First());

                Console.WriteLine("From: " + joesFirstMsg.Sender);
                Console.WriteLine("Msg : " + joesFirstMsg.Text);
            }
        }
Beispiel #5
0
 public IObservable <TResult> PbcWriteStreamRead <TRequest, TResult>(IRiakEndPoint endPoint, TRequest request,
                                                                     Func <TResult, bool> repeatRead)
     where TRequest : class
     where TResult : class, new()
 {
     return(PbcWriteStreamReadIterator(endPoint, request, repeatRead));
 }
Beispiel #6
0
        internal RiakClient(IRiakEndPoint endPoint, string seed = null)
        {
            _endPoint = endPoint;

            ClientId = GetClientId(seed);
            Async    = new RiakAsyncClient(this);
        }
Beispiel #7
0
 public async Task PbcWriteRead(IRiakEndPoint endPoint, MessageCode messageCode, MessageCode expectedMessageCode)
 {
     await endPoint.GetSingleResultViaPbc(async socket =>
     {
         await PbcWrite(socket, messageCode).ConfigureAwait(false);
         await PbcRead(socket, expectedMessageCode).ConfigureAwait(false);
     }).ConfigureAwait(false);
 }
 public LiveRiakConnectionTestBase(string section = "riak1NodeConfiguration")
 {
     // TODO: do something smarter with this
     // switch between cluster and load balancer configuration "easily" by changing the following
     // two lines around
     //Cluster = RiakExternalLoadBalancer.FromConfig("riakHaproxyConfiguration");
     Cluster = RiakCluster.FromConfig(section);
 }
Beispiel #9
0
 public LiveRiakConnectionTestBase(string section = "riak1NodeConfiguration")
 {
     // TODO: do something smarter with this
     // switch between cluster and load balancer configuration "easily" by changing the following
     // two lines around
     //Cluster = RiakExternalLoadBalancer.FromConfig("riakHaproxyConfiguration");
     Cluster = RiakCluster.FromConfig(section);
 }
Beispiel #10
0
 public async Task PbcWriteRead <TRequest>(IRiakEndPoint endPoint, TRequest request, MessageCode expectedMessageCode)
     where TRequest : class
 {
     await endPoint.GetSingleResultViaPbc(async socket =>
     {
         await PbcWrite(socket, request).ConfigureAwait(false);
         await PbcRead(socket, expectedMessageCode).ConfigureAwait(false);
     }).ConfigureAwait(false);
 }
Beispiel #11
0
        public void ShortConnectTimeoutMayResultInError()
        {
            IRiakEndPoint cluster = RiakCluster.FromConfig("riakShortConnectConfiguration");
            IRiakClient   client  = cluster.CreateClient();
            RiakResult    result  = client.Ping();

            if (!result.IsSuccess)
            {
                Assert.IsTrue(result.ErrorMessage.Contains("Connection to remote server timed out"), result.ErrorMessage);
            }
        }
Beispiel #12
0
        public void ShortReadTimeoutMayResultInError()
        {
            IRiakEndPoint cluster = RiakCluster.FromConfig("riakShortReadConfiguration");
            IRiakClient   client  = cluster.CreateClient();
            RiakResult    result  = client.Ping();

            if (!result.IsSuccess)
            {
                Assert.IsTrue(result.ErrorMessage.Contains("the connected party did not properly respond after a period of time"), result.ErrorMessage);
            }
        }
Beispiel #13
0
        private static void DeleteExistingKeys(IRiakEndPoint cluster, string bucket)
        {
            // Delete all keys in bucket... maybe should just delete the bucket itself
            var keys = cluster.CreateClient().StreamListKeys(bucket).Value.ToList();

            Console.WriteLine("Cleaning up {0} existing items", keys.Count);
            foreach (var key in keys)
            {
                var res = cluster.CreateClient().Delete(new RiakObjectId { Bucket = bucket, Key = key });
            }
        }
Beispiel #14
0
        public async Task <TResult> PbcWriteRead <TResult>(IRiakEndPoint endPoint, MessageCode messageCode)
            where TResult : class, new()
        {
            var result = await endPoint.GetSingleResultViaPbc(async socket =>
            {
                await PbcWrite(socket, messageCode).ConfigureAwait(false);
                var result2 = await PbcRead <TResult>(socket).ConfigureAwait(false);
                return(result2);
            }).ConfigureAwait(false);

            return(result);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Creating Data");
            Customer            customer     = CreateCustomer();
            IEnumerable <Order> orders       = CreateOrders(customer);
            OrderSummary        orderSummary = CreateOrderSummary(customer, orders);


            Console.WriteLine("Starting Client");
            using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
            {
                IRiakClient client = endpoint.CreateClient();

                Console.WriteLine("Storing Data");

                client.Put(ToRiakObject(customer));

                foreach (Order order in orders)
                {
                    // NB: this adds secondary index data as well
                    client.Put(ToRiakObject(order));
                }

                client.Put(ToRiakObject(orderSummary));

                Console.WriteLine("Fetching related data by shared key");
                string key = "1";

                var result = client.Get(customersBucketName, key);
                CheckResult(result);
                Console.WriteLine("Customer     1: {0}\n", GetValueAsString(result));

                result = client.Get(orderSummariesBucketName, key);
                CheckResult(result);
                Console.WriteLine("OrderSummary 1: {0}\n", GetValueAsString(result));

                Console.WriteLine("Index Queries");

                // Query for order keys where the SalesPersonId index is set to 9000
                var riakIndexId = new RiakIndexId(ordersBucketName, ordersSalesPersonIdIndexName);
                RiakResult <RiakIndexResult> indexRiakResult = client.GetSecondaryIndex(riakIndexId, 9000); // NB: *must* use 9000 as integer here.
                CheckResult(indexRiakResult);
                RiakIndexResult indexResult = indexRiakResult.Value;
                Console.WriteLine("Jane's orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));

                // Query for orders where the OrderDate index is between 2013-10-01 and 2013-10-31
                riakIndexId     = new RiakIndexId(ordersBucketName, ordersOrderDateIndexName);
                indexRiakResult = client.GetSecondaryIndex(riakIndexId, "2013-10-01", "2013-10-31"); // NB: *must* use strings here.
                CheckResult(indexRiakResult);
                indexResult = indexRiakResult.Value;
                Console.WriteLine("October orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));
            }
        }
Beispiel #16
0
        public async Task <TResult> PbcWriteRead <TRequest, TResult>(IRiakEndPoint endPoint, TRequest request)
            where TRequest : class
            where TResult : class, new()
        {
            var result = await endPoint.GetSingleResultViaPbc(async socket =>
            {
                await PbcWrite(socket, request).ConfigureAwait(false);
                var singleResult = await PbcRead <TResult>(socket).ConfigureAwait(false);
                return(singleResult);
            }).ConfigureAwait(false);

            return(result);
        }
Beispiel #17
0
        private async Task InsertMessagesIntoDatabase(string table, List <Message> allMessages)
        {
            IRiakEndPoint cluster = RiakCluster.FromConfig("riakConfig");
            IRiakClient   client  = cluster.CreateClient();

            while (allMessages.Count() > 0)
            {
                List <Message> messages = allMessages.Take(80).ToList();
                allMessages.RemoveRange(0, messages.Count());

                var rows = new List <Row>();

                foreach (Message message in messages)
                {
                    var cells = new Cell[]
                    {
                        new Cell("LT"),
                        new Cell(message.SerialNo),
                        new Cell(message.DeviceName),
                        new Cell(message.Timestamp),
                        new Cell(message.Value)
                    };
                    rows.Add(new Row(cells));
                }

                var columns = new Column[]
                {
                    new Column("Country", ColumnType.Varchar),
                    new Column("SerialNo", ColumnType.Varchar),
                    new Column("DeviceName", ColumnType.Varchar),
                    new Column("Time", ColumnType.Timestamp),
                    new Column("Value", ColumnType.Double)
                };

                var cmd = new Store.Builder()
                          .WithTable(table)
                          .WithColumns(columns)
                          .WithRows(rows)
                          .Build();

                RiakResult rslt = client.Execute(cmd);

                if (!rslt.IsSuccess)
                {
                    throw new Exception("Connection to Riak was not successful. AllMessages: " + allMessages.Count());
                }
            }
        }
        public TestBase()
        {
#if NOAUTH
            cluster = RiakCluster.FromConfig("riak1NodeNoAuthConfiguration");
#else
            if (MonoUtil.IsRunningOnMono)
            {
                cluster = RiakCluster.FromConfig("riak1NodeNoAuthConfiguration");
            }
            else
            {
                cluster = RiakCluster.FromConfig("riak1NodeConfiguration");
            }
#endif
            client = cluster.CreateClient();
        }
        public TestBase(bool auth = true)
        {
#if NOAUTH
            cluster = RiakCluster.FromConfig("riak1NodeNoAuthConfiguration");
#else
            if (auth == false || MonoUtil.IsRunningOnMono)
            {
                cluster = RiakCluster.FromConfig("riak1NodeNoAuthConfiguration");
            }
            else
            {
                cluster = RiakCluster.FromConfig("riak1NodeConfiguration");
            }
#endif
            client = cluster.CreateClient();
        }
        public LiveRiakConnectionTestBase()
        {
            string configName = "riakConfiguration";
#if NOAUTH
            configName = "riakNoAuthConfiguration";
#else
            if (MonoUtil.IsRunningOnMono)
            {
                configName = "riakNoAuthConfiguration";
            }
            else
            {
                configName = "riakConfiguration";
            }
#endif
            Cluster = RiakCluster.FromConfig(configName);
        }
        public LiveRiakConnectionTestBase()
        {
            string configName = "riakConfiguration";

#if NOAUTH
            configName = "riakNoAuthConfiguration";
#else
            if (MonoUtil.IsRunningOnMono)
            {
                configName = "riakNoAuthConfiguration";
            }
            else
            {
                configName = "riakConfiguration";
            }
#endif
            Cluster = RiakCluster.FromConfig(configName);
        }
Beispiel #22
0
        private void InsertMessageIntoDatabase(string table, Message message)
        {
            IRiakEndPoint cluster = RiakCluster.FromConfig("riakConfig");
            IRiakClient   client  = cluster.CreateClient();

            var cells = new Cell[]
            {
                new Cell("LT"),
                new Cell(message.SerialNo),
                new Cell(message.DeviceName),
                new Cell(message.Timestamp),
                new Cell(message.Value)
            };

            var rows = new Row[]
            {
                new Row(cells)
            };

            var columns = new Column[]
            {
                new Column("Country", ColumnType.Varchar),
                new Column("SerialNo", ColumnType.Varchar),
                new Column("DeviceName", ColumnType.Varchar),
                new Column("Time", ColumnType.Timestamp),
                new Column("Value", ColumnType.Double)
            };

            var cmd = new Store.Builder()
                      .WithTable(table)
                      .WithColumns(columns)
                      .WithRows(rows)
                      .Build();

            RiakResult rslt = client.Execute(cmd);

            if (!rslt.IsSuccess)
            {
                throw new Exception("Connection to Riak was not successful.");
            }
        }
        public LiveRiakConnectionTestBase()
        {
            string userName   = Environment.GetEnvironmentVariable("USERNAME");
            string configName = "riak1NodeConfiguration";

#if NOAUTH
            configName = userName == "buildbot" ?
                         "riak1NodeNoAuthConfiguration" : "riakDevrelNoAuthConfiguration";
#else
            if (MonoUtil.IsRunningOnMono)
            {
                configName = "riak1NodeNoAuthConfiguration";
            }
            else
            {
                configName = userName == "buildbot" ?
                             "riak1NodeConfiguration" : "riakDevrelConfiguration";
            }
#endif
            Cluster = RiakCluster.FromConfig(configName);
        }
Beispiel #24
0
 public static IRiakEndPoint GetConnectionManager(string host, int port)
 {
     if (cluster == null)
     {
         var tempFileName = Path.GetTempFileName();
         File.AppendAllText(tempFileName, String.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
     <configuration>
       <configSections>
     <section name=""riakConfig"" type=""CorrugatedIron.Config.RiakClusterConfiguration, CorrugatedIron""/>
       </configSections>
       <riakConfig nodePollTime=""5000"" defaultRetryWaitTime=""200"" defaultRetryCount=""3"">
     <nodes>
       <node name=""dev1"" hostAddress=""{0}"" pbcPort=""{1}"" restScheme=""http"" restPort=""8098"" poolSize=""20"" />
     </nodes>
       </riakConfig>
     </configuration>
     ", host, port));
         cluster = RiakCluster.FromConfig("riakConfig", tempFileName);
     }
     return cluster;
 }
        public MainForm()
        {
            InitializeComponent();

            _cluster = RiakCluster.FromConfig("riakConfig");
            _client = _cluster.CreateClient();

            _worker = new BackgroundWorker
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = false
            };

            _worker.DoWork += AsyncLoadImages;

            _resizeSettings = new ResizeSettings
            {
                MaxWidth = 120,
                MaxHeight = 100,
                Format = "jpg"
            };
        }
Beispiel #26
0
        public TestBase(bool useTtb = false, bool auth = true)
        {
            var config       = RiakClusterConfiguration.LoadFromConfig("riakConfiguration");
            var noAuthConfig = RiakClusterConfiguration.LoadFromConfig("riakNoAuthConfiguration");

            if (useTtb)
            {
                config.UseTtbEncoding       = true;
                noAuthConfig.UseTtbEncoding = true;
            }
#if NOAUTH
            cluster = new RiakCluster(noAuthConfig);
#else
            if (auth == false || MonoUtil.IsRunningOnMono)
            {
                cluster = new RiakCluster(noAuthConfig);
            }
            else
            {
                cluster = new RiakCluster(config);
            }
#endif
            client = cluster.CreateClient();
        }
Beispiel #27
0
        public TestBase(bool useTtb = false, bool auth = true)
        {
            var config = RiakClusterConfiguration.LoadFromConfig("riakConfiguration");
            var noAuthConfig = RiakClusterConfiguration.LoadFromConfig("riakNoAuthConfiguration");
            if (useTtb)
            {
                config.UseTtbEncoding = true;
                noAuthConfig.UseTtbEncoding = true;
            }
#if NOAUTH
            cluster = new RiakCluster(noAuthConfig);
#else
            if (auth == false || MonoUtil.IsRunningOnMono)
            {
                cluster = new RiakCluster(noAuthConfig);
            }
            else
            {
                cluster = new RiakCluster(config);
            }

#endif
            client = cluster.CreateClient();
        }
 public ExampleBase()
 {
     endpoint = RiakCluster.FromConfig("riakConfig");
 }
 public DinnerRepository()
 {
     _cluster = new RiakCluster(_clusterConfig, new RiakConnectionFactory());
     _client = _cluster.CreateClient();
 }
Beispiel #30
0
 static Program()
 {
     cluster = RiakCluster.FromConfig("riakConfig");
 }
Beispiel #31
0
 static Program()
 {
     cluster = RiakCluster.FromConfig("riakConfig");
 }
Beispiel #32
0
        public Task <RiakRestResponse> RestRequest(IRiakEndPoint endPoint, RiakRestRequest request)
        {
            return(endPoint.GetSingleResultViaRest(async serverUrl =>
            {
                var baseUri = new StringBuilder(serverUrl).Append(request.Uri);
                if (request.QueryParams.Count > 0)
                {
                    baseUri.Append("?");
                    var first = request.QueryParams.First();
                    baseUri.Append(first.Key.UrlEncoded()).Append("=").Append(first.Value.UrlEncoded());
                    request.QueryParams.Skip(1)
                    .ForEach(
                        kv =>
                        baseUri.Append("&")
                        .Append(kv.Key.UrlEncoded())
                        .Append("=")
                        .Append(kv.Value.UrlEncoded()));
                }
                var targetUri = new Uri(baseUri.ToString());

                var req = (HttpWebRequest)WebRequest.Create(targetUri);
                req.KeepAlive = true;
                req.Method = request.Method;
                req.Credentials = CredentialCache.DefaultCredentials;

                if (!string.IsNullOrWhiteSpace(request.ContentType))
                {
                    req.ContentType = request.ContentType;
                }

                if (!request.Cache)
                {
                    req.Headers.Set(RiakConstants.Rest.HttpHeaders.DisableCacheKey,
                                    RiakConstants.Rest.HttpHeaders.DisableCacheValue);
                }

                request.Headers.ForEach(h => req.Headers.Set(h.Key, h.Value));

                if (request.Body != null && request.Body.Length > 0)
                {
                    req.ContentLength = request.Body.Length;

                    var writer = await req.GetRequestStreamAsync().ConfigureAwait(false);
                    writer.Write(request.Body, 0, request.Body.Length);
                }
                else
                {
                    req.ContentLength = 0;
                }

                try
                {
                    var response = (HttpWebResponse)await req.GetResponseAsync().ConfigureAwait(false);

                    var result = new RiakRestResponse
                    {
                        ContentLength = response.ContentLength,
                        ContentType = response.ContentType,
                        StatusCode = response.StatusCode,
                        Headers = response.Headers.AllKeys.ToDictionary(k => k, k => response.Headers[k]),
                        ContentEncoding = !string.IsNullOrWhiteSpace(response.ContentEncoding)
                            ? Encoding.GetEncoding(response.ContentEncoding)
                            : Encoding.Default
                    };

                    if (response.ContentLength > 0)
                    {
                        using (var responseStream = response.GetResponseStream())
                        {
                            if (responseStream != null)
                            {
                                using (var reader = new StreamReader(responseStream, result.ContentEncoding))
                                {
                                    result.Body = reader.ReadToEnd();
                                }
                            }
                        }
                    }

                    if (result.StatusCode != HttpStatusCode.NoContent)
                    {
                        throw new RiakException((uint)ResultCode.InvalidResponse, "Unexpected Status Code: {0} ({1})".Fmt(result.StatusCode, (int)result.StatusCode), false);
                    }

                    return result;
                }
                catch (RiakException ex)
                {
                    throw;
                }
                catch (WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.ProtocolError)
                    {
                        throw new RiakException((uint)ResultCode.HttpError, ex.Message, false);
                    }

                    throw new RiakException((uint)ResultCode.HttpError, ex.Message, true);
                }
                catch (Exception ex)
                {
                    throw new RiakException((uint)ResultCode.CommunicationError, ex.Message, true);
                }
            }));
        }
Beispiel #33
0
 internal RiakAsyncClient(IRiakEndPoint endPoint)
 {
     _endPoint = endPoint;
 }
Beispiel #34
0
 public RiakStorage(byte[] infoHash)
 {
     _cluster = RiakCluster.FromConfig(ClusterConfig);
     _client  = _cluster.CreateClient();
 }
Beispiel #35
0
 public Task PbcWrite(IRiakEndPoint endPoint, MessageCode messageCode)
 {
     return(endPoint.GetSingleResultViaPbc(async socket => await PbcWrite(socket, messageCode).ConfigureAwait(false)));
 }
Beispiel #36
0
 public ExampleBase()
 {
     endpoint = RiakCluster.FromConfig("riakConfig");
 }
Beispiel #37
0
 public RiakBatch(IRiakEndPoint endPoint)
 {
     _endPoint        = endPoint;
     _endPointContext = new RiakEndPointContext();
 }
 static RiakSessionStateStore()
 {
     EndPoint = RiakCluster.FromConfig("riakConfig");
 }
Beispiel #39
0
 public IObservable <TResult> PbcWriteStreamRead <TResult>(IRiakEndPoint endPoint, MessageCode messageCode,
                                                           Func <TResult, bool> repeatRead)
     where TResult : class, new()
 {
     return(PbcWriteStreamReadIterator(endPoint, messageCode, repeatRead));
 }
Beispiel #40
0
 public override void SetUp()
 {
     base.SetUp();
     cluster = RiakCluster.FromConfig("riakConfig");
     client = cluster.CreateClient();
     fixture.Inject(client);
     userDocumentMapper = fixture.Freeze<IMapper<User, UserDocument>>();
     userMapper = fixture.Freeze<IMapper<UserDocument, User>>();
     sut = fixture.Create<UserRepository>();
 }
Beispiel #41
0
 internal RiakClient(IRiakEndPoint endPoint)
 {
     _endPoint = endPoint;
     Async     = new RiakAsyncClient(endPoint);
 }
Beispiel #42
0
        static void Main(string[] args)
        {
            const string bucket = "test";

            try
            {
                using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
                {
                    IRiakClient client = endpoint.CreateClient();

                    // Creating Objects In Riak
                    Console.WriteLine("Creating Objects In Riak...");

                    int val1        = 1;
                    var objectId1   = new RiakObjectId(bucket, "one");
                    var riakObject1 = new RiakObject(objectId1, val1);
                    var result      = client.Put(riakObject1);
                    CheckResult(result);

                    string val2        = "two";
                    var    objectId2   = new RiakObjectId(bucket, "two");
                    var    riakObject2 = new RiakObject(objectId2, val2);
                    result = client.Put(riakObject2);
                    CheckResult(result);

                    var val3 = new Dictionary <string, int>
                    {
                        { "myValue1", 3 },
                        { "myValue2", 4 }
                    };
                    var objectId3   = new RiakObjectId(bucket, "three");
                    var riakObject3 = new RiakObject(objectId3, val3);
                    result = client.Put(riakObject3);
                    CheckResult(result);

                    // Fetching Objects From Riak
                    Console.WriteLine("Reading Objects From Riak...");

                    var fetchResult1 = client.Get(objectId1);
                    CheckResult(fetchResult1);
                    RiakObject fetchObject1 = fetchResult1.Value;
                    int        fetchVal1    = fetchObject1.GetObject <int>();
                    Debug.Assert(val1 == fetchVal1, "Assert Failed", "val1 {0} != fetchVal1 {1}", val1, fetchVal1);

                    var fetchResult2 = client.Get(objectId2);
                    CheckResult(fetchResult2);
                    RiakObject fetchObject2 = fetchResult2.Value;
                    string     fetchVal2    = fetchObject2.GetObject <string>();
                    Debug.Assert(val2 == fetchVal2, "Assert Failed", "val2 {0} != fetchVal2 {1}", val2, fetchVal2);

                    var fetchResult3 = client.Get(objectId3);
                    CheckResult(fetchResult3);
                    RiakObject fetchObject3 = fetchResult3.Value;
                    var        fetchVal3    = fetchObject3.GetObject <Dictionary <string, int> >();
                    Debug.Assert(dictEqualityComparer.Equals(val3, fetchVal3), "Assert Failed", "val3 {0} != fetchVal3 {1}", val3, fetchVal3);

                    // Updating Objects In Riak
                    Console.WriteLine("Updating Objects In Riak");

                    fetchVal3["myValue1"] = 42;
                    var updateObject1 = new RiakObject(bucket, "three", fetchVal3);
                    var updateResult1 = client.Put(updateObject1);
                    CheckResult(updateResult1);

                    var fetchResult4 = client.Get(objectId3);
                    CheckResult(fetchResult4);
                    RiakObject fetchObject4 = fetchResult4.Value;
                    var        fetchVal4    = fetchObject4.GetObject <Dictionary <string, int> >();
                    Debug.Assert(false == dictEqualityComparer.Equals(val3, fetchVal4), "Assert Failed", "val3 {0} == fetchVal4 {1}", val3, fetchVal4);
                    Debug.Assert(fetchVal4["myValue1"] == 42, "Assert Failed", "myValue1 should have been 42");

                    // Deleting Objects From Riak
                    Console.WriteLine("Deleting Objects From Riak...");

                    RiakResult delResult1 = client.Delete(objectId1);
                    CheckResult(delResult1);

                    RiakResult delResult2 = client.Delete(objectId2);
                    CheckResult(delResult2);

                    RiakResult delResult3 = client.Delete(objectId3);
                    CheckResult(delResult3);


                    // Working With Complex Objects
                    Console.WriteLine("Working With Complex Objects...");

                    var book = new Book();
                    book.ISBN        = "1111979723";
                    book.Title       = "Moby Dick";
                    book.Author      = "Herman Melville";
                    book.Body        = "Call me Ishmael. Some years ago...";
                    book.CopiesOwned = 3;

                    var bookId        = new RiakObjectId("books", book.ISBN);
                    var bookObject    = new RiakObject(bookId, book);
                    var bookPutResult = client.Put(bookObject);
                    CheckResult(bookPutResult);

                    var fetchBookResult = client.Get(bookId);
                    CheckResult(fetchBookResult);
                    RiakObject fetchedBookObject = fetchBookResult.Value;
                    string     bookJson          = Encoding.UTF8.GetString(fetchedBookObject.Value);
                    Console.WriteLine("Serialized Object: {0}", bookJson);

                    var bookDeleteResult = client.Delete(bookId);
                    CheckResult(bookDeleteResult);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: {0}", e.Message);
            }
        }
Beispiel #43
0
 private static void VerifyObjects(IRiakEndPoint cluster, ConcurrentBag<StoredObject> storedObjects)
 {
     var client = cluster.CreateClient();
     foreach (var storedObj in storedObjects)
     {
         var result = client.Get(new RiakObjectId { Bucket = storedObj.Value.Bucket, Key = storedObj.Value.Key });
         var hash = GetHash(result.Value.Value);
         if (hash != storedObj.Hash)
             throw new Exception("Put & Get checksums do not match");
     }
 }
Beispiel #44
0
        private static ConcurrentBag<StoredObject> StoreObjects(IRiakEndPoint cluster, string bucket, int maxThreads, int maxObjSizeKB, int minObjSizeKB, int itemsToStore, ConcurrentBag<Stopwatch> individualTimings, Stopwatch stopwatch)
        {
            // Create pool of Riak Clients and Random objects
            var riakResourcePool = new ConcurrentBag<RiakBenchmarkResource>();
            for (int i = 0; i < maxThreads; ++i)
                riakResourcePool.Add(new RiakBenchmarkResource { Client = cluster.CreateClient(), Random = new Random() });

            var size = maxObjSizeKB * 1024 * 2; // multiply by two to make random buffer copy math easier below
            var randomBytes = GetRandomByteArray(size);

            var storedObjects = new ConcurrentBag<StoredObject>();

            stopwatch.Start();

            int count = 0;
            int totalSize = 0;
            try
            {
                Console.WriteLine("Storing {0} objects in Riak", itemsToStore);
                Parallel.For(0, itemsToStore, new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, i =>
                {
                    var iterationStopwatch = Stopwatch.StartNew();

                    RiakBenchmarkResource riakResource;
                    riakResourcePool.TryTake(out riakResource);
                    try
                    {
                        var rand = riakResource.Random;
                        var item = new byte[rand.Next(minObjSizeKB * 1024, maxObjSizeKB * 1024) + 1];
                        Array.Copy(randomBytes, rand.Next(0, maxObjSizeKB * 1024), item, 0, item.Length);

                        var obj = new RiakObject(bucket, Guid.NewGuid().ToString(), item, "application/binary", CorrugatedIron.Util.RiakConstants.CharSets.Utf8);

                        var result = riakResource.Client.Put(obj, new RiakPutOptions { ReturnBody = false, W = 2 });
                        if (!result.IsSuccess)
                            System.Diagnostics.Debugger.Break();

                        int countSnapshot = Interlocked.Increment(ref count);
                        Interlocked.Add(ref totalSize, item.Length);

                        if (countSnapshot % Math.Max(itemsToStore / 10, 1) == 0)
                            Console.WriteLine("Processed {0} of {1}. Elapsed: {2}", count, itemsToStore, stopwatch.Elapsed);

                        storedObjects.Add(new StoredObject { Value = result.Value, Size = item.Length, Hash = GetHash(item) });
                    }
                    finally
                    {
                        riakResourcePool.Add(riakResource);
                        iterationStopwatch.Stop();
                        individualTimings.Add(iterationStopwatch);
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            stopwatch.Stop();
            return storedObjects;
        }
        public LiveRiakConnectionTestBase()
        {
            string userName = Environment.GetEnvironmentVariable("USERNAME");
            string configName = "riak1NodeConfiguration";
#if NOAUTH
            configName = userName == "buildbot" ?
                "riak1NodeNoAuthConfiguration" : "riakDevrelNoAuthConfiguration";
#else
            if (MonoUtil.IsRunningOnMono)
            {
                configName = "riak1NodeNoAuthConfiguration";
            }
            else
            {
                configName = userName == "buildbot" ?
                    "riak1NodeConfiguration" : "riakDevrelConfiguration";
            }
#endif
            Cluster = RiakCluster.FromConfig(configName);
        }