示例#1
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);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
            var testCount = 10;

            //var conn = new CouchbaseConnector();
            //conn.Connect();
            //conn.Insert(RedditModel.GetDemo());

            var cluster = RiakCluster.FromConfig("riakConfig");
            //IRiakClient client = cluster.CreateClient();
            //var a = client.Ping();

            var benchmarks = new BenchmarkFactory().GetAllBenchmarks(ModelDataType.Reddit);

            foreach (var benchmark in benchmarks)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                //Console.Write($"\r{i * 100 / testCount}%\t");
                benchmark.Test <RedditModel>(new JustInsertsStrategy()
                {
                    CountOfOperations = testCount
                });
                stopwatch.Stop();
                Console.WriteLine($"{benchmark,9} resulted with {stopwatch.Elapsed:g}");
                benchmark.Dispose();
            }

            Console.ReadKey();
        }
示例#3
0
        public static IRiakClient ConfigureRiak()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["Riak"];

            if (connectionString == null)
            {
                throw new ArgumentException("No Riak connection string");
            }

            var data = connectionString.ConnectionString.Split(';');

            var bucket = data.FirstOrDefault(x => x.StartsWith("bucket", StringComparison.CurrentCultureIgnoreCase));

            if (bucket == null)
            {
                throw new ArgumentException("No BUCKET parameter in riak connection string");
            }

            bucket = bucket.Substring(7);

            var cluster = RiakCluster.FromConfig("riakConfig");
            var client  = cluster.CreateClient();

            Settings.Bucket = bucket;
            var regex = new Regex("([+\\-!\\(\\){}\\[\\]^\"~*?:\\\\\\/>< ]|[&\\|]{2}|AND|OR|NOT)", RegexOptions.Compiled);

            Settings.KeyGenerator = (type, key) =>
            {
                var first = regex.Replace(type.FullName.Replace("Demo.Domain.", ""), "");
                return($"{first}:{key}");
            };

            return(client);
        }
示例#4
0
        //eejmplo

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

            client = cluster.CreateClient();
        }
示例#5
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);
 }
        public static void ClearRiakDb(string connectionName)
        {
            var connectionString = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionString == null)
            {
                return;
            }

            var data = connectionString.ConnectionString.Split(';');

            var bucket = data.FirstOrDefault(x => x.StartsWith("bucket", StringComparison.CurrentCultureIgnoreCase));

            if (bucket == null)
            {
                throw new ArgumentException("No BUCKET parameter in riak connection string");
            }

            bucket = bucket.Substring(7);

            var cluster = RiakCluster.FromConfig("riakConfig");
            var client  = cluster.CreateClient();

            var stream    = client.StreamListKeys(bucket);
            var objectids = stream.Value.Select(x => new RiakObjectId(bucket, x)).ToList();

            client.Delete(objectids);

            var streamSystem    = client.StreamListKeys($"{bucket}.system");
            var objectidsSystem = streamSystem.Value.Select(x => new RiakObjectId($"{bucket}.system", x)).ToList();

            client.Delete(objectidsSystem);

            var options = new RiakBucketProperties()
                          .SetW(Quorum.WellKnown.Quorum).SetR(Quorum.WellKnown.Quorum)
                          .SetDw(1).SetRw(Quorum.WellKnown.Quorum)
                          .SetPr(1).SetPw(1)
                          .SetLegacySearch(false);
            var result = client.SetBucketProperties(bucket, options);

            if (!result.IsSuccess)
            {
                Logger.Warn("Failed to set primary bucket props.  Error: {0}", result.ErrorMessage);
            }

            var systemOptions = new RiakBucketProperties()
                                .SetW(Quorum.WellKnown.All).SetR(Quorum.WellKnown.All)
                                .SetDw(1).SetRw(Quorum.WellKnown.All)
                                .SetPr(Quorum.WellKnown.Quorum).SetPw(Quorum.WellKnown.Quorum)
                                .SetLegacySearch(false);

            result = client.SetBucketProperties($"{bucket}.system", systemOptions);
            if (!result.IsSuccess)
            {
                Logger.Warn("Failed to set system bucket props.  Error: {0}", result.ErrorMessage);
            }
        }
示例#7
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);
            }
        }
示例#8
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);
            }
        }
示例#9
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)));
            }
        }
示例#10
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(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);
        }
示例#13
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);
        }
示例#15
0
 static Program()
 {
     cluster = RiakCluster.FromConfig("riakConfig");
 }
示例#16
0
 public ExampleBase()
 {
     endpoint = RiakCluster.FromConfig("riakConfig");
 }
示例#17
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);
            }
        }
示例#18
0
 public RiakStorage(byte[] infoHash)
 {
     _cluster = RiakCluster.FromConfig(ClusterConfig);
     _client  = _cluster.CreateClient();
 }
示例#19
0
 private RiakClusterManager()
 {
     EndPoint = RiakCluster.FromConfig("riakConfig");
 }