protected void SetUp()
        {
            ConnMock = new Mock<IRiakConnection>();
            ClusterConfigMock = new Mock<IRiakClusterConfiguration>();
            ConnFactoryMock = new Mock<IRiakConnectionFactory>();
            NodeConfigMock = new Mock<IRiakNodeConfiguration>();

            ConnFactoryMock.Setup(m => m.CreateConnection(It.IsAny<IRiakNodeConfiguration>())).Returns(ConnMock.Object);
            NodeConfigMock.SetupGet(m => m.PoolSize).Returns(1);
            ClusterConfigMock.SetupGet(m => m.RiakNodes).Returns(new List<IRiakNodeConfiguration>
                                                                     {NodeConfigMock.Object});

            Cluster = new RiakCluster(ClusterConfigMock.Object, ConnFactoryMock.Object);
            Client = Cluster.CreateClient();
        }
Esempio n. 2
0
        public void Parallel_ForEach_Can_Be_Used_To_Put_And_Get_Objects()
        {
            const int    numNodes             = 4;
            const int    poolSize             = 8;
            const int    totalConnectionCount = poolSize * numNodes;
            const ushort portInterval         = 10;
            const ushort startingPort         = 10017;
            const ushort endingPort           = startingPort + ((numNodes - 1) * portInterval);
            const int    totalObjects         = 65536;

            byte[] data = new byte[65536];
            Random.NextBytes(data);

            int batchSize    = totalConnectionCount;
            int totalBatches = totalObjects / batchSize;

            Assert.AreEqual(0, totalObjects % batchSize);
            Debug.WriteLine("batchSize: {0}, totalBatches: {1}", batchSize, totalBatches);

            string riakHost = Environment.GetEnvironmentVariable("RIAK_HOST");

            if (String.IsNullOrWhiteSpace(riakHost))
            {
                riakHost = "riak-test";
            }

            Debug.WriteLine("Riak host: {0}", riakHost);

            Assert.AreEqual(10047, endingPort);

            var objs = new List <RiakObject>();

            for (int i = 0; i < totalObjects; i++)
            {
                var key = String.Format("{0}_{1}", TestKey, i);
                var id  = new RiakObjectId(TestBucket, key);
                var obj = new RiakObject(id, data, RiakConstants.ContentTypes.ApplicationOctetStream, null);
                objs.Add(obj);
            }

            IRiakClusterConfiguration clusterConfig = new RiakClusterConfiguration();

            for (ushort port = startingPort; port <= endingPort; port += portInterval)
            {
                IRiakNodeConfiguration nc = new RiakNodeConfiguration();
                nc.PoolSize    = poolSize;
                nc.HostAddress = riakHost;
                nc.PbcPort     = port;
                nc.Name        = String.Format("dev_{0}", port);
                clusterConfig.AddNode(nc);
            }

            var batchObjs = new RiakObject[batchSize];
            var p         = new int[] { 1, batchSize };

            foreach (int parallelism in p)
            {
                var parallelOptions = new ParallelOptions();
                parallelOptions.MaxDegreeOfParallelism = parallelism;

                using (var cluster = new RiakCluster(clusterConfig))
                {
                    var client = cluster.CreateClient();

                    var sw = new Stopwatch();
                    sw.Start();

                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                client.Put(obj);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - put {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);

                    sw.Reset();

                    sw.Start();
                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                var id = new RiakObjectId(obj.Bucket, obj.Key);
                                client.Get(id);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - fetched {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);
                }
            }
        }
Esempio n. 3
0
 public void SetUp()
 {
     Cluster = new RiakCluster(ClusterConfig);
     Client  = Cluster.CreateClient();
 }
        private static void SetUpRiakClient()
        {
            var factory = new CorrugatedIron.Comms.RiakConnectionFactory();
              var clusterconfig = new CorrugatedIron.Config.Fluent.RiakClusterConfiguration()
            .SetNodePollTime(5000)
            .SetDefaultRetryWaitTime(200)
            .SetDefaultRetryCount(3)
            .AddNode(a => a
              .SetHostAddress("169.254.11.11")
              .SetPbcPort(8087)
              .SetRestPort(8098)
              .SetPoolSize(20)
              .SetName("Riak")
             );
              var cluster = new RiakCluster(clusterconfig, factory);
              riakClient = cluster.CreateClient();

              Log("Initialized Riak client");
              ConfigureBucketAllowMult(true);
        }
 public void SetUp()
 {
     Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory());
     Client = Cluster.CreateClient();
 }
