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); } }
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); }
//eejmplo public Form1() { InitializeComponent(); IRiakEndPoint cluster = RiakCluster.FromConfig("riakConfig"); client = cluster.CreateClient(); }
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(); }
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); } }
public void SetUp() { Cluster = new RiakCluster(ClusterConfig); Client = Cluster.CreateClient(); var props = Client.GetBucketProperties(Bucket); props.SetSearch(true); Client.SetBucketProperties(Bucket, props).ShouldBeTrue(); }
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); }
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); } }
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); } }
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))); } }
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(); }
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(); }
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 = new RiakClient(Cluster); }
protected void SetUpInternal() { ConnMock = new Mock <IRiakConnection>(); ClusterConfigMock = new Mock <IRiakClusterConfiguration>(); NodeConfigMock = new Mock <IRiakNodeConfiguration>(); ConnMock.Setup(m => m.PbcWriteRead <TRequest, TResult>(It.IsAny <IRiakEndPoint>(), It.IsAny <TRequest>()).ConfigureAwait(false).GetAwaiter().GetResult()).Returns(() => Result); NodeConfigMock.SetupGet(m => m.PoolSize).Returns(1); NodeConfigMock.SetupGet(m => m.BufferSize).Returns(2097152); ClusterConfigMock.SetupGet(m => m.RiakNodes).Returns(new List <IRiakNodeConfiguration> { NodeConfigMock.Object }); ClusterConfigMock.SetupGet(m => m.DefaultRetryCount).Returns(100); ClusterConfigMock.SetupGet(m => m.DefaultRetryWaitTime).Returns(100); Cluster = new RiakCluster(ClusterConfigMock.Object); 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); }
protected void SetUpInternal() { ConnMock = new Mock <IRiakConnection>(); ClusterConfigMock = new Mock <IRiakClusterConfiguration>(); ConnFactoryMock = new Mock <IRiakConnectionFactory>(); NodeConfigMock = new Mock <IRiakNodeConfiguration>(); ConnMock.Setup(m => m.PbcWriteRead <TRequest, TResult>(It.IsAny <TRequest>())).Returns(() => Result); 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 }); ClusterConfigMock.SetupGet(m => m.DefaultRetryCount).Returns(100); ClusterConfigMock.SetupGet(m => m.DefaultRetryWaitTime).Returns(100); Cluster = new RiakCluster(ClusterConfigMock.Object, ConnFactoryMock.Object); Client = Cluster.CreateClient(); }
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); }
public void _() { var conf = new RiakClusterConfiguration { Nodes = { new RiakNodeConfiguration { Name = "[email protected]", HostAddress = "localhost" } } }; var fact = new RiakConnectionFactory(); var clus = new RiakCluster(conf, fact); var client = clus.CreateClient(); var init = new IfNotLatest(new IfNotExists(new Table.Create()), new Table.Throw()); DbContext.SetInitializer(init); var context = new MyContext(client); var set = context.Entities; var e1 = new MyEntity(); set.Add(e1); context.Save(); var e2 = set.First(x => x.Id == e1.Id && x.Stamp == e1.Stamp); Assert.IsNotNull(e2); Assert.AreEqual(e1.Id, e2.Id); Assert.AreEqual(e1.Stamp, e2.Stamp); }
public void SetUp() { Cluster = new RiakCluster(ClusterConfig); Client = Cluster.CreateClient(); }
private RiakClusterManager() { EndPoint = RiakCluster.FromConfig("riakConfig"); }
public RiakStorage(byte[] infoHash) { _cluster = RiakCluster.FromConfig(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 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); } } }
static Program() { cluster = RiakCluster.FromConfig("riakConfig"); }
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); } }
public ExampleBase() { endpoint = RiakCluster.FromConfig("riakConfig"); }
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); } } }
public void SetUp() { Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory()); Client = Cluster.CreateClient(); }