Esempio n. 6
0
        public void SetUp()
        {
            Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory());
            Client = Cluster.CreateClient();

            var props = Client.GetBucketProperties(Bucket, true).Value;
            props.SetSearch(true);
            Client.SetBucketProperties(Bucket, props);
        }
Esempio n. 7
0
 public void SetUp()
 {
     Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory());
     Client  = Cluster.CreateClient();
 }
 public void SetUp()
 {
     Cluster = new RiakCluster(ClusterConfig);
     Client = Cluster.CreateClient();
 }
        public void Parallel_ForEach_Can_Be_Used_To_Put_And_Get_Objects()
        {
            /* NB: this example assumes a 4-node devrel available
             * with localhost PB ports at 10017, 10027, 10037 and 10047 */
            const int numNodes = 4;
            const int poolSize = 8;
            const int totalConnectionCount = poolSize * numNodes;
            const ushort portInterval = 10;
            const ushort startingPort = 10017;
            const ushort endingPort = startingPort + ((numNodes - 1) * portInterval);
            const int totalObjects = 65536;

            byte[] data = new byte[65536];
            Random.NextBytes(data);

            int batchSize = totalConnectionCount;
            int totalBatches = totalObjects / batchSize;
            Assert.AreEqual(0, totalObjects % batchSize);
            Debug.WriteLine("batchSize: {0}, totalBatches: {1}", batchSize, totalBatches);

            string riakHost = Environment.GetEnvironmentVariable("RIAK_HOST");
            if (String.IsNullOrWhiteSpace(riakHost))
            {
                riakHost = "riak-test";
            }

            Debug.WriteLine("Riak host: {0}", riakHost);

            Assert.AreEqual(10047, endingPort);

            var objs = new List<RiakObject>();
            for (int i = 0; i < totalObjects; i++)
            {
                var key = String.Format("{0}_{1}", TestKey, i);
                var id = new RiakObjectId(TestBucket, key);
                var obj = new RiakObject(id, data, RiakConstants.ContentTypes.ApplicationOctetStream, null);
                objs.Add(obj);
            }

            IRiakClusterConfiguration clusterConfig = new RiakClusterConfiguration();

            for (ushort port = startingPort; port <= endingPort; port += portInterval)
            {
                IRiakNodeConfiguration nc = new RiakNodeConfiguration();
                nc.PoolSize = poolSize;
                nc.HostAddress = riakHost;
                nc.PbcPort = port;
                nc.Name = String.Format("dev_{0}", port);
                clusterConfig.AddNode(nc);
            }

            var batchObjs = new RiakObject[batchSize];
            var p = new int[] { 1, batchSize };

            foreach (int parallelism in p)
            {
                var parallelOptions = new ParallelOptions();
                parallelOptions.MaxDegreeOfParallelism = parallelism;

                using (var cluster = new RiakCluster(clusterConfig))
                {
                    var client = cluster.CreateClient();

                    var sw = new Stopwatch();
                    sw.Start();

                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                client.Put(obj);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - put {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);

                    sw.Reset();

                    sw.Start();
                    for (int i = 0; i < totalObjects; i += batchSize)
                    {
                        objs.CopyTo(i, batchObjs, 0, batchSize);
                        Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
                        {
                            try
                            {
                                var id = new RiakObjectId(obj.Bucket, obj.Key);
                                client.Get(id);
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
                            }
                        });
                    }

                    sw.Stop();
                    Debug.WriteLine("parallelism: {0} - fetched {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);
                }
            }
        }
        public void SetUp()
        {
            Cluster = new RiakCluster(ClusterConfig);
            Client = Cluster.CreateClient();

            var props = Client.GetBucketProperties(Bucket);
            props.SetSearch(true);
            Client.SetBucketProperties(Bucket, props).ShouldBeTrue();
        